]> granicus.if.org Git - multimarkdown/commitdiff
FIXED: Limit lines treated as ATX headers
authorFletcher T. Penney <fletcher@fletcherpenney.net>
Wed, 15 Mar 2017 00:10:55 +0000 (20:10 -0400)
committerFletcher T. Penney <fletcher@fletcherpenney.net>
Wed, 15 Mar 2017 00:10:55 +0000 (20:10 -0400)
Sources/libMultiMarkdown/mmd.c
Sources/libMultiMarkdown/scanners.c
Sources/libMultiMarkdown/scanners.h
Sources/libMultiMarkdown/scanners.re

index ee3026f47427ff76ffbb0e61fac01a1a5835b251..0046deb4ddb37af457d12840e835817b9988194d 100644 (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;
-
-                       // 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;
+                       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 '#' 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:
index e2ac3d1ce6b305199db2aefcb3a95d93e15de9af..fe334c8a6cfde00e34a72ad87ddcc80237dfdeee 100644 (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) {
index c0460854b62b82729b6ec2ed9d200f2d3b768091..cb6591c8b07939740efb28efd5b54679ef6bd223 100644 (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);
index 22f47b60dd5f356087ec7f4387a0cca985d404df..e891d56d139dbe4729fa8efde9fdb8d1cb0d71cd 100644 (file)
 
        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) {