From 121ad46680c32b705a35e1ccc1355a0037f7502d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Mart=C3=ADnez=20Portela?= Date: Fri, 26 Aug 2022 19:04:50 +0200 Subject: [PATCH] Support text markup on list tags. --- org_rw/org_rw.py | 11 ++++++++--- tests/06-lists.org | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/org_rw/org_rw.py b/org_rw/org_rw.py index 6bb96c3..2b7ce1d 100644 --- a/org_rw/org_rw.py +++ b/org_rw/org_rw.py @@ -185,6 +185,9 @@ def get_links_from_content(content): link_value.append(tok) def text_to_dom(tokens, item): + if tokens is None: + return [] + in_link = False in_description = False link_value = [] @@ -421,7 +424,7 @@ class Headline: else: current_node = indentation_tree[-1] - node = dom.ListItem(line.tag, text_to_dom(line.content, line), orig=line) + node = dom.ListItem(text_to_dom(line.tag, line), text_to_dom(line.content, line), orig=line) current_node.append(node) elif ( @@ -1464,7 +1467,7 @@ def dump_contents(raw): bullet = raw.bullet if raw.bullet else raw.counter + raw.counter_sep content = token_list_to_raw(raw.content) checkbox = f"[{raw.checkbox_value}]" if raw.checkbox_value else "" - tag = f"{raw.tag_indentation}{raw.tag}::" if raw.tag else "" + tag = f"{raw.tag_indentation}{token_list_to_raw(raw.tag)}::" if raw.tag else "" return ( raw.linenum, f"{raw.indentation}{bullet}{checkbox}{tag}{content}", @@ -1847,7 +1850,9 @@ class OrgDocReader: match.group("checkbox_indentation"), match.group("checkbox_value"), match.group("tag_indentation"), - match.group("tag"), + parse_content_block( + [RawLine(linenum=linenum, line=match.group("tag"))] + ).contents if match.group("tag") else None, parse_content_block( [RawLine(linenum=linenum, line=match.group("content"))] ).contents, diff --git a/tests/06-lists.org b/tests/06-lists.org index 97ef57c..b80e358 100644 --- a/tests/06-lists.org +++ b/tests/06-lists.org @@ -37,3 +37,17 @@ Also represented as 1) First element 2) Second element + +* Definition lists + :PROPERTIES: + :ID: 06-definition-lists + :CREATED: [2020-01-01 Wed 01:01] + :END: + + - Key :: Value + - Key2 :: Value2 + +Also with markup + +- _Key_ :: _Value_ +- /Key/ 2 :: /Value/ 2