Skip to content

Commit 6e12137

Browse files
committed
Allows links in viewport names
1 parent 4bb8e53 commit 6e12137

File tree

4 files changed

+89
-5
lines changed

4 files changed

+89
-5
lines changed

taskwiki/main.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,14 @@ def task_info_or_vimwiki_follow_link():
299299
']]' in line,
300300
column >= line.find('[['),
301301
column <= line.find(']]') + 1
302+
]) or all([
303+
'[' in line,
304+
'](' in line,
305+
')' in line,
306+
line.find('[') < line.find(']('),
307+
line.find('](') < line.find(')'),
308+
column >= line.find('['),
309+
column <= line.find(')') + 1
302310
])
303311

304312
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
@@ -68,8 +72,8 @@
6872
re.compile(
6973
r'^' # Starts at the begging of the line
7074
r'(?P<header_start>[#]+)' # Heading begging
71-
r'(?P<name>[^#\|\[\{]*)' # Name of the viewport, all before the | sign
72-
# Cannot include '[', '#', '|', and '{'
75+
r'(?P<name>[^#\|]*)' # Name of the viewport, all before the | sign
76+
# Cannot include '#'
7377
r'\|' # Bar
7478
r'(?!\|)' # (But not two, that would be a preset)
7579
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 + r'\((.*?)\)'
40+
regex = header_level + r'\((.*)\)'
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
@@ -159,3 +159,75 @@ def test_override_default_virtual_tags_positive_without_forcing(self, test_synta
159159
assert port.defaults == {'project':'Home'}
160160
assert port.sort == DEFAULT_SORT_ORDER
161161
assert port.tw == 'default'
162+
163+
def test_vimwiki_link_as_header_name_simple(self, test_syntax):
164+
if test_syntax[0] == 'default':
165+
example_viewport = "HEADER2([[Test|https://www.vim.org]] | project:Home)"
166+
elif test_syntax[0] == 'markdown':
167+
example_viewport = "HEADER2([Test](https://www.vim.org) | project:Home)"
168+
169+
port = self.process_viewport(example_viewport, test_syntax)
170+
171+
assert port.taskfilter == list(DEFAULT_VIEWPORT_VIRTUAL_TAGS) + ["(", "project:Home", ")"]
172+
173+
if test_syntax[0] == 'default':
174+
assert port.name == "[[Test|https://www.vim.org]]"
175+
elif test_syntax[0] == 'markdown':
176+
assert port.name == "[Test](https://www.vim.org)"
177+
178+
assert port.defaults == {'project':'Home'}
179+
assert port.sort == DEFAULT_SORT_ORDER
180+
assert port.tw == 'default'
181+
182+
def test_vimwiki_link_as_header_name_with_defaults(self, test_syntax):
183+
if test_syntax[0] == 'default':
184+
example_viewport = "HEADER2([[Test|https://www.vim.org]] | project:Home)"
185+
elif test_syntax[0] == 'markdown':
186+
example_viewport = "HEADER2([Test](https://www.vim.org) | project:Home)"
187+
188+
port = self.process_viewport(example_viewport, test_syntax)
189+
190+
assert port.taskfilter == list(DEFAULT_VIEWPORT_VIRTUAL_TAGS) + ["(", "project:Home", ")"]
191+
if test_syntax[0] == 'default':
192+
assert port.name == "[[Test|https://www.vim.org]]"
193+
elif test_syntax[0] == 'markdown':
194+
assert port.name == "[Test](https://www.vim.org)"
195+
assert port.defaults == {'project':'Home'}
196+
assert port.sort == DEFAULT_SORT_ORDER
197+
assert port.tw == 'default'
198+
199+
def test_vimwiki_link_in_header_name_simple(self, test_syntax):
200+
if test_syntax[0] == 'default':
201+
example_viewport = "HEADER2(Link to [[this|https://www.vim.org]] | project:Home)"
202+
elif test_syntax[0] == 'markdown':
203+
example_viewport = "HEADER2(Link to [this](https://www.vim.org) | project:Home)"
204+
205+
port = self.process_viewport(example_viewport, test_syntax)
206+
207+
assert port.taskfilter == list(DEFAULT_VIEWPORT_VIRTUAL_TAGS) + ["(", "project:Home", ")"]
208+
209+
if test_syntax[0] == 'default':
210+
assert port.name == "Link to [[this|https://www.vim.org]]"
211+
elif test_syntax[0] == 'markdown':
212+
assert port.name == "Link to [this](https://www.vim.org)"
213+
214+
assert port.defaults == {'project':'Home'}
215+
assert port.sort == DEFAULT_SORT_ORDER
216+
assert port.tw == 'default'
217+
218+
def test_vimwiki_link_in_header_name_with_defaults(self, test_syntax):
219+
if test_syntax[0] == 'default':
220+
example_viewport = "HEADER2(Link to [[this|https://www.vim.org]] | project:Home)"
221+
elif test_syntax[0] == 'markdown':
222+
example_viewport = "HEADER2(Link to [this](https://www.vim.org) | project:Home)"
223+
224+
port = self.process_viewport(example_viewport, test_syntax)
225+
226+
assert port.taskfilter == list(DEFAULT_VIEWPORT_VIRTUAL_TAGS) + ["(", "project:Home", ")"]
227+
if test_syntax[0] == 'default':
228+
assert port.name == "Link to [[this|https://www.vim.org]]"
229+
elif test_syntax[0] == 'markdown':
230+
assert port.name == "Link to [this](https://www.vim.org)"
231+
assert port.defaults == {'project':'Home'}
232+
assert port.sort == DEFAULT_SORT_ORDER
233+
assert port.tw == 'default'

0 commit comments

Comments
 (0)