Skip to content

Commit

Permalink
Merge pull request hoedown#181 from mikesamuel/master
Browse files Browse the repository at this point in the history
HTML comments in middle of block
  • Loading branch information
mildsunrise committed Nov 20, 2015
2 parents ca4609d + 8635ebf commit d8d37c3
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
18 changes: 16 additions & 2 deletions src/document.c
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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

0 comments on commit d8d37c3

Please sign in to comment.