Skip to content

Commit

Permalink
md_is_html_comment: Reflect updated spec.txt.
Browse files Browse the repository at this point in the history
* Accept "<!-->" and "<!--->" as valid HTML comments.
* HTML comment now can contain "--"
  • Loading branch information
mity committed Jan 11, 2024
1 parent 0f9d3b0 commit aac6db0
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions src/md4c.c
Original file line number Diff line number Diff line change
Expand Up @@ -1201,26 +1201,13 @@ md_is_html_comment(MD_CTX* ctx, const MD_LINE* lines, int n_lines, OFF beg, OFF
return FALSE;
if(CH(off+1) != _T('!') || CH(off+2) != _T('-') || CH(off+3) != _T('-'))
return FALSE;
off += 4;

/* ">" and "->" must not follow the opening. */
if(off < lines[0].end && CH(off) == _T('>'))
return FALSE;
if(off+1 < lines[0].end && CH(off) == _T('-') && CH(off+1) == _T('>'))
return FALSE;

/* HTML comment must not contain "--", so we scan just for "--" instead
* of "-->" and verify manually that '>' follows. */
if(md_scan_for_html_closer(ctx, _T("--"), 2,
lines, n_lines, off, max_end, p_end, &ctx->html_comment_horizon))
{
if(*p_end < max_end && CH(*p_end) == _T('>')) {
*p_end = *p_end + 1;
return TRUE;
}
}
/* Skip only "<!" so that we accept also "<!-->" or "<!--->" */
off += 2;

return FALSE;
/* Scan for ordinary comment closer "-->". */
return md_scan_for_html_closer(ctx, _T("-->"), 3,
lines, n_lines, off, max_end, p_end, &ctx->html_comment_horizon);
}

static int
Expand Down

0 comments on commit aac6db0

Please sign in to comment.