diff --git a/README.md b/README.md index eae3f59..a5c2693 100644 --- a/README.md +++ b/README.md @@ -169,6 +169,7 @@ Inline directives occur in the body of comment blocks. Most take one argument enclosed in parenthesis. - `@function(name)` generates a link to a function defined in the plugin. + The equivalent spelling `@function(name())` is also accepted. - `@command(name)` generates a link to a command defined in the plugin. - `@flag(name)` generates a link to a flag defined in the plugin. - `@setting(name)` generates a link to a setting defined in the plugin. diff --git a/tests/test_function_link_parentheses.py b/tests/test_function_link_parentheses.py new file mode 100644 index 0000000..a7af74f --- /dev/null +++ b/tests/test_function_link_parentheses.py @@ -0,0 +1,22 @@ +import unittest + +from vimdoc import module +from vimdoc import output + + +class TestFunctionLinkParentheses(unittest.TestCase): + + def setUp(self): + self.writer = output.Helpfile( + module.Module('example', module.VimPlugin('example')), '.') + + def test_function_call_spelling_matches_plain_name(self): + self.assertEqual('See |foo#Bar()| and |foo#Bar()|.', self.writer.Expand( + 'See @function(foo#Bar()) and @function(foo#Bar).', None)) + + def test_relative_function_name_with_parentheses(self): + self.assertEqual('|example#Bar()|', self.writer.Expand( + '@function(#Bar())', 'example#')) + + def test_unknown_directive_keeps_its_parentheses(self): + self.assertEqual('@unknown(Foo())', self.writer.Expand('@unknown(Foo())', None)) diff --git a/vimdoc/output.py b/vimdoc/output.py index 6e2a267..0d5d1e0 100644 --- a/vimdoc/output.py +++ b/vimdoc/output.py @@ -259,6 +259,8 @@ def ExpandInline(self, inline, element, namespace): if inline == 'section': return self.Link(self.Slug(element)) elif inline == 'function': + if element.endswith('()'): + element = element[:-2] # If a user says @function(#Foo) then that points to in#this#file#Foo. if element.startswith('#'): element = (namespace or '') + element[1:] diff --git a/vimdoc/regex.py b/vimdoc/regex.py index 725fe28..bde0613 100644 --- a/vimdoc/regex.py +++ b/vimdoc/regex.py @@ -357,7 +357,7 @@ def _DelimitedRegex(pattern): \s*\) )? """, re.VERBOSE) -inline_directive = re.compile(r'@([a-zA-Z_][a-zA-Z0-9_]*)(?:\(([^\s)]+)\))?') +inline_directive = re.compile(r'@([a-zA-Z_][a-zA-Z0-9_]*)(?:\(((?:[^\s()]|\(\))+)\))?') name_hole = re.compile(r'<>') arg_hole = re.compile(r'{\]')