diff options
-rw-r--r-- | src/blocks.c | 12 | ||||
-rw-r--r-- | src/html/html.c | 1 | ||||
-rw-r--r-- | src/scanners.h | 53 | ||||
-rw-r--r-- | src/scanners.re | 38 |
4 files changed, 63 insertions, 41 deletions
diff --git a/src/blocks.c b/src/blocks.c index bd25d6c..cf0e9e4 100644 --- a/src/blocks.c +++ b/src/blocks.c @@ -752,11 +752,15 @@ static void incorporate_line(gh_buf *line, int line_number, block** curptr) add_line(container, &input, offset); } else if (container->tag == fenced_code) { + matched = 0; + + if (indent <= 3 && + peek_at(&input, first_nonspace) == container->attributes.fenced_code_data.fence_char) { + int fence_len = scan_close_code_fence(&input, first_nonspace); + if (fence_len > container->attributes.fenced_code_data.fence_length) + matched = 1; + } - matched = (indent <= 3 - && peek_at(&input, first_nonspace) == container->attributes.fenced_code_data.fence_char) - && scan_close_code_fence(&input, first_nonspace, - container->attributes.fenced_code_data.fence_length); if (matched) { // if closing fence, don't add line to container; instead, close it: finalize(container, line_number); diff --git a/src/html/html.c b/src/html/html.c index 3bd5df0..2a65a63 100644 --- a/src/html/html.c +++ b/src/html/html.c @@ -6,7 +6,6 @@ #include "stmd.h" #include "debug.h" -#include "scanners.h" #include "html/houdini.h" // Functions to convert block and inline lists to HTML strings. diff --git a/src/scanners.h b/src/scanners.h index f96c42d..785d424 100644 --- a/src/scanners.h +++ b/src/scanners.h @@ -1,15 +1,42 @@ #include "stmd.h" -int scan_autolink_uri(chunk *c, int offset); -int scan_autolink_email(chunk *c, int offset); -int scan_html_tag(chunk *c, int offset); -int scan_html_block_tag(chunk *c, int offset); -int scan_link_url(chunk *c, int offset); -int scan_link_title(chunk *c, int offset); -int scan_spacechars(chunk *c, int offset); -int scan_atx_header_start(chunk *c, int offset); -int scan_setext_header_line(chunk *c, int offset); -int scan_hrule(chunk *c, int offset); -int scan_open_code_fence(chunk *c, int offset); -int scan_close_code_fence(chunk *c, int offset, int len); -int scan_entity(chunk *c, int offset); +extern int _scan_autolink_uri(const unsigned char *p); +extern int _scan_autolink_email(const unsigned char *p); +extern int _scan_html_tag(const unsigned char *p); +extern int _scan_html_block_tag(const unsigned char *p); +extern int _scan_link_url(const unsigned char *p); +extern int _scan_link_title(const unsigned char *p); +extern int _scan_spacechars(const unsigned char *p); +extern int _scan_atx_header_start(const unsigned char *p); +extern int _scan_setext_header_line(const unsigned char *p); +extern int _scan_hrule(const unsigned char *p); +extern int _scan_open_code_fence(const unsigned char *p); +extern int _scan_close_code_fence(const unsigned char *p); +extern int _scan_entity(const unsigned char *p); + +static int scan_at(int (*scanner)(const unsigned char *), chunk *c, int offset) +{ + int res; + unsigned char *ptr = (unsigned char *)c->data; + unsigned char lim = ptr[c->len]; + + ptr[c->len] = '\0'; + res = scanner(ptr + offset); + ptr[c->len] = lim; + + return res; +} + +#define scan_autolink_uri(c, n) scan_at(&_scan_autolink_uri, c, n) +#define scan_autolink_email(c, n) scan_at(&_scan_autolink_email, c, n) +#define scan_html_tag(c, n) scan_at(&_scan_html_tag, c, n) +#define scan_html_block_tag(c, n) scan_at(&_scan_html_block_tag, c, n) +#define scan_link_url(c, n) scan_at(&_scan_link_url, c, n) +#define scan_link_title(c, n) scan_at(&_scan_link_title, c, n) +#define scan_spacechars(c, n) scan_at(&_scan_spacechars, c, n) +#define scan_atx_header_start(c, n) scan_at(&_scan_atx_header_start, c, n) +#define scan_setext_header_line(c, n) scan_at(&_scan_setext_header_line, c, n) +#define scan_hrule(c, n) scan_at(&_scan_hrule, c, n) +#define scan_open_code_fence(c, n) scan_at(&_scan_open_code_fence, c, n) +#define scan_close_code_fence(c, n) scan_at(&_scan_close_code_fence, c, n) +#define scan_entity(c, n) scan_at(&_scan_entity, c, n) diff --git a/src/scanners.re b/src/scanners.re index 5ac7c15..71103f6 100644 --- a/src/scanners.re +++ b/src/scanners.re @@ -1,15 +1,12 @@ -#include "scanners.h" +#include <stdlib.h> #define SCAN_DATA \ const unsigned char *marker = NULL; \ - const unsigned char *p = c->data + offset; \ const unsigned char *start = p; \ - const unsigned char *end = c->data + c->len /*!re2c re2c:define:YYCTYPE = "unsigned char"; re2c:define:YYCURSOR = p; - re2c:define:YYLIMIT = end; re2c:define:YYMARKER = marker; re2c:define:YYCTXMARKER = marker; re2c:yyfill:enable = 0; @@ -62,7 +59,7 @@ */ // Try to match URI autolink after first <, returning number of chars matched. -extern int scan_autolink_uri(chunk *c, int offset) +extern int _scan_autolink_uri(const unsigned char *p) { SCAN_DATA; /*!re2c @@ -72,7 +69,7 @@ extern int scan_autolink_uri(chunk *c, int offset) } // Try to match email autolink after first <, returning num of chars matched. -extern int scan_autolink_email(chunk *c, int offset) +extern int _scan_autolink_email(const unsigned char *p) { SCAN_DATA; /*!re2c @@ -86,7 +83,7 @@ extern int scan_autolink_email(chunk *c, int offset) } // Try to match an HTML tag after first <, returning num of chars matched. -extern int scan_html_tag(chunk *c, int offset) +extern int _scan_html_tag(const unsigned char *p) { SCAN_DATA; /*!re2c @@ -97,7 +94,7 @@ extern int scan_html_tag(chunk *c, int offset) // Try to match an HTML block tag including first <, // returning num of chars matched. -extern int scan_html_block_tag(chunk *c, int offset) +extern int _scan_html_block_tag(const unsigned char *p) { SCAN_DATA; /*!re2c @@ -112,7 +109,7 @@ extern int scan_html_block_tag(chunk *c, int offset) // This may optionally be contained in <..>; otherwise // whitespace and unbalanced right parentheses aren't allowed. // Newlines aren't ever allowed. -extern int scan_link_url(chunk *c, int offset) +extern int _scan_link_url(const unsigned char *p) { SCAN_DATA; /*!re2c @@ -125,7 +122,7 @@ extern int scan_link_url(chunk *c, int offset) // Try to match a link title (in single quotes, in double quotes, or // in parentheses), returning number of chars matched. Allow one // level of internal nesting (quotes within quotes). -extern int scan_link_title(chunk *c, int offset) +extern int _scan_link_title(const unsigned char *p) { SCAN_DATA; /*!re2c @@ -137,7 +134,7 @@ extern int scan_link_title(chunk *c, int offset) } // Match space characters, including newlines. -extern int scan_spacechars(chunk *c, int offset) +extern int _scan_spacechars(const unsigned char *p) { SCAN_DATA; /*!re2c @@ -147,7 +144,7 @@ extern int scan_spacechars(chunk *c, int offset) } // Match ATX header start. -extern int scan_atx_header_start(chunk *c, int offset) +extern int _scan_atx_header_start(const unsigned char *p) { SCAN_DATA; /*!re2c @@ -158,7 +155,7 @@ extern int scan_atx_header_start(chunk *c, int offset) // Match sexext header line. Return 1 for level-1 header, // 2 for level-2, 0 for no match. -extern int scan_setext_header_line(chunk *c, int offset) +extern int _scan_setext_header_line(const unsigned char *p) { SCAN_DATA; /*!re2c @@ -171,7 +168,7 @@ extern int scan_setext_header_line(chunk *c, int offset) // Scan a horizontal rule line: "...three or more hyphens, asterisks, // or underscores on a line by themselves. If you wish, you may use // spaces between the hyphens or asterisks." -extern int scan_hrule(chunk *c, int offset) +extern int _scan_hrule(const unsigned char *p) { SCAN_DATA; /*!re2c @@ -183,7 +180,7 @@ extern int scan_hrule(chunk *c, int offset) } // Scan an opening code fence. -extern int scan_open_code_fence(chunk *c, int offset) +extern int _scan_open_code_fence(const unsigned char *p) { SCAN_DATA; /*!re2c @@ -194,23 +191,18 @@ extern int scan_open_code_fence(chunk *c, int offset) } // Scan a closing code fence with length at least len. -extern int scan_close_code_fence(chunk *c, int offset, int len) +extern int _scan_close_code_fence(const unsigned char *p) { SCAN_DATA; /*!re2c - ([`]{3,} | [~]{3,}) / spacechar* [\n] - { if (p - start > len) { - return (p - start); - } else { - return 0; - } } + ([`]{3,} | [~]{3,}) / spacechar* [\n] { return (p - start); } .? { return 0; } */ } // Scans an entity. // Returns number of chars matched. -extern int scan_entity(chunk *c, int offset) +extern int _scan_entity(const unsigned char *p) { SCAN_DATA; /*!re2c |