Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
kivikakk committed Sep 16, 2018
2 parents 22d1149 + 42cd523 commit e4de28e
Show file tree
Hide file tree
Showing 9 changed files with 519 additions and 83 deletions.
50 changes: 27 additions & 23 deletions api_test/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,9 @@ static void render_xml(test_batch_runner *runner) {

static const char markdown[] = "foo *bar*\n"
"\n"
"paragraph 2\n";
"paragraph 2\n"
"\n"
"```\ncode\n```\n";
cmark_node *doc =
cmark_parse_document(markdown, sizeof(markdown) - 1, CMARK_OPT_DEFAULT);

Expand All @@ -536,14 +538,16 @@ static void render_xml(test_batch_runner *runner) {
"<!DOCTYPE document SYSTEM \"CommonMark.dtd\">\n"
"<document xmlns=\"http://commonmark.org/xml/1.0\">\n"
" <paragraph>\n"
" <text>foo </text>\n"
" <text xml:space=\"preserve\">foo </text>\n"
" <emph>\n"
" <text>bar</text>\n"
" <text xml:space=\"preserve\">bar</text>\n"
" </emph>\n"
" </paragraph>\n"
" <paragraph>\n"
" <text>paragraph 2</text>\n"
" <text xml:space=\"preserve\">paragraph 2</text>\n"
" </paragraph>\n"
" <code_block xml:space=\"preserve\">code\n"
"</code_block>\n"
"</document>\n",
"render document");
free(xml);
Expand All @@ -552,9 +556,9 @@ static void render_xml(test_batch_runner *runner) {
STR_EQ(runner, xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<!DOCTYPE document SYSTEM \"CommonMark.dtd\">\n"
"<paragraph sourcepos=\"1:1-1:9\">\n"
" <text sourcepos=\"1:1-1:4\">foo </text>\n"
" <text sourcepos=\"1:1-1:4\" xml:space=\"preserve\">foo </text>\n"
" <emph sourcepos=\"1:5-1:9\">\n"
" <text sourcepos=\"1:6-1:8\">bar</text>\n"
" <text sourcepos=\"1:6-1:8\" xml:space=\"preserve\">bar</text>\n"
" </emph>\n"
"</paragraph>\n",
"render first paragraph with source pos");
Expand Down Expand Up @@ -1008,41 +1012,41 @@ static void source_pos(test_batch_runner *runner) {
"<!DOCTYPE document SYSTEM \"CommonMark.dtd\">\n"
"<document sourcepos=\"1:1-10:20\" xmlns=\"http://commonmark.org/xml/1.0\">\n"
" <heading sourcepos=\"1:1-1:13\" level=\"1\">\n"
" <text sourcepos=\"1:3-1:5\">Hi </text>\n"
" <text sourcepos=\"1:3-1:5\" xml:space=\"preserve\">Hi </text>\n"
" <emph sourcepos=\"1:6-1:12\">\n"
" <text sourcepos=\"1:7-1:11\">there</text>\n"
" <text sourcepos=\"1:7-1:11\" xml:space=\"preserve\">there</text>\n"
" </emph>\n"
" <text sourcepos=\"1:13-1:13\">.</text>\n"
" <text sourcepos=\"1:13-1:13\" xml:space=\"preserve\">.</text>\n"
" </heading>\n"
" <paragraph sourcepos=\"3:1-4:42\">\n"
" <text sourcepos=\"3:1-3:14\">Hello \xe2\x80\x9c </text>\n"
" <text sourcepos=\"3:1-3:14\" xml:space=\"preserve\">Hello \xe2\x80\x9c </text>\n"
" <link sourcepos=\"3:15-3:37\" destination=\"http://www.google.com\" title=\"\">\n"
" <text sourcepos=\"3:16-3:36\">http://www.google.com</text>\n"
" <text sourcepos=\"3:16-3:36\" xml:space=\"preserve\">http://www.google.com</text>\n"
" </link>\n"
" <softbreak />\n"
" <text sourcepos=\"4:1-4:6\">there </text>\n"
" <code sourcepos=\"4:8-4:9\">hi</code>\n"
" <text sourcepos=\"4:11-4:14\"> -- </text>\n"
" <text sourcepos=\"4:1-4:6\" xml:space=\"preserve\">there </text>\n"
" <code sourcepos=\"4:8-4:9\" xml:space=\"preserve\">hi</code>\n"
" <text sourcepos=\"4:11-4:14\" xml:space=\"preserve\"> -- </text>\n"
" <link sourcepos=\"4:15-4:41\" destination=\"www.google.com\" title=\"ok\">\n"
" <text sourcepos=\"4:16-4:19\">okay</text>\n"
" <text sourcepos=\"4:16-4:19\" xml:space=\"preserve\">okay</text>\n"
" </link>\n"
" <text sourcepos=\"4:42-4:42\">.</text>\n"
" <text sourcepos=\"4:42-4:42\" xml:space=\"preserve\">.</text>\n"
" </paragraph>\n"
" <block_quote sourcepos=\"6:1-10:20\">\n"
" <list sourcepos=\"6:3-10:20\" type=\"ordered\" start=\"1\" delim=\"period\" tight=\"false\">\n"
" <item sourcepos=\"6:3-8:1\">\n"
" <paragraph sourcepos=\"6:6-7:10\">\n"
" <text sourcepos=\"6:6-6:10\">Okay.</text>\n"
" <text sourcepos=\"6:6-6:10\" xml:space=\"preserve\">Okay.</text>\n"
" <softbreak />\n"
" <text sourcepos=\"7:6-7:10\">Sure.</text>\n"
" <text sourcepos=\"7:6-7:10\" xml:space=\"preserve\">Sure.</text>\n"
" </paragraph>\n"
" </item>\n"
" <item sourcepos=\"9:3-10:20\">\n"
" <paragraph sourcepos=\"9:6-10:20\">\n"
" <text sourcepos=\"9:6-9:15\">Yes, okay.</text>\n"
" <text sourcepos=\"9:6-9:15\" xml:space=\"preserve\">Yes, okay.</text>\n"
" <softbreak />\n"
" <image sourcepos=\"10:6-10:20\" destination=\"hi\" title=\"yes\">\n"
" <text sourcepos=\"10:8-10:9\">ok</text>\n"
" <text sourcepos=\"10:8-10:9\" xml:space=\"preserve\">ok</text>\n"
" </image>\n"
" </paragraph>\n"
" </item>\n"
Expand All @@ -1066,11 +1070,11 @@ static void ref_source_pos(test_batch_runner *runner) {
"<!DOCTYPE document SYSTEM \"CommonMark.dtd\">\n"
"<document sourcepos=\"1:1-3:40\" xmlns=\"http://commonmark.org/xml/1.0\">\n"
" <paragraph sourcepos=\"1:1-1:28\">\n"
" <text sourcepos=\"1:1-1:10\">Let's try </text>\n"
" <text sourcepos=\"1:1-1:10\" xml:space=\"preserve\">Let's try </text>\n"
" <link sourcepos=\"1:11-1:21\" destination=\"https://github.com\" title=\"GitHub\">\n"
" <text sourcepos=\"1:12-1:20\">reference</text>\n"
" <text sourcepos=\"1:12-1:20\" xml:space=\"preserve\">reference</text>\n"
" </link>\n"
" <text sourcepos=\"1:22-1:28\"> links.</text>\n"
" <text sourcepos=\"1:22-1:28\" xml:space=\"preserve\"> links.</text>\n"
" </paragraph>\n"
"</document>\n",
"sourcepos are as expected");
Expand Down
2 changes: 1 addition & 1 deletion man/man3/cmark-gfm.3
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH cmark-gfm 3 "August 21, 2018" "LOCAL" "Library Functions Manual"
.TH cmark-gfm 3 "September 17, 2018" "LOCAL" "Library Functions Manual"
.SH
NAME
.PP
Expand Down
6 changes: 4 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,13 @@ if (MSVC)
APPEND PROPERTY LINK_FLAGS /INCREMENTAL:NO)
endif(MSVC)

set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS ON)
if(NOT MSVC OR CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS ON)
include(InstallRequiredSystemLibraries)
endif()

set(libdir lib${LIB_SUFFIX})

include (InstallRequiredSystemLibraries)
install(TARGETS ${PROGRAM} ${CMARK_INSTALL}
EXPORT cmark-gfm
RUNTIME DESTINATION bin
Expand Down
8 changes: 6 additions & 2 deletions src/commonmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ 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;
Expand Down Expand Up @@ -369,14 +370,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
37 changes: 34 additions & 3 deletions src/inlines.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,37 @@ static bufsize_t scan_to_closing_backticks(subject *subj,
return 0;
}

// Destructively modify string, converting newlines to
// spaces, then removing a single leading + trailing space.
static void S_normalize_code(cmark_strbuf *s) {
bufsize_t r, w;

for (r = 0, w = 0; r < s->size; ++r) {
switch (s->ptr[r]) {
case '\r':
if (s->ptr[r + 1] != '\n') {
s->ptr[w++] = ' ';
}
break;
case '\n':
s->ptr[w++] = ' ';
break;
default:
s->ptr[w++] = s->ptr[r];
}
}

// begins and ends with space?
if (s->ptr[0] == ' ' && s->ptr[w - 1] == ' ') {
cmark_strbuf_drop(s, 1);
cmark_strbuf_truncate(s, w - 2);
} else {
cmark_strbuf_truncate(s, w);
}

}


// Parse backtick code section or raw backticks, return an inline.
// Assumes that the subject has a backtick at the current position.
static cmark_node *handle_backticks(subject *subj, int options) {
Expand All @@ -336,15 +367,15 @@ static cmark_node *handle_backticks(subject *subj, int options) {

cmark_strbuf_set(&buf, subj->input.data + startpos,
endpos - startpos - openticks.len);
cmark_strbuf_trim(&buf);
cmark_strbuf_normalize_whitespace(&buf);
S_normalize_code(&buf);

cmark_node *node = make_code(subj, startpos, endpos - openticks.len - 1, cmark_chunk_buf_detach(&buf));
adjust_subj_node_newlines(subj, node, endpos - startpos, openticks.len, options);
return node;
}
}


// Scan ***, **, or * and return number scanned, or 0.
// Advances position.
static int scan_delims(subject *subj, unsigned char c, bool *can_open,
Expand Down Expand Up @@ -1410,7 +1441,7 @@ bufsize_t cmark_parse_reference_inline(cmark_mem *mem, cmark_chunk *input,
// parse optional link_title
beforetitle = subj.pos;
spnl(&subj);
matchlen = scan_link_title(&subj.input, subj.pos);
matchlen = subj.pos == beforetitle ? 0 : scan_link_title(&subj.input, subj.pos);
if (matchlen) {
title = cmark_chunk_dup(&subj.input, subj.pos, matchlen);
subj.pos += matchlen;
Expand Down
4 changes: 2 additions & 2 deletions src/xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static int S_render_node(cmark_node *node, cmark_event_type ev_type,
case CMARK_NODE_CODE:
case CMARK_NODE_HTML_BLOCK:
case CMARK_NODE_HTML_INLINE:
cmark_strbuf_puts(xml, ">");
cmark_strbuf_puts(xml, " xml:space=\"preserve\">");
escape_xml(xml, node->as.literal.data, node->as.literal.len);
cmark_strbuf_puts(xml, "</");
cmark_strbuf_puts(xml, cmark_node_get_type_string(node));
Expand Down Expand Up @@ -100,7 +100,7 @@ static int S_render_node(cmark_node *node, cmark_event_type ev_type,
escape_xml(xml, node->as.code.info.data, node->as.code.info.len);
cmark_strbuf_putc(xml, '"');
}
cmark_strbuf_puts(xml, ">");
cmark_strbuf_puts(xml, " xml:space=\"preserve\">");
escape_xml(xml, node->as.code.literal.data, node->as.code.literal.len);
cmark_strbuf_puts(xml, "</");
cmark_strbuf_puts(xml, cmark_node_get_type_string(node));
Expand Down
29 changes: 29 additions & 0 deletions test/regression.txt
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,32 @@ A footnote in a paragraph[^1]
</ol>
</section>
````````````````````````````````

Issue #527 - meta tags in inline contexts

```````````````````````````````` example
City:
<span itemprop="contentLocation" itemscope itemtype="https://schema.org/City">
<meta itemprop="name" content="Springfield">
</span>
.
<p>City:
<span itemprop="contentLocation" itemscope itemtype="https://schema.org/City">
<meta itemprop="name" content="Springfield">
</span></p>
````````````````````````````````

Issue #530 - link parsing corner cases

```````````````````````````````` example
[a](\ b)

[a](<<b)

[a](<b
)
.
<p>[a](\ b)</p>
<p><a href="%3C%3Cb">a</a></p>
<p><a href="%3Cb">a</a></p>
````````````````````````````````
Expand Down
Loading

0 comments on commit e4de28e

Please sign in to comment.