Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML comments in middle of block #181

Merged
merged 1 commit into from Nov 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/document.c
Expand Up @@ -402,9 +402,23 @@ tag_length(uint8_t *data, size_t size, hoedown_autolink_type *autolink)
/* a valid tag can't be shorter than 3 chars */
if (size < 3) return 0;

/* begins with a '<' optionally followed by '/', followed by letter or number */
if (data[0] != '<') return 0;
i = (data[1] == '/') ? 2 : 1;

/* HTML comment, laxist form */
if (size > 5 && data[1] == '!' && data[2] == '-' && data[3] == '-') {
i = 5;

while (i < size && !(data[i - 2] == '-' && data[i - 1] == '-' && data[i] == '>'))
i++;

i++;

if (i <= size)
return i;
}

/* begins with a '<' optionally followed by '/', followed by letter or number */
i = (data[1] == '/') ? 2 : 1;

if (!isalnum(data[i]))
return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/html_smartypants.c
Expand Up @@ -314,7 +314,7 @@ smartypants_cb__ltag(hoedown_buffer *ob, struct smartypants_data *smrt, uint8_t
size_t tag, i = 0;

/* This is a comment. Copy everything verbatim until --> or EOF is seen. */
if (i + 4 < size && memcmp(text, "<!--", 4) == 0) {
if (i + 4 < size && memcmp(text + i, "<!--", 4) == 0) {
i += 4;
while (i + 3 < size && memcmp(text + i, "-->", 3) != 0)
i++;
Expand Down
6 changes: 6 additions & 0 deletions test/Tests/CommentsInMiddleOfLine.html
@@ -0,0 +1,6 @@
<p>It would be super-keen to be able to use <a href=
"https://github.com/google/moe">MOE</a> directives in Markdown.</p>
<!-- HTML comments work at the start of a block -->
<p>But I'd <!-- MOE:begin_strip -->really, really
<!-- MOE:end_strip -->
like to be able to use them in the middle of a line.</p>
8 changes: 8 additions & 0 deletions test/Tests/CommentsInMiddleOfLine.text
@@ -0,0 +1,8 @@
It would be super-keen to be able to use [MOE](https://github.com/google/moe)
directives in Markdown.

<!-- HTML comments work at the start of a block -->

But I'd <!-- MOE:begin_strip -->really, really <!-- MOE:end_strip -->
like to be able to use them in the middle of a line.

4 changes: 4 additions & 0 deletions test/config.json
Expand Up @@ -97,6 +97,10 @@
"output": "Tests/Formatting in Table of Contents.html",
"flags": ["--html-toc", "-t", "3"]
},
{
"input": "Tests/CommentsInMiddleOfLine.text",
"output": "Tests/CommentsInMiddleOfLine.html"
},
{
"input": "Tests/Math.text",
"output": "Tests/Math.html",
Expand Down