diff options
author | Philip Sargent <philip.sargent@gmail.com> | 2025-03-16 13:15:45 +0000 |
---|---|---|
committer | Philip Sargent <philip.sargent@gmail.com> | 2025-03-16 13:15:45 +0000 |
commit | 38130c876b86e2a014384d2d507dba77b8c84728 (patch) | |
tree | b3c14d73febefec18006df9367988754ab3f3dcc /core/utils.py | |
parent | 31c77fd89c831d4e6450d5b29755954e329d5d0f (diff) | |
download | troggle-38130c876b86e2a014384d2d507dba77b8c84728.tar.gz troggle-38130c876b86e2a014384d2d507dba77b8c84728.tar.bz2 troggle-38130c876b86e2a014384d2d507dba77b8c84728.zip |
attempt to reformat logbook entries.. fail. Too many side efefcts.
Diffstat (limited to 'core/utils.py')
-rw-r--r-- | core/utils.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/core/utils.py b/core/utils.py index 26be1a0..7e5b212 100644 --- a/core/utils.py +++ b/core/utils.py @@ -124,6 +124,56 @@ def alphabet_suffix(n): suffix = "_X_" + random.choice(string.ascii_lowercase) + random.choice(string.ascii_lowercase) return suffix +def wrap_text(text): + """ + Splits a long string into multiple lines, ensuring that each line is no more than + 70 characters long. Newline characters are inserted immediately before spaces to + prevent breaking words. + + Parameters: + text (str): The input string that needs to be wrapped. + + Returns: + str: The input string formatted with newline characters such that each line + does not exceed 70 characters in length. + + Functionality: + 1. The function first splits the input string into individual words. + 2. It iterates through the words and adds them to the current line, ensuring the + line's length does not exceed 70 characters. + 3. If adding a word would cause the line to exceed the limit, the current line is + added to a list of lines, and a new line is started with the word. + 4. The process repeats until all words are processed, and the final line is added. + 5. The list of lines is then joined with newline characters and returned as a + single formatted string. + + This function written by CoPilot. + BUT interactions between exisitng \n characters makes this much less simple than it appears. + """ + + return text # abort all wrap processing pending proper redesign + + words = text.split(' ') + lines = [] + current_line = "" + + for word in words: + # Check if adding the word exceeds 70 characters + if len(current_line) + len(word) + 1 <= 70: + if current_line: + current_line += ' ' + current_line += word + else: + lines.append(current_line.strip(' ')) + current_line = word + + # Add the last line + if current_line: + lines.append(current_line.strip(' ')) + + # Join the lines with newline characters + return '\n'.join(lines) + def make_new_expo(year): coUniqueAttribs = {"year": year} otherAttribs = {"name": f"CUCC expo {year}", "logbookfile": "logbook.html"} |