-/* Generated by re2c 0.14.3 on Sat Feb 11 13:20:22 2017 */
+/* Generated by re2c 0.14.3 on Sun Feb 12 13:52:25 2017 */
/**
MultiMarkdown 6 -- Lightweight markup processor to produce HTML, LaTeX, and more.
}
-size_t scan_setext(const char * c) {
+size_t scan_title(const char * c) {
const char * marker = NULL;
const char * start = c;
yych = *c;
switch (yych) {
case '\n': goto yy733;
- case ' ': goto yy734;
- case '-': goto yy736;
- case '=': goto yy735;
+ case '"': goto yy734;
+ case '\'': goto yy735;
+ case '(': goto yy736;
default: goto yy737;
}
yy733:
yy734:
yych = *(marker = ++c);
switch (yych) {
- case ' ': goto yy749;
- case '-': goto yy750;
- case '=': goto yy751;
- default: goto yy733;
+ case 0x00:
+ case '\n':
+ case '\r': goto yy733;
+ default: goto yy746;
}
yy735:
yych = *(marker = ++c);
switch (yych) {
- case '=': goto yy744;
- default: goto yy733;
+ case 0x00:
+ case '\n':
+ case '\r': goto yy733;
+ default: goto yy744;
}
yy736:
yych = *(marker = ++c);
switch (yych) {
- case '-': goto yy738;
- default: goto yy733;
+ case 0x00:
+ case '\n':
+ case '\r': goto yy733;
+ default: goto yy739;
}
yy737:
yych = *++c;
yy738:
++c;
yych = *c;
+yy739:
switch (yych) {
case 0x00:
- case '\n': goto yy741;
- case '\r': goto yy743;
- case '-': goto yy738;
- default: goto yy740;
+ case '\n':
+ case '\r': goto yy740;
+ case ')': goto yy741;
+ default: goto yy738;
}
yy740:
c = marker;
goto yy733;
yy741:
++c;
-yy742:
{ return (size_t)( c - start ); }
yy743:
+ ++c;
+ yych = *c;
+yy744:
+ switch (yych) {
+ case 0x00:
+ case '\n':
+ case '\r': goto yy740;
+ case '\'': goto yy741;
+ default: goto yy743;
+ }
+yy745:
+ ++c;
+ yych = *c;
+yy746:
+ switch (yych) {
+ case 0x00:
+ case '\n':
+ case '\r': goto yy740;
+ case '"': goto yy741;
+ default: goto yy745;
+ }
+}
+
+}
+
+size_t scan_setext(const char * c) {
+ const char * marker = NULL;
+ const char * start = c;
+
+
+{
+ char yych;
+ yych = *c;
+ switch (yych) {
+ case '\n': goto yy749;
+ case ' ': goto yy750;
+ case '-': goto yy752;
+ case '=': goto yy751;
+ default: goto yy753;
+ }
+yy749:
+ { return 0; }
+yy750:
+ yych = *(marker = ++c);
+ switch (yych) {
+ case ' ': goto yy765;
+ case '-': goto yy766;
+ case '=': goto yy767;
+ default: goto yy749;
+ }
+yy751:
+ yych = *(marker = ++c);
+ switch (yych) {
+ case '=': goto yy760;
+ default: goto yy749;
+ }
+yy752:
+ yych = *(marker = ++c);
+ switch (yych) {
+ case '-': goto yy754;
+ default: goto yy749;
+ }
+yy753:
yych = *++c;
+ goto yy749;
+yy754:
+ ++c;
+ yych = *c;
switch (yych) {
- case '\n': goto yy741;
- default: goto yy742;
+ case 0x00:
+ case '\n': goto yy757;
+ case '\r': goto yy759;
+ case '-': goto yy754;
+ default: goto yy756;
}
-yy744:
+yy756:
+ c = marker;
+ goto yy749;
+yy757:
+ ++c;
+yy758:
+ { return (size_t)( c - start ); }
+yy759:
+ yych = *++c;
+ switch (yych) {
+ case '\n': goto yy757;
+ default: goto yy758;
+ }
+yy760:
++c;
yych = *c;
switch (yych) {
case 0x00:
- case '\n': goto yy746;
- case '\r': goto yy748;
- case '=': goto yy744;
- default: goto yy740;
+ case '\n': goto yy762;
+ case '\r': goto yy764;
+ case '=': goto yy760;
+ default: goto yy756;
}
-yy746:
+yy762:
++c;
-yy747:
+yy763:
{ return (size_t)( c - start ); }
-yy748:
+yy764:
yych = *++c;
switch (yych) {
- case '\n': goto yy746;
- default: goto yy747;
+ case '\n': goto yy762;
+ default: goto yy763;
}
-yy749:
+yy765:
yych = *++c;
switch (yych) {
- case ' ': goto yy752;
- case '-': goto yy750;
- case '=': goto yy751;
- default: goto yy740;
+ case ' ': goto yy768;
+ case '-': goto yy766;
+ case '=': goto yy767;
+ default: goto yy756;
}
-yy750:
+yy766:
yych = *++c;
switch (yych) {
- case '-': goto yy738;
- default: goto yy740;
+ case '-': goto yy754;
+ default: goto yy756;
}
-yy751:
+yy767:
yych = *++c;
switch (yych) {
- case '=': goto yy744;
- default: goto yy740;
+ case '=': goto yy760;
+ default: goto yy756;
}
-yy752:
+yy768:
++c;
switch ((yych = *c)) {
- case '-': goto yy750;
- case '=': goto yy751;
- default: goto yy740;
+ case '-': goto yy766;
+ case '=': goto yy767;
+ default: goto yy756;
}
}
}
-char * url_accept(const char * source, token ** remainder, bool validate) {
+char * url_accept(const char * source, size_t start, size_t max_len, size_t * end_pos, bool validate) {
char * url = NULL;
char * clean = NULL;
- token * t = NULL;
- token * first = NULL;
- token * last = NULL;
+ size_t scan_len;
- switch ((*remainder)->type) {
- case PAIR_PAREN:
- case PAIR_ANGLE:
- case PAIR_QUOTE_SINGLE:
- case PAIR_QUOTE_DOUBLE:
- t = token_chain_accept_multiple(remainder, 2, PAIR_ANGLE, PAIR_PAREN);
- url = text_inside_pair(source, t);
- break;
- case SLASH:
- case TEXT_PLAIN:
- first = *remainder;
-
- // Grab parts for URL
- while (token_chain_accept_multiple(remainder, 7, AMPERSAND, COLON, EQUAL, SLASH, TEXT_PERIOD, TEXT_PLAIN, UL));
+ scan_len = scan_destination(&source[start]);
- last = (*remainder)->prev;
+ if (scan_len) {
+ if (scan_len > max_len)
+ scan_len = max_len;
- // Is there a space in a URL concatenated with a title or attribute?
- // e.g. [foo]: http://foo.bar/ class="foo"
- // Since only one space between URL and class, they are joined.
+ if (end_pos)
+ *end_pos = start + scan_len;
- if (last->type == TEXT_PLAIN) {
- // Trim leading whitespace
- token_trim_leading_whitespace(last, source);
- token_split_on_char(last, source, ' ');
- *remainder = last->next;
- }
+ // Is this <foo>?
+ if ((source[start] == '<') &&
+ (source[start + scan_len - 1] == '>')) {
+ // Strip '<' and '>'
+ start++;
+ scan_len -= 2;
+ }
- url = strndup(&source[first->start], last->start + last->len - first->start);
- break;
- }
+ url = strndup(&source[start], scan_len);
- // Is this a valid URL?
- clean = clean_string(url, false);
-
- if (validate && !validate_url(clean)) {
- free(clean);
- clean = NULL;
+ clean = clean_string(url, false);
+
+ if (validate && !validate_url(clean)) {
+ free(clean);
+ clean = NULL;
+ }
+
+ free(url);
}
- free(url);
return clean;
}
/// Extract url string from `(foo)` or `(<foo>)` or `(foo "bar")`
void extract_from_paren(token * paren, const char * source, char ** url, char ** title, char ** attributes) {
- token * t;
+ size_t scan_len;
+ size_t pos = paren->child->next->start;
+
+
size_t attr_len;
- token * remainder = paren->child->next;
+ // Skip whitespace
+ while (char_is_whitespace(source[pos]))
+ pos++;
- if (remainder) {
- // Skip whitespace
- whitespace_accept(&remainder);
+ // Grab URL
+ *url = url_accept(source, pos, paren->start + paren->len - 1 - pos, &pos, false);
- // Grab URL
- *url = url_accept(source, &remainder, false);
+ // Skip whitespace
+ while (char_is_whitespace(source[pos]))
+ pos++;
- // Skip whitespace
- whitespace_accept(&remainder);
+ // Grab title, if present
+ scan_len = scan_title(&source[pos]);
- // Grab title, if present
- t = token_chain_accept_multiple(&remainder, 3, PAIR_QUOTE_DOUBLE, PAIR_QUOTE_SINGLE, PAIR_PAREN);
+ if (scan_len) {
+ *title = strndup(&source[pos + 1], scan_len - 2);
+ pos += scan_len;
+ }
- if (t) {
- *title = text_inside_pair(source, t);
- }
+ // Skip whitespace
+ while (char_is_whitespace(source[pos]))
+ pos++;
- // Grab attributes, if present
- if (t) {
- attr_len = scan_attributes(&source[t->start + t->len]);
-
- if (attr_len) {
- *attributes = strndup(&source[t->start + t->len], attr_len);
- }
- }
+ // Grab attributes, if present
+ attr_len = scan_attributes(&source[pos]);
+
+ if (attr_len) {
+ *attributes = strndup(&source[pos], attr_len);
}
}