FIXED: Limit lines treated as ATX headers

This commit is contained in:
Fletcher T. Penney 2017-03-14 20:10:55 -04:00
parent 439e322d5a
commit 955624d449
4 changed files with 86 additions and 14 deletions

View File

@ -402,22 +402,26 @@ void mmd_assign_line_type(mmd_engine * e, token * line) {
case HASH4:
case HASH5:
case HASH6:
line->type = (line->child->type - HASH1) + LINE_ATX_1;
line->child->type = (line->type - LINE_ATX_1) + MARKER_H1;
if (scan_atx(&source[line->child->start])) {
line->type = (line->child->type - HASH1) + LINE_ATX_1;
line->child->type = (line->type - LINE_ATX_1) + MARKER_H1;
// Strip trailing whitespace from '#' sequence
line->child->len = line->child->type - MARKER_H1 + 1;
// Strip trailing whitespace from '#' sequence
line->child->len = line->child->type - MARKER_H1 + 1;
// Strip trailing '#' sequence if present
if (line->child->tail->type == TEXT_NL) {
if ((line->child->tail->prev->type >= HASH1) &&
(line->child->tail->prev->type <= HASH6))
line->child->tail->prev->type = TEXT_EMPTY;
// Strip trailing '#' sequence if present
if (line->child->tail->type == TEXT_NL) {
if ((line->child->tail->prev->type >= HASH1) &&
(line->child->tail->prev->type <= HASH6))
line->child->tail->prev->type = TEXT_EMPTY;
} else {
token_describe(line->child->tail, NULL);
if ((line->child->tail->type >= HASH1) &&
(line->child->tail->type <= HASH6))
line->child->tail->type = TEXT_EMPTY;
}
} else {
token_describe(line->child->tail, NULL);
if ((line->child->tail->type >= HASH1) &&
(line->child->tail->type <= HASH6))
line->child->tail->type = TEXT_EMPTY;
line->type = LINE_PLAIN;
}
break;
case TEXT_NUMBER_POSS_LIST:

View File

@ -1,4 +1,4 @@
/* Generated by re2c 0.14.3 on Tue Mar 14 12:15:24 2017 */
/* Generated by re2c 0.14.3 on Tue Mar 14 20:07:08 2017 */
/**
MultiMarkdown 6 -- Lightweight markup processor to produce HTML, LaTeX, and more.
@ -9940,6 +9940,62 @@ yy824:
}
size_t scan_atx(const char * c) {
const char * marker = NULL;
const char * start = c;
{
char yych;
yych = *c;
switch (yych) {
case '\n': goto yy827;
case '#': goto yy828;
default: goto yy829;
}
yy827:
{ return 0; }
yy828:
yych = *(marker = ++c);
switch (yych) {
case '\t':
case ' ': goto yy830;
case '#': goto yy833;
default: goto yy827;
}
yy829:
yych = *++c;
goto yy827;
yy830:
++c;
yych = *c;
switch (yych) {
case 0x00:
case '\n':
case '\r': goto yy832;
case '\t':
case ' ': goto yy830;
default: goto yy835;
}
yy832:
c = marker;
goto yy827;
yy833:
++c;
yych = *c;
switch (yych) {
case '\t':
case ' ': goto yy830;
case '#': goto yy833;
default: goto yy832;
}
yy835:
++c;
{ return (size_t)( c - start ); }
}
}
#ifdef TEST
void Test_scan_url(CuTest* tc) {

View File

@ -72,6 +72,7 @@ enum alignments {
size_t scan_alignment_string(const char * c);
size_t scan_attr(const char * c);
size_t scan_attributes(const char * c);
size_t scan_atx(const char * c);
size_t scan_definition(const char * c);
size_t scan_destination(const char * c);
size_t scan_email(const char * c);

View File

@ -158,6 +158,7 @@
setext_2 = non_indent '-'{2,} nl_eof;
atx = '#'+ [ \t]+ [^ \t\n\r\x00];
*/
@ -460,6 +461,16 @@ size_t scan_setext(const char * c) {
*/
}
size_t scan_atx(const char * c) {
const char * marker = NULL;
const char * start = c;
/*!re2c
atx { return (size_t)( c - start ); }
.? { return 0; }
*/
}
#ifdef TEST
void Test_scan_url(CuTest* tc) {