Skip to content

Commit 79df411

Browse files
committed
Allows links in viewport names
1 parent 377aac6 commit 79df411

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
lines changed

taskwiki/regexp.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,12 @@
4646
re.compile(
4747
r'^' # Starts at the begging of the line
4848
r'(?P<header_start>[=]+)' # Heading begging
49-
r'(?P<name>[^=\|\[\{]*)' # Name of the viewport, all before the | sign
50-
# Cannot include '[', '=', '|', and '{'
49+
50+
r'(?P<name>([^=\|\[\{]*)|(\s*\{\{.*}}\s*)|(\s*\[\[.*]]\s*))'
51+
# Name of the viewport, either with
52+
# a vimwiki link or without
53+
# Cannot include '='
54+
5155
r'\|' # Bar
5256
r'(?!\|)' # (But not two, that would be a preset)
5357
r'(?P<filter>[^=\|]*?)' # Filter
@@ -66,8 +70,8 @@
6670
re.compile(
6771
r'^' # Starts at the begging of the line
6872
r'(?P<header_start>[#]+)' # Heading begging
69-
r'(?P<name>[^#\|\[\{]*)' # Name of the viewport, all before the | sign
70-
# Cannot include '[', '#', '|', and '{'
73+
r'(?P<name>[^#\|]*)' # Name of the viewport, all before the | sign
74+
# Cannot include '#'
7175
r'\|' # Bar
7276
r'(?!\|)' # (But not two, that would be a preset)
7377
r'(?P<filter>[^#\|]*?)' # Filter

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def header_expand(string):
3737
inclusive.
3838
"""
3939
for header_level, format_header in format_header_dict.items():
40-
regex = header_level + '\((.*?)\)'
40+
regex = header_level + '\((.*)\)'
4141
string = re.sub(regex,
4242
lambda match: format_header % match.group(1),
4343
string)

tests/test_viewport_parsing.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,39 @@ def test_override_default_virtual_tags_positive_without_forcing(self, test_synta
151151
assert port.defaults == {'project':'Home'}
152152
assert port.sort == DEFAULT_SORT_ORDER
153153
assert port.tw == 'default'
154+
155+
def test_vimwiki_link_in_header_simple(self, test_syntax):
156+
if test_syntax[0] == 'default':
157+
example_viewport = "HEADER2([[Test|https://www.vim.org]] | project:Home)"
158+
elif test_syntax[0] == 'markdown':
159+
example_viewport = "HEADER2([Test](https://www.vim.org) | project:Home)"
160+
161+
port = self.process_viewport(example_viewport, test_syntax)
162+
163+
assert port.taskfilter == list(DEFAULT_VIEWPORT_VIRTUAL_TAGS) + ["(", "project:Home", ")"]
164+
165+
if test_syntax[0] == 'default':
166+
assert port.name == "[[Test|https://www.vim.org]]"
167+
elif test_syntax[0] == 'markdown':
168+
assert port.name == "[Test](https://www.vim.org)"
169+
170+
assert port.defaults == {'project':'Home'}
171+
assert port.sort == DEFAULT_SORT_ORDER
172+
assert port.tw == 'default'
173+
174+
def test_vimwiki_link_in_header_with_defaults(self, test_syntax):
175+
if test_syntax[0] == 'default':
176+
example_viewport = "HEADER2([[Test|https://www.vim.org]] | project:Home)"
177+
elif test_syntax[0] == 'markdown':
178+
example_viewport = "HEADER2([Test](https://www.vim.org) | project:Home)"
179+
180+
port = self.process_viewport(example_viewport, test_syntax)
181+
182+
assert port.taskfilter == list(DEFAULT_VIEWPORT_VIRTUAL_TAGS) + ["(", "project:Home", ")"]
183+
if test_syntax[0] == 'default':
184+
assert port.name == "[[Test|https://www.vim.org]]"
185+
elif test_syntax[0] == 'markdown':
186+
assert port.name == "[Test](https://www.vim.org)"
187+
assert port.defaults == {'project':'Home'}
188+
assert port.sort == DEFAULT_SORT_ORDER
189+
assert port.tw == 'default'

0 commit comments

Comments
 (0)