Skip to content

Commit

Permalink
Add MKDEXT_LAX_SPACING extension
Browse files Browse the repository at this point in the history
  • Loading branch information
vmg committed Apr 12, 2012
1 parent 0e1cb2b commit 3826180
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
45 changes: 30 additions & 15 deletions src/markdown.c
Original file line number Diff line number Diff line change
Expand Up @@ -1426,18 +1426,38 @@ parse_paragraph(struct buf *ob, struct sd_markdown *rndr, uint8_t *data, size_t
if ((level = is_headerline(data + i, size - i)) != 0)
break;

if (rndr->ext_flags & MKDEXT_LAX_HTML_BLOCKS) {
if (data[i] == '<' && rndr->cb.blockhtml && parse_htmlblock(ob, rndr, data + i, size - i, 0)) {
/*
* Early termination of a paragraph with the same logic
* as Markdown 1.0.0. If this logic is applied, the
* Markdown 1.0.3 test suite won't pass cleanly
*
* :: If the first character in a new line is not a letter,
* let's check to see if there's some kind of block starting
* here
*/
if ((rndr->ext_flags & MKDEXT_LAX_SPACING) && !isalnum(data[i])) {
if (is_atxheader(rndr, data + i, size - i) ||
is_hrule(data + i, size - i) ||
prefix_quote(data + i, size - i) ||
prefix_oli(data + i, size - i) ||
prefix_uli(data + i, size - i)) {
end = i;
break;
}
}

if (is_atxheader(rndr, data + i, size - i) ||
is_hrule(data + i, size - i) ||
prefix_quote(data + i, size - i)) {
end = i;
break;
/* see if an html block starts here */
if (data[i] == '<' && rndr->cb.blockhtml &&
parse_htmlblock(ob, rndr, data + i, size - i, 0)) {
end = i;
break;
}

/* see if a code fence starts here */
if ((rndr->ext_flags & MKDEXT_FENCED_CODE) != 0 &&
is_codefence(data + i, size - i, NULL) != 0) {
end = i;
break;
}
}

i = end;
Expand Down Expand Up @@ -1802,13 +1822,8 @@ htmlblock_end_tag(
i += w;
w = 0;

if (rndr->ext_flags & MKDEXT_LAX_HTML_BLOCKS) {
if (i < size)
w = is_empty(data + i, size - i);
} else {
if (i < size && (w = is_empty(data + i, size - i)) == 0)
return 0; /* non-blank line after tag line */
}
if (i < size)
w = is_empty(data + i, size - i);

return i + w;
}
Expand Down
2 changes: 1 addition & 1 deletion src/markdown.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ enum mkd_extensions {
MKDEXT_FENCED_CODE = (1 << 2),
MKDEXT_AUTOLINK = (1 << 3),
MKDEXT_STRIKETHROUGH = (1 << 4),
MKDEXT_LAX_HTML_BLOCKS = (1 << 5),
MKDEXT_SPACE_HEADERS = (1 << 6),
MKDEXT_SUPERSCRIPT = (1 << 7),
MKDEXT_LAX_SPACING = (1 << 7),
};

/* sd_callbacks - functions for rendering parsed data */
Expand Down

0 comments on commit 3826180

Please sign in to comment.