Skip to content

Commit 7c71bd1

Browse files
committed
Merge branch 'upstream-master'
2 parents 3785191 + 78267ab commit 7c71bd1

File tree

10 files changed

+119
-22
lines changed

10 files changed

+119
-22
lines changed

api_test/main.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,53 @@ static void source_pos(test_batch_runner *runner) {
10581058
cmark_node_free(doc);
10591059
}
10601060

1061+
static void source_pos_inlines(test_batch_runner *runner) {
1062+
{
1063+
static const char markdown[] =
1064+
"*first*\n"
1065+
"second\n";
1066+
1067+
cmark_node *doc = cmark_parse_document(markdown, sizeof(markdown) - 1, CMARK_OPT_DEFAULT);
1068+
char *xml = cmark_render_xml(doc, CMARK_OPT_DEFAULT | CMARK_OPT_SOURCEPOS);
1069+
STR_EQ(runner, xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
1070+
"<!DOCTYPE document SYSTEM \"CommonMark.dtd\">\n"
1071+
"<document sourcepos=\"1:1-2:6\" xmlns=\"http://commonmark.org/xml/1.0\">\n"
1072+
" <paragraph sourcepos=\"1:1-2:6\">\n"
1073+
" <emph sourcepos=\"1:1-1:7\">\n"
1074+
" <text sourcepos=\"1:2-1:6\" xml:space=\"preserve\">first</text>\n"
1075+
" </emph>\n"
1076+
" <softbreak />\n"
1077+
" <text sourcepos=\"2:1-2:6\" xml:space=\"preserve\">second</text>\n"
1078+
" </paragraph>\n"
1079+
"</document>\n",
1080+
"sourcepos are as expected");
1081+
free(xml);
1082+
cmark_node_free(doc);
1083+
}
1084+
{
1085+
static const char markdown[] =
1086+
"*first\n"
1087+
"second*\n";
1088+
1089+
cmark_node *doc = cmark_parse_document(markdown, sizeof(markdown) - 1, CMARK_OPT_DEFAULT);
1090+
char *xml = cmark_render_xml(doc, CMARK_OPT_DEFAULT | CMARK_OPT_SOURCEPOS);
1091+
STR_EQ(runner, xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
1092+
"<!DOCTYPE document SYSTEM \"CommonMark.dtd\">\n"
1093+
"<document sourcepos=\"1:1-2:7\" xmlns=\"http://commonmark.org/xml/1.0\">\n"
1094+
" <paragraph sourcepos=\"1:1-2:7\">\n"
1095+
" <emph sourcepos=\"1:1-2:7\">\n"
1096+
" <text sourcepos=\"1:2-1:6\" xml:space=\"preserve\">first</text>\n"
1097+
" <softbreak />\n"
1098+
" <text sourcepos=\"2:1-2:6\" xml:space=\"preserve\">second</text>\n"
1099+
" </emph>\n"
1100+
" </paragraph>\n"
1101+
"</document>\n",
1102+
"sourcepos are as expected");
1103+
free(xml);
1104+
cmark_node_free(doc);
1105+
}
1106+
}
1107+
10611108
static void ref_source_pos(test_batch_runner *runner) {
10621109
static const char markdown[] =
10631110
"Let's try [reference] links.\n"
@@ -1110,6 +1157,7 @@ int main() {
11101157
test_feed_across_line_ending(runner);
11111158
test_pathological_regressions(runner);
11121159
source_pos(runner);
1160+
source_pos_inlines(runner);
11131161
ref_source_pos(runner);
11141162

11151163
test_print_summary(runner);

src/commonmark.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ static int S_render_node(cmark_renderer *renderer, cmark_node *node,
172172
int i;
173173
bool entering = (ev_type == CMARK_EVENT_ENTER);
174174
const char *info, *code, *title;
175+
char fencechar[2] = {'\0', '\0'};
175176
size_t info_len, code_len;
176177
char listmarker[LISTMARKER_SIZE];
177178
char *emph_delim;
@@ -284,6 +285,7 @@ static int S_render_node(cmark_renderer *renderer, cmark_node *node,
284285
}
285286
info = cmark_node_get_fence_info(node);
286287
info_len = strlen(info);
288+
fencechar[0] = strchr(info, '`') == NULL ? '`' : '~';
287289
code = cmark_node_get_literal(node);
288290
code_len = strlen(code);
289291
// use indented form if no info, and code doesn't
@@ -303,15 +305,15 @@ static int S_render_node(cmark_renderer *renderer, cmark_node *node,
303305
numticks = 3;
304306
}
305307
for (i = 0; i < numticks; i++) {
306-
LIT("`");
308+
LIT(fencechar);
307309
}
308310
LIT(" ");
309311
OUT(info, false, LITERAL);
310312
CR();
311313
OUT(cmark_node_get_literal(node), false, LITERAL);
312314
CR();
313315
for (i = 0; i < numticks; i++) {
314-
LIT("`");
316+
LIT(fencechar);
315317
}
316318
}
317319
BLANKLINE();

src/houdini_href_e.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* - The characters which are *not* safe to be in
1616
* an URL because they are RESERVED characters.
1717
*
18-
* We asume (lazily) that any RESERVED char that
18+
* We assume (lazily) that any RESERVED char that
1919
* appears inside an URL is actually meant to
2020
* have its native function (i.e. as an URL
2121
* component/separator) and hence needs no escaping.

src/inlines.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -760,9 +760,10 @@ static delimiter *S_insert_emph(subject *subj, delimiter *opener,
760760
}
761761
cmark_node_insert_after(opener_inl, emph);
762762

763-
emph->start_line = emph->end_line = subj->line;
764-
emph->start_column = opener_inl->start_column + subj->column_offset;
765-
emph->end_column = closer_inl->end_column + subj->column_offset;
763+
emph->start_line = opener_inl->start_line;
764+
emph->end_line = closer_inl->end_line;
765+
emph->start_column = opener_inl->start_column;
766+
emph->end_column = closer_inl->end_column;
766767

767768
// if opener has 0 characters, remove it and its associated inline
768769
if (opener_num_chars == 0) {

src/main.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@
2121
# endif
2222
#endif
2323

24+
#if defined(__OpenBSD__)
25+
# include <sys/param.h>
26+
# if OpenBSD >= 201605
27+
# define USE_PLEDGE
28+
# include <unistd.h>
29+
# endif
30+
#endif
31+
2432
#if defined(_WIN32) && !defined(__CYGWIN__)
2533
#include <io.h>
2634
#include <fcntl.h>
@@ -134,6 +142,13 @@ int main(int argc, char *argv[]) {
134142

135143
cmark_gfm_core_extensions_ensure_registered();
136144

145+
#ifdef USE_PLEDGE
146+
if (pledge("stdio rpath", NULL) != 0) {
147+
perror("pledge");
148+
return 1;
149+
}
150+
#endif
151+
137152
#if defined(_WIN32) && !defined(__CYGWIN__)
138153
_setmode(_fileno(stdin), _O_BINARY);
139154
_setmode(_fileno(stdout), _O_BINARY);

src/render.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ static void S_out(cmark_renderer *renderer, cmark_node *node,
5757
}
5858
}
5959
renderer->column = 0;
60+
renderer->last_breakable = 0;
6061
renderer->begin_line = true;
6162
renderer->begin_content = true;
6263
renderer->need_cr -= 1;

src/scanners.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Generated by re2c 1.0.3 */
1+
/* Generated by re2c 1.1.1 */
22
#include <stdlib.h>
33
#include "chunk.h"
44
#include "scanners.h"
@@ -9226,7 +9226,7 @@ bufsize_t _scan_open_code_fence(const unsigned char *p)
92269226
144, 192, 192, 192, 192, 192, 192, 192,
92279227
192, 192, 192, 192, 192, 192, 192, 192,
92289228
192, 192, 192, 192, 192, 192, 192, 192,
9229-
192, 192, 192, 192, 192, 192, 96, 192,
9229+
192, 192, 192, 192, 192, 192, 224, 192,
92309230
0, 0, 0, 0, 0, 0, 0, 0,
92319231
0, 0, 0, 0, 0, 0, 0, 0,
92329232
0, 0, 0, 0, 0, 0, 0, 0,

src/scanners.re

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ bufsize_t _scan_open_code_fence(const unsigned char *p)
286286
const unsigned char *start = p;
287287
/*!re2c
288288
[`]{3,} / [^`\r\n\x00]*[\r\n] { return (bufsize_t)(p - start); }
289-
[~]{3,} / [^~\r\n\x00]*[\r\n] { return (bufsize_t)(p - start); }
289+
[~]{3,} / [^\r\n\x00]*[\r\n] { return (bufsize_t)(p - start); }
290290
* { return 0; }
291291
*/
292292
}

test/spec.txt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,8 +1600,8 @@ begins with a code fence, indented no more than three spaces.
16001600

16011601
The line with the opening code fence may optionally contain some text
16021602
following the code fence; this is trimmed of leading and trailing
1603-
whitespace and called the [info string](@).
1604-
The [info string] may not contain any backtick
1603+
whitespace and called the [info string](@). If the [info string] comes
1604+
after a backtick fence, it may not contain any backtick
16051605
characters. (The reason for this restriction is that otherwise
16061606
some inline code would be incorrectly interpreted as the
16071607
beginning of a fenced code block.)
@@ -1989,6 +1989,18 @@ foo</p>
19891989
````````````````````````````````
19901990

19911991

1992+
[Info strings] for tilde code blocks can contain backticks and tildes:
1993+
1994+
```````````````````````````````` example
1995+
~~~ aa ``` ~~~
1996+
foo
1997+
~~~
1998+
.
1999+
<pre><code class="language-aa">foo
2000+
</code></pre>
2001+
````````````````````````````````
2002+
2003+
19922004
Closing code fences cannot have [info strings]:
19932005

19942006
```````````````````````````````` example

wrappers/wrapper.rkt

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,34 @@
1313
(define-ffi-definer defcmark (ffi-lib "libcmark"))
1414

1515
(define _cmark_node_type
16-
(_enum '(none
16+
(_enum '(;; Error status
17+
none
1718
;; Block
1819
document block-quote list item code-block
19-
html paragraph header hrule
20+
html-block custom-block
21+
paragraph heading thematic-break
22+
;; ?? first-block = document
23+
;; ?? last-block = thematic-break
2024
;; Inline
21-
text softbreak linebreak code inline-html
22-
emph strong link image)))
25+
text softbreak linebreak code html-inline custom-inline
26+
emph strong link image
27+
;; ?? first-inline = text
28+
;; ?? last-inline = image
29+
)))
2330
(define _cmark_list_type
2431
(_enum '(no_list bullet_list ordered_list)))
2532
(define _cmark_delim_type
2633
(_enum '(no_delim period_delim paren_delim)))
2734
(define _cmark_opts
28-
(_bitmask '(sourcepos = 1 hardbreaks = 2 normalize = 4 smart = 8)))
35+
(_bitmask
36+
'(sourcepos = 2 ; include sourcepos attribute on block elements
37+
hardbreaks = 4 ; render `softbreak` elements as hard line breaks
38+
safe = 8 ; suppress raw HTML and unsafe links
39+
nobreaks = 16 ; render `softbreak` elements as spaces
40+
normalize = 256 ; legacy (no effect)
41+
validate-utf8 = 512 ; validate UTF-8 in the input
42+
smart = 1024 ; straight quotes to curly, ---/-- to em/en dashes
43+
)))
2944

3045
(define-cpointer-type _node)
3146

@@ -56,8 +71,8 @@
5671
(defcmark cmark_node_get_type_string (_fun _node -> _bytes))
5772
(defcmark cmark_node_get_literal (_fun _node -> _string))
5873
(defcmark cmark_node_set_literal (_fun _node _string -> _bool))
59-
(defcmark cmark_node_get_header_level (_fun _node -> _int))
60-
(defcmark cmark_node_set_header_level (_fun _node _int -> _bool))
74+
(defcmark cmark_node_get_heading_level (_fun _node -> _int))
75+
(defcmark cmark_node_set_heading_level (_fun _node _int -> _bool))
6176
(defcmark cmark_node_get_list_type (_fun _node -> _cmark_list_type))
6277
(defcmark cmark_node_set_list_type (_fun _node _cmark_list_type -> _bool))
6378
(defcmark cmark_node_get_list_delim (_fun _node -> _cmark_delim_type))
@@ -84,6 +99,9 @@
8499
(defcmark cmark_node_append_child (_fun _node _node -> _bool))
85100
(defcmark cmark_consolidate_text_nodes (_fun _node -> _void))
86101

102+
(defcmark cmark_version (_fun -> _int))
103+
(defcmark cmark_version_string (_fun -> _string))
104+
87105
)
88106

89107
;; Rackety interface
@@ -108,7 +126,7 @@
108126
(define-syntax-rule (define-getters+setters name [type field ...] ...)
109127
(define name (list (list 'type (make-getter+setter field) ...) ...)))
110128
(define-getters+setters getters+setters
111-
[header header_level] [code-block fence_info]
129+
[heading heading_level] [code-block fence_info]
112130
[link url title] [image url title]
113131
[list list_type list_delim list_start list_tight])
114132

@@ -126,12 +144,12 @@
126144
[else '()]))
127145
(define (assert-no what-not b)
128146
(when b (error 'cmark->sexpr "unexpected ~a in ~s" what-not type)))
129-
(cond [(memq type '(document paragraph header block-quote list item
147+
(cond [(memq type '(document paragraph heading block-quote list item
130148
emph strong link image))
131149
(assert-no 'text text)
132150
(list type info children)]
133-
[(memq type '(text code code-block html inline-html
134-
softbreak linebreak hrule))
151+
[(memq type '(text code code-block html-block html-inline
152+
softbreak linebreak thematic-break))
135153
(assert-no 'children (pair? children))
136154
(list type info text)]
137155
[else (error 'cmark->sexpr "unknown type: ~s" type)]))

0 commit comments

Comments
 (0)