Skip to content

Commit 5637294

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

4 files changed

Lines changed: 89 additions & 5 deletions

File tree

taskwiki/main.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,14 @@ def task_info_or_vimwiki_follow_link():
271271
']]' in line,
272272
column >= line.find('[['),
273273
column <= line.find(']]') + 1
274+
]) or all([
275+
'[' in line,
276+
'](' in line,
277+
')' in line,
278+
line.find('[') < line.find(']('),
279+
line.find('](') < line.find(')'),
280+
column >= line.find('['),
281+
column <= line.find(')') + 1
274282
])
275283

276284
if inside_vimwiki_link:

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*)|(.*\[\[.*]].*))'
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: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,75 @@ 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_as_header_name_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_as_header_name_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'
190+
191+
def test_vimwiki_link_in_header_name_simple(self, test_syntax):
192+
if test_syntax[0] == 'default':
193+
example_viewport = "HEADER2(Link to [[this|https://www.vim.org]] | project:Home)"
194+
elif test_syntax[0] == 'markdown':
195+
example_viewport = "HEADER2(Link to [this](https://www.vim.org) | project:Home)"
196+
197+
port = self.process_viewport(example_viewport, test_syntax)
198+
199+
assert port.taskfilter == list(DEFAULT_VIEWPORT_VIRTUAL_TAGS) + ["(", "project:Home", ")"]
200+
201+
if test_syntax[0] == 'default':
202+
assert port.name == "Link to [[this|https://www.vim.org]]"
203+
elif test_syntax[0] == 'markdown':
204+
assert port.name == "Link to [this](https://www.vim.org)"
205+
206+
assert port.defaults == {'project':'Home'}
207+
assert port.sort == DEFAULT_SORT_ORDER
208+
assert port.tw == 'default'
209+
210+
def test_vimwiki_link_in_header_name_with_defaults(self, test_syntax):
211+
if test_syntax[0] == 'default':
212+
example_viewport = "HEADER2(Link to [[this|https://www.vim.org]] | project:Home)"
213+
elif test_syntax[0] == 'markdown':
214+
example_viewport = "HEADER2(Link to [this](https://www.vim.org) | project:Home)"
215+
216+
port = self.process_viewport(example_viewport, test_syntax)
217+
218+
assert port.taskfilter == list(DEFAULT_VIEWPORT_VIRTUAL_TAGS) + ["(", "project:Home", ")"]
219+
if test_syntax[0] == 'default':
220+
assert port.name == "Link to [[this|https://www.vim.org]]"
221+
elif test_syntax[0] == 'markdown':
222+
assert port.name == "Link to [this](https://www.vim.org)"
223+
assert port.defaults == {'project':'Home'}
224+
assert port.sort == DEFAULT_SORT_ORDER
225+
assert port.tw == 'default'

0 commit comments

Comments
 (0)