Proposed alternative fix for the title stripping issue #1

Open
kenkeiras wants to merge 5 commits from kenkeiras/org-rw:proposed-fix/strip-title into fix/strip-title
Showing only changes of commit 14e344981b - Show all commits

View File

@ -67,7 +67,9 @@ BASE_ENVIRONMENT = {
), ),
} }
HEADLINE_TAGS_RE = re.compile(r"((?P<space_before_tags>\s+)(:(\w|[0-9_@#%])+)+:)(?P<space_after_tags>\s*)$") HEADLINE_TAGS_RE = re.compile(
r"((?P<space_before_tags>\s+)(:(\w|[0-9_@#%])+)+:)(?P<space_after_tags>\s*)$"
)
HEADLINE_RE = re.compile(r"^(?P<stars>\*+)(?P<spacing>\s+)(?P<line>.*?)$") HEADLINE_RE = re.compile(r"^(?P<stars>\*+)(?P<spacing>\s+)(?P<line>.*?)$")
KEYWORDS_RE = re.compile( KEYWORDS_RE = re.compile(
r"^(?P<indentation>\s*)#\+(?P<key>[^:\[]+)(\[(?P<options>[^\]]*)\])?:(?P<spacing>\s*)(?P<value>.*)$" r"^(?P<indentation>\s*)#\+(?P<key>[^:\[]+)(\[(?P<options>[^\]]*)\])?:(?P<spacing>\s*)(?P<value>.*)$"
@ -2186,11 +2188,11 @@ def parse_headline(hl, doc, parent) -> Headline:
if hl_tags is None: if hl_tags is None:
tags = [] tags = []
space_before_tags = space_after_tags = '' space_before_tags = space_after_tags = ""
else: else:
tags = hl_tags.group(0).strip()[1:-1].split(":") tags = hl_tags.group(0).strip()[1:-1].split(":")
space_before_tags = hl_tags.group('space_before_tags') or '' space_before_tags = hl_tags.group("space_before_tags") or ""
space_after_tags = hl_tags.group('space_after_tags') or '' space_after_tags = hl_tags.group("space_after_tags") or ""
line = HEADLINE_TAGS_RE.sub("", line) line = HEADLINE_TAGS_RE.sub("", line)
hl_state = None hl_state = None
@ -2212,7 +2214,7 @@ def parse_headline(hl, doc, parent) -> Headline:
if len(tags) == 0: if len(tags) == 0:
# No tags, so title might contain trailing whitespaces, handle it # No tags, so title might contain trailing whitespaces, handle it
title_ends_with_whitespace_match = re.search(r'\s+$', title) title_ends_with_whitespace_match = re.search(r"\s+$", title)
if title_ends_with_whitespace_match is not None: if title_ends_with_whitespace_match is not None:
space_before_tags = title_ends_with_whitespace_match.group(0) space_before_tags = title_ends_with_whitespace_match.group(0)
title = title[: -len(space_before_tags)] title = title[: -len(space_before_tags)]
@ -2448,7 +2450,9 @@ class OrgDoc:
def dump_headline(self, headline, recursive=True): def dump_headline(self, headline, recursive=True):
tags = headline.space_before_tags tags = headline.space_before_tags
if len(headline.shallow_tags) > 0: if len(headline.shallow_tags) > 0:
tags += ":" + ":".join(headline.shallow_tags) + ":" + headline.space_after_tags tags += (
":" + ":".join(headline.shallow_tags) + ":" + headline.space_after_tags
)
state = "" state = ""
if headline._state: if headline._state:
@ -2456,13 +2460,7 @@ class OrgDoc:
raw_title = token_list_to_raw(headline.title.contents) raw_title = token_list_to_raw(headline.title.contents)
yield ( yield ("*" * headline.depth + headline.spacing + state + raw_title + tags)
"*" * headline.depth
+ headline.spacing
+ state
+ raw_title
+ tags
)
planning = headline.get_planning_line() planning = headline.get_planning_line()
if planning is not None: if planning is not None: