From 69be461f4fd47571f2550d2d7ae5ce9e779f0cf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Techet?= Date: Sat, 1 Jan 2022 20:45:49 +0100 Subject: [PATCH] Markdown: handle XML/HTML comments --- .../xml-comment.d/args.ctags | 1 + .../xml-comment.d/expected.tags | 1 + .../parser-markdown.r/xml-comment.d/input.md | 7 +++++++ parsers/markdown.c | 20 +++++++++++++++++-- 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 Units/parser-markdown.r/xml-comment.d/args.ctags create mode 100644 Units/parser-markdown.r/xml-comment.d/expected.tags create mode 100644 Units/parser-markdown.r/xml-comment.d/input.md diff --git a/Units/parser-markdown.r/xml-comment.d/args.ctags b/Units/parser-markdown.r/xml-comment.d/args.ctags new file mode 100644 index 0000000000..5ee5f79f70 --- /dev/null +++ b/Units/parser-markdown.r/xml-comment.d/args.ctags @@ -0,0 +1 @@ +--sort=no diff --git a/Units/parser-markdown.r/xml-comment.d/expected.tags b/Units/parser-markdown.r/xml-comment.d/expected.tags new file mode 100644 index 0000000000..7153ca7c19 --- /dev/null +++ b/Units/parser-markdown.r/xml-comment.d/expected.tags @@ -0,0 +1 @@ +EXTRACT ME 1 input.md /^# EXTRACT ME 1$/;" c diff --git a/Units/parser-markdown.r/xml-comment.d/input.md b/Units/parser-markdown.r/xml-comment.d/input.md new file mode 100644 index 0000000000..e431eb962b --- /dev/null +++ b/Units/parser-markdown.r/xml-comment.d/input.md @@ -0,0 +1,7 @@ + + + + +# EXTRACT ME 1 diff --git a/parsers/markdown.c b/parsers/markdown.c index 8432e18ec9..effd726015 100644 --- a/parsers/markdown.c +++ b/parsers/markdown.c @@ -193,6 +193,7 @@ static void findMarkdownTags (void) long startSourceLineNumber = 0; long startLineNumber = 0; bool inPreambule = false; + bool inComment = false; nestingLevels = nestingLevelsNewFull (0, fillEndField); @@ -246,9 +247,24 @@ static void findMarkdownTags (void) lineProcessed = true; } } + /* XML comment start */ + else if (lineLen >= pos + 4 && line[pos] == '<' && line[pos + 1] == '!' && + line[pos + 2] == '-' && line[pos + 3] == '-') + { + if (strstr ((const char *)(line + pos + 4), "-->") == NULL) + inComment = true; + lineProcessed = true; + } + /* XML comment end */ + else if (lineLen >= pos + 3 && line[pos] == '-' && line[pos + 1] == '-' && + line[pos + 2] == '>') + { + inComment = false; + lineProcessed = true; + } - /* code block */ - if (inCodeChar) + /* code block or comment */ + if (inCodeChar || inComment) lineProcessed = true; /* code block using indent */