Skip to content
Snippets Groups Projects
Commit 60cc9332 authored by Frank Sauerburger's avatar Frank Sauerburger
Browse files

Make --> optional in markdown command line

Don't enforce the end comment characters --> in markdowns command line. This
closes #2. The new implementation however, enforce that > is not used in
neither the command nor the args.
parent de007e33
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -199,19 +199,25 @@ class Markdown(DoxecSyntax):
<!-- COMMAND ARGS -->
The args part must not contain the greater than '>" character. The
trailing '-->' is optional.
None is returned, if the format does not match. If a valid line is
found, the tuple (command, args) is returned.
>>> Markdown.parse_command("<!-- write file.txt -->")
('write', 'file.txt')
>>> Markdown.parse_command("<!-- invalid line ") is None
>>> Markdown.parse_command("<!-- write file.txt")
('write', 'file.txt')
>>> Markdown.parse_command("-- invalid line -->") is None
True
"""
match = re.match(r"<!--\s+(\S.*\S)\s+-->\s*$", line)
match = re.match(r"<!--\s+([^> \t\n\r\f\v][^>]*)(\s+-->)?\s*$", line)
if match is None:
return None
token = re.split("\s+", match.group(1), maxsplit=1)
token = re.split("\s+", match.group(1).strip(), maxsplit=1)
if len(token) == 2:
return tuple(token)
else:
......
......@@ -14,6 +14,14 @@ class MarkdownSyntaxTestCase(unittest.TestCase):
retval = Markdown.parse_command("<!-- WRITE hello_world.c -->")
self.assertEqual(retval, ("WRITE", "hello_world.c"))
def test_parse_command_valid_no_end(self):
"""
Run parse_command on an input without the comment end `-->` and check
the return value.
"""
retval = Markdown.parse_command("<!-- WRITE hello_world.c")
self.assertEqual(retval, ("WRITE", "hello_world.c"))
def test_parse_command_whitespace(self):
"""
Run parse_command on a valid input with whitespace added/removed in various
......@@ -69,6 +77,7 @@ class MarkdownSyntaxTestCase(unittest.TestCase):
retval = Markdown.parse_command("<! -- WRITE hello_world.c -->")
self.assertIsNone(retval)
# this is still invalid, since the args part must not contain '>'
retval = Markdown.parse_command("<!-- WRITE hello_world.c - ->")
self.assertIsNone(retval)
......@@ -83,9 +92,6 @@ class MarkdownSyntaxTestCase(unittest.TestCase):
retval = Markdown.parse_command("!-- WRITE hello_world.c -->")
self.assertIsNone(retval)
retval = Markdown.parse_command("<!-- WRITE hello_world.c ")
self.assertIsNone(retval)
retval = Markdown.parse_command("WRITE hello_world.c")
self.assertIsNone(retval)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment