From 6710775882e6649da3a2b2a6f05c150c849be516 Mon Sep 17 00:00:00 2001 From: Lyz Date: Sat, 25 Jan 2025 14:22:23 +0100 Subject: [PATCH] fix: strip token_list_to_plaintext otherwise when you do headline.title.get_text() you may have trailing whitespaces --- org_rw/org_rw.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/org_rw/org_rw.py b/org_rw/org_rw.py index 31b904c..4fc5da5 100644 --- a/org_rw/org_rw.py +++ b/org_rw/org_rw.py @@ -415,7 +415,6 @@ class Headline: isinstance(line, DelimiterLine) and line.delimiter_type == DelimiterLineType.END_BLOCK ): - start = current_node.header.linenum end = line.linenum @@ -815,7 +814,6 @@ class Headline: def set_property(self, name: str, value: str): for prop in self.properties: - # A matching property is found, update it if prop.key == name: prop.value = value @@ -1000,7 +998,6 @@ class Headline: and result_first[0] == "structural" and result_first[1].strip().upper() == ":RESULTS:" ): - (end_line, _) = self.get_structural_end_after( kword.linenum + 1 ) @@ -1795,7 +1792,7 @@ def token_list_to_plaintext(tok_list) -> str: else: assert isinstance(chunk, MarkerToken) - return "".join(contents) + return "".join(contents).strip() def token_list_to_raw(tok_list): @@ -2017,7 +2014,6 @@ def tokenize_contents(contents: str) -> List[TokenItems]: and is_pre(last_char) and ((i + 1 < len(contents)) and is_border(contents[i + 1])) ): - is_valid_mark = False # Check that is closed later text_in_line = True @@ -2408,7 +2404,6 @@ class OrgDoc: # Writing def dump_headline(self, headline, recursive=True): - tags = "" if len(headline.shallow_tags) > 0: tags = ":" + ":".join(headline.shallow_tags) + ":" @@ -2422,7 +2417,14 @@ class OrgDoc: if not (raw_title.endswith(" ") or raw_title.endswith("\t")) and tags: tags_padding = " " - yield "*" * headline.depth + headline.spacing + state + raw_title + tags_padding + tags + yield ( + "*" * headline.depth + + headline.spacing + + state + + raw_title + + tags_padding + + tags + ) planning = headline.get_planning_line() if planning is not None: