Skip to content

Commit

Permalink
fix(delete_taskwiki_heading): add markdown
Browse files Browse the repository at this point in the history
Remove anchors which are misleading.

Remove xfail for delete_taskwiki_heading.
  • Loading branch information
jfishe committed Apr 27, 2024
1 parent 8c9459a commit 59def4c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 24 deletions.
22 changes: 18 additions & 4 deletions src/panvimwiki/filter/delete_taskwiki_heading.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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__":
Expand Down
16 changes: 8 additions & 8 deletions tests/func/convert.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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.
16 changes: 8 additions & 8 deletions tests/func/convert_shift.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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.
6 changes: 3 additions & 3 deletions tests/unit/filter/out/delete_taskwiki_heading.wiki.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
1 change: 0 additions & 1 deletion tests/unit/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 59def4c

Please sign in to comment.