Skip to content

Commit

Permalink
Updates to most recent cmark-gfm changes, including addition of task …
Browse files Browse the repository at this point in the history
…list.
  • Loading branch information
KristopherGBaker committed Feb 6, 2019
1 parent 66015c4 commit f35a401
Show file tree
Hide file tree
Showing 58 changed files with 12,289 additions and 19,162 deletions.
4 changes: 2 additions & 2 deletions Sources/libcmark_gfm/arena.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "cmark.h"
#include "cmark_extension_api.h"
#include "cmark-gfm.h"
#include "cmark-gfm-extension_api.h"

static struct arena_chunk {
size_t sz, used;
Expand Down
18 changes: 11 additions & 7 deletions Sources/libcmark_gfm/autolink.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "autolink.h"
#include "parser.h"
#include <parser.h>
#include <string.h>
#include <utf8.h>

Expand Down Expand Up @@ -269,7 +269,11 @@ static cmark_node *match(cmark_syntax_extension *ext, cmark_parser *parser,
// inline was finished in inlines.c.
}

static void postprocess_text(cmark_parser *parser, cmark_node *text, int offset) {
static void postprocess_text(cmark_parser *parser, cmark_node *text, int offset, int depth) {
// postprocess_text can recurse very deeply if there is a very long line of
// '@' only. Stop at a reasonable depth to ensure it cannot crash.
if (depth > 1000) return;

size_t link_end;
uint8_t *data = text->as.literal.data,
*at;
Expand Down Expand Up @@ -307,7 +311,7 @@ static void postprocess_text(cmark_parser *parser, cmark_node *text, int offset)
}

if (rewind == 0 || ns > 0) {
postprocess_text(parser, text, max_rewind + 1 + offset);
postprocess_text(parser, text, max_rewind + 1 + offset, depth + 1);
return;
}

Expand All @@ -327,14 +331,14 @@ static void postprocess_text(cmark_parser *parser, cmark_node *text, int offset)

if (link_end < 2 || nb != 1 || np == 0 ||
(!cmark_isalpha(data[link_end - 1]) && data[link_end - 1] != '.')) {
postprocess_text(parser, text, max_rewind + 1 + offset);
postprocess_text(parser, text, max_rewind + 1 + offset, depth + 1);
return;
}

link_end = autolink_delim(data, link_end);

if (link_end == 0) {
postprocess_text(parser, text, max_rewind + 1 + offset);
postprocess_text(parser, text, max_rewind + 1 + offset, depth + 1);
return;
}

Expand Down Expand Up @@ -369,7 +373,7 @@ static void postprocess_text(cmark_parser *parser, cmark_node *text, int offset)
text->as.literal.len = offset + max_rewind - rewind;
text->as.literal.data[text->as.literal.len] = 0;

postprocess_text(parser, post, 0);
postprocess_text(parser, post, 0, depth + 1);
}

static cmark_node *postprocess(cmark_syntax_extension *ext, cmark_parser *parser, cmark_node *root) {
Expand All @@ -396,7 +400,7 @@ static cmark_node *postprocess(cmark_syntax_extension *ext, cmark_parser *parser
}

if (ev == CMARK_EVENT_ENTER && node->type == CMARK_NODE_TEXT) {
postprocess_text(parser, node, 0);
postprocess_text(parser, node, 0, /*depth*/0);
}
}

Expand Down
36 changes: 21 additions & 15 deletions Sources/libcmark_gfm/blocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "syntax_extension.h"
#include "config.h"
#include "parser.h"
#include "cmark.h"
#include "cmark-gfm.h"
#include "node.h"
#include "references.h"
#include "utf8.h"
Expand Down Expand Up @@ -755,22 +755,24 @@ static void S_find_first_nonspace(cmark_parser *parser, cmark_chunk *input) {
char c;
int chars_to_tab = TAB_STOP - (parser->column % TAB_STOP);

parser->first_nonspace = parser->offset;
parser->first_nonspace_column = parser->column;
while ((c = peek_at(input, parser->first_nonspace))) {
if (c == ' ') {
parser->first_nonspace += 1;
parser->first_nonspace_column += 1;
chars_to_tab = chars_to_tab - 1;
if (chars_to_tab == 0) {
if (parser->first_nonspace <= parser->offset) {
parser->first_nonspace = parser->offset;
parser->first_nonspace_column = parser->column;
while ((c = peek_at(input, parser->first_nonspace))) {
if (c == ' ') {
parser->first_nonspace += 1;
parser->first_nonspace_column += 1;
chars_to_tab = chars_to_tab - 1;
if (chars_to_tab == 0) {
chars_to_tab = TAB_STOP;
}
} else if (c == '\t') {
parser->first_nonspace += 1;
parser->first_nonspace_column += chars_to_tab;
chars_to_tab = TAB_STOP;
} else {
break;
}
} else if (c == '\t') {
parser->first_nonspace += 1;
parser->first_nonspace_column += chars_to_tab;
chars_to_tab = TAB_STOP;
} else {
break;
}
}

Expand Down Expand Up @@ -1137,6 +1139,7 @@ static void open_new_blocks(cmark_parser *parser, cmark_node **container,

(*container)->internal_offset = matched;
} else if ((!indented || cont_type == CMARK_NODE_LIST) &&
parser->indent < 4 &&
(matched = parse_list_marker(
parser->mem, input, parser->first_nonspace,
(*container)->type == CMARK_NODE_PARAGRAPH, &data))) {
Expand Down Expand Up @@ -1372,6 +1375,9 @@ static void S_process_line(cmark_parser *parser, const unsigned char *buffer,

parser->offset = 0;
parser->column = 0;
parser->first_nonspace = 0;
parser->first_nonspace_column = 0;
parser->indent = 0;
parser->blank = false;
parser->partially_consumed_tab = false;

Expand Down
6 changes: 3 additions & 3 deletions Sources/libcmark_gfm/cmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
#include "registry.h"
#include "node.h"
#include "houdini.h"
#include "cmark.h"
#include "cmark-gfm.h"
#include "buffer.h"

cmark_node_type CMARK_NODE_LAST_BLOCK = CMARK_NODE_FOOTNOTE_DEFINITION;
cmark_node_type CMARK_NODE_LAST_INLINE = CMARK_NODE_FOOTNOTE_REFERENCE;

int cmark_version() { return CMARK_VERSION; }
int cmark_version() { return CMARK_GFM_VERSION; }

const char *cmark_version_string() { return CMARK_VERSION_STRING; }
const char *cmark_version_string() { return CMARK_GFM_VERSION_STRING; }

static void *xcalloc(size_t nmem, size_t size) {
void *ptr = calloc(nmem, size);
Expand Down
18 changes: 12 additions & 6 deletions Sources/libcmark_gfm/commonmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <assert.h>

#include "config.h"
#include "cmark.h"
#include "cmark-gfm.h"
#include "node.h"
#include "buffer.h"
#include "utf8.h"
Expand Down Expand Up @@ -35,7 +35,7 @@ static CMARK_INLINE void outc(cmark_renderer *renderer, cmark_node *node,
c < 0x80 && escape != LITERAL &&
((escape == NORMAL &&
(c == '*' || c == '_' || c == '[' || c == ']' || c == '#' || c == '<' ||
c == '>' || c == '\\' || c == '`' || c == '!' ||
c == '>' || c == '\\' || c == '`' || c == '~' || c == '!' ||
(c == '&' && cmark_isalpha(nextc)) || (c == '!' && nextc == '[') ||
(renderer->begin_content && (c == '-' || c == '+' || c == '=') &&
// begin_content doesn't get set to false til we've passed digits
Expand Down Expand Up @@ -168,9 +168,11 @@ static int S_render_node(cmark_renderer *renderer, cmark_node *node,
int list_number;
cmark_delim_type list_delim;
int numticks;
bool extra_spaces;
int i;
bool entering = (ev_type == CMARK_EVENT_ENTER);
const char *info, *code, *title;
char fencechar[2] = {'\0', '\0'};
size_t info_len, code_len;
char listmarker[LISTMARKER_SIZE];
char *emph_delim;
Expand Down Expand Up @@ -283,6 +285,7 @@ static int S_render_node(cmark_renderer *renderer, cmark_node *node,
}
info = cmark_node_get_fence_info(node);
info_len = strlen(info);
fencechar[0] = strchr(info, '`') == NULL ? '`' : '~';
code = cmark_node_get_literal(node);
code_len = strlen(code);
// use indented form if no info, and code doesn't
Expand All @@ -302,15 +305,15 @@ static int S_render_node(cmark_renderer *renderer, cmark_node *node,
numticks = 3;
}
for (i = 0; i < numticks; i++) {
LIT("`");
LIT(fencechar);
}
LIT(" ");
OUT(info, false, LITERAL);
CR();
OUT(cmark_node_get_literal(node), false, LITERAL);
CR();
for (i = 0; i < numticks; i++) {
LIT("`");
LIT(fencechar);
}
}
BLANKLINE();
Expand Down Expand Up @@ -369,14 +372,17 @@ static int S_render_node(cmark_renderer *renderer, cmark_node *node,
code = cmark_node_get_literal(node);
code_len = strlen(code);
numticks = shortest_unused_backtick_sequence(code);
extra_spaces = code_len == 0 ||
code[0] == '`' || code[code_len - 1] == '`' ||
code[0] == ' ' || code[code_len - 1] == ' ';
for (i = 0; i < numticks; i++) {
LIT("`");
}
if (code_len == 0 || code[0] == '`') {
if (extra_spaces) {
LIT(" ");
}
OUT(cmark_node_get_literal(node), allow_wrap, LITERAL);
if (code_len == 0 || code[code_len - 1] == '`') {
if (extra_spaces) {
LIT(" ");
}
for (i = 0; i < numticks; i++) {
Expand Down
6 changes: 4 additions & 2 deletions Sources/libcmark_gfm/core-extensions.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include "core-extensions.h"
#include "cmark-gfm-core-extensions.h"
#include "autolink.h"
#include "strikethrough.h"
#include "table.h"
#include "tagfilter.h"
#include "tasklist.h"
#include "registry.h"
#include "plugin.h"

Expand All @@ -12,10 +13,11 @@ static int core_extensions_registration(cmark_plugin *plugin) {
create_strikethrough_extension());
cmark_plugin_register_syntax_extension(plugin, create_autolink_extension());
cmark_plugin_register_syntax_extension(plugin, create_tagfilter_extension());
cmark_plugin_register_syntax_extension(plugin, create_tasklist_extension());
return 1;
}

void core_extensions_ensure_registered(void) {
void cmark_gfm_core_extensions_ensure_registered(void) {
static int registered = 0;

if (!registered) {
Expand Down
Loading

0 comments on commit f35a401

Please sign in to comment.