From 490b36887aebb9273bb5daf628eafd437fc79cf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Mart=C3=ADnez=20Portela?= Date: Thu, 22 Aug 2024 00:20:15 +0200 Subject: [PATCH 1/4] Require space before list item tag separator. --- org_rw/org_rw.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/org_rw/org_rw.py b/org_rw/org_rw.py index 970f641..5f49c26 100644 --- a/org_rw/org_rw.py +++ b/org_rw/org_rw.py @@ -103,7 +103,7 @@ PLANNING_RE = re.compile( r")+\s*" ) LIST_ITEM_RE = re.compile( - r"(?P\s*)((?P[*\-+])|((?P\d|[a-zA-Z])(?P[.)]))) ((?P\s*)\[(?P[ Xx])\])?((?P\s*)(?P.*?)::)?(?P.*)" + r"(?P\s*)((?P[*\-+])|((?P\d|[a-zA-Z])(?P[.)]))) ((?P\s*)\[(?P[ Xx])\])?((?P\s*)((?P.*?)\s::))?(?P.*)" ) IMPLICIT_LINK_RE = re.compile(r"(https?:[^<> ]*[a-zA-Z0-9])") @@ -2052,7 +2052,7 @@ def dump_contents(raw): content = "\n".join(content_lines) checkbox = f"[{raw.checkbox_value}]" if raw.checkbox_value else "" tag = ( - f"{raw.tag_indentation}{token_list_to_raw(raw.tag or '')}::" + f"{raw.tag_indentation}{token_list_to_raw(raw.tag or '')} ::" if raw.tag or raw.tag_indentation else "" ) -- 2.45.2 From f31c64c2426b1400320f481042964fd61a05a265 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Mart=C3=ADnez=20Portela?= Date: Thu, 22 Aug 2024 00:20:44 +0200 Subject: [PATCH 2/4] Properly track which tokens are used for closing formats. --- org_rw/org_rw.py | 1 + 1 file changed, 1 insertion(+) diff --git a/org_rw/org_rw.py b/org_rw/org_rw.py index 5f49c26..b8dccac 100644 --- a/org_rw/org_rw.py +++ b/org_rw/org_rw.py @@ -1962,6 +1962,7 @@ def tokenize_contents(contents: str) -> List[TokenItems]: cut_string() tokens.append((TOKEN_TYPE_CLOSE_MARKER, char)) has_changed = True + closes.remove(i) if not has_changed: text.append(char) -- 2.45.2 From 5552b3324b1f0503129f678d4495ad36e121f695 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Mart=C3=ADnez=20Portela?= Date: Thu, 22 Aug 2024 00:21:02 +0200 Subject: [PATCH 3/4] Handle `]` which not close link descriptions or references. --- org_rw/org_rw.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org_rw/org_rw.py b/org_rw/org_rw.py index b8dccac..6cc4cef 100644 --- a/org_rw/org_rw.py +++ b/org_rw/org_rw.py @@ -1911,7 +1911,7 @@ def tokenize_contents(contents: str) -> List[TokenItems]: continue # Possible link close or open of description - if char == "]" and len(contents) > i + 1 and in_link: + if char == "]" and len(contents) > i + 1 and in_link and contents[i + 1] in "][": if contents[i + 1] == "]": cut_string() -- 2.45.2 From 4af4cda44b84c798ac934b559aab68e99c3876d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Mart=C3=ADnez=20Portela?= Date: Thu, 22 Aug 2024 00:26:11 +0200 Subject: [PATCH 4/4] Fix formatting. --- org_rw/org_rw.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/org_rw/org_rw.py b/org_rw/org_rw.py index 6cc4cef..99ac122 100644 --- a/org_rw/org_rw.py +++ b/org_rw/org_rw.py @@ -1911,7 +1911,12 @@ def tokenize_contents(contents: str) -> List[TokenItems]: continue # Possible link close or open of description - if char == "]" and len(contents) > i + 1 and in_link and contents[i + 1] in "][": + if ( + char == "]" + and len(contents) > i + 1 + and in_link + and contents[i + 1] in "][" + ): if contents[i + 1] == "]": cut_string() -- 2.45.2