From 59def4c00490cf294f344639b5fb23e53884552e Mon Sep 17 00:00:00 2001 From: "John D. Fisher" Date: Sat, 27 Apr 2024 16:30:43 -0700 Subject: [PATCH] fix(delete_taskwiki_heading): add markdown Remove anchors which are misleading. Remove xfail for delete_taskwiki_heading. --- .../filter/delete_taskwiki_heading.py | 22 +++++++++++++++---- tests/func/convert.md | 16 +++++++------- tests/func/convert_shift.md | 16 +++++++------- .../out/delete_taskwiki_heading.wiki.md | 6 ++--- tests/unit/test_filters.py | 1 - 5 files changed, 37 insertions(+), 24 deletions(-) diff --git a/src/panvimwiki/filter/delete_taskwiki_heading.py b/src/panvimwiki/filter/delete_taskwiki_heading.py index a49055f..ac29fd1 100755 --- a/src/panvimwiki/filter/delete_taskwiki_heading.py +++ b/src/panvimwiki/filter/delete_taskwiki_heading.py @@ -24,13 +24,22 @@ def prepare(doc): def action(elem, doc): """Remove taskwiki heading.""" - regex = re.compile(r"\|.*$", re.MULTILINE) + regex = re.compile(r"(\\\||\{#).*$", re.MULTILINE) subst = "" if isinstance(elem, pf.Header): - result = re.sub(regex, subst, elem.identifier, 0) + result = re.sub( + regex, + subst, + pf.convert_text( + text=elem, + input_format="panflute", + output_format="markdown", + ), + 0, + ) elem.content = pf.convert_text(result)[0].content - elem.identifier = result + elem.identifier = "" return elem # return None -> element unchanged # return [] -> delete element @@ -46,7 +55,12 @@ def main(doc=None): Pandoc filter using panflute """ - return pf.run_filter(action, prepare=prepare, finalize=finalize, doc=doc) + return pf.run_filter( + action, + prepare=prepare, + finalize=finalize, + doc=doc, + ) if __name__ == "__main__": diff --git a/tests/func/convert.md b/tests/func/convert.md index 7dd8178..3c5bf7c 100644 --- a/tests/func/convert.md +++ b/tests/func/convert.md @@ -1,6 +1,6 @@ -# Journal 2017-04-24 {#Journal 2017-04-24} +# Journal 2017-04-24 -## Ordered List {#Ordered List} +## Ordered List 1. []{.done4}OrderedList done4 should appear []{#-InlineTagShouldAppear}[InlineTagShouldAppear]{#InlineTagShouldAppear @@ -13,7 +13,7 @@ 6. OrderedList should appear 1. OrderedList a) should appear -### Definition List {#Definition List} +### Definition List Term 1 : Definition 1 should appear @@ -23,7 +23,7 @@ Term 2 : Definition 2 should appear : Definition 3 should appear -### Unordered lists {#Unordered lists} +### Unordered lists - Bulleted list item 1 should appear - Bulleted list item 1 should appear @@ -41,18 +41,18 @@ Term 2 Del_empty_heading will remove the following, but del_taskwiki_heading will only remove the taskwiki heading: -### Text {#Text} +### Text Normal text should appear with only one blank line preceding next heading. -## Empty Parent Heading with Non-Empty Child should appear {#Empty Parent Heading with Non-Empty Child should appear} +## Empty Parent Heading with Non-Empty Child should appear -### Non-Empty Child Heading should appear {#Non-Empty Child Heading should appear} +### Non-Empty Child Heading should appear Non-Empty Child text should appear. -# Journal 2017-04-26 {#Journal 2017-04-26} +# Journal 2017-04-26 Should concatenate non-contiguous Monday and Wednesday and ignore missing Tuesday and Thursday. Spurious not for test validation. diff --git a/tests/func/convert_shift.md b/tests/func/convert_shift.md index fb0761f..cf2acca 100644 --- a/tests/func/convert_shift.md +++ b/tests/func/convert_shift.md @@ -1,6 +1,6 @@ -## Journal 2017-04-24 {#Journal 2017-04-24} +## Journal 2017-04-24 -### Ordered List {#Ordered List} +### Ordered List 1. []{.done4}OrderedList done4 should appear []{#-InlineTagShouldAppear}[InlineTagShouldAppear]{#InlineTagShouldAppear @@ -13,7 +13,7 @@ 6. OrderedList should appear 1. OrderedList a) should appear -#### Definition List {#Definition List} +#### Definition List Term 1 : Definition 1 should appear @@ -23,7 +23,7 @@ Term 2 : Definition 2 should appear : Definition 3 should appear -#### Unordered lists {#Unordered lists} +#### Unordered lists - Bulleted list item 1 should appear - Bulleted list item 1 should appear @@ -41,18 +41,18 @@ Term 2 Del_empty_heading will remove the following, but del_taskwiki_heading will only remove the taskwiki heading: -#### Text {#Text} +#### Text Normal text should appear with only one blank line preceding next heading. -### Empty Parent Heading with Non-Empty Child should appear {#Empty Parent Heading with Non-Empty Child should appear} +### Empty Parent Heading with Non-Empty Child should appear -#### Non-Empty Child Heading should appear {#Non-Empty Child Heading should appear} +#### Non-Empty Child Heading should appear Non-Empty Child text should appear. -## Journal 2017-04-26 {#Journal 2017-04-26} +## Journal 2017-04-26 Should concatenate non-contiguous Monday and Wednesday and ignore missing Tuesday and Thursday. Spurious not for test validation. diff --git a/tests/unit/filter/out/delete_taskwiki_heading.wiki.md b/tests/unit/filter/out/delete_taskwiki_heading.wiki.md index 8727d65..86ecba8 100644 --- a/tests/unit/filter/out/delete_taskwiki_heading.wiki.md +++ b/tests/unit/filter/out/delete_taskwiki_heading.wiki.md @@ -1,13 +1,13 @@ -# Vimwiki with Taskwiki Content {#Vimwiki with Taskwiki Content} +# Vimwiki with Taskwiki Content - [Wikilinks URL should be converted](file:URI) - [Wikilinks URL should be converted](d "wikilink") -## Taskwiki Viewports {#Taskwiki Viewports } +## Taskwiki Viewports The heading should convert the Viewports should not. -### Taskwiki Preset Headers {#Taskwiki Preset Headers } +### Taskwiki Preset Headers The heading should convert the Preset should not. diff --git a/tests/unit/test_filters.py b/tests/unit/test_filters.py index 630d571..2aac024 100644 --- a/tests/unit/test_filters.py +++ b/tests/unit/test_filters.py @@ -104,7 +104,6 @@ def pandoc_filter_fixture(): if filters in [ "pandoc_filter/delete_tag_lines.md", - "pandoc_filter/delete_taskwiki_heading.md", ]: marks = pytest.mark.xfail(reason=f"{filters} not implemented") yield pytest.param(test_input, expected, id=filters, marks=marks)