commonmarker 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of commonmarker might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +23 -17
- data/ext/commonmarker/cmark/CMakeLists.txt +1 -1
- data/ext/commonmarker/cmark/Makefile +13 -14
- data/ext/commonmarker/cmark/README.md +1 -0
- data/ext/commonmarker/cmark/api_test/cplusplus.h +1 -2
- data/ext/commonmarker/cmark/api_test/harness.c +60 -79
- data/ext/commonmarker/cmark/api_test/harness.h +13 -20
- data/ext/commonmarker/cmark/api_test/main.c +809 -714
- data/ext/commonmarker/cmark/build/CMakeCache.txt +3 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/Makefile.cmake +0 -67
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/build.make +1 -1
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/link.txt +1 -1
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/DependInfo.cmake +1 -1
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/build.make +23 -23
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/cmake_clean.cmake +1 -1
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/link.txt +1 -1
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/blocks.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/cmark.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/cmark_ctype.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/commonmark.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/html.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/inlines.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/iterator.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/latex.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/man.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/node.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/render.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/scanners.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/xml.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/cmake_install.cmake +10 -2
- data/ext/commonmarker/cmark/build/src/cmark_version.h +2 -2
- data/ext/commonmarker/cmark/build/src/libcmark.a +0 -0
- data/ext/commonmarker/cmark/build/src/libcmark.pc +1 -1
- data/ext/commonmarker/cmark/build/testdir/CTestTestfile.cmake +1 -0
- data/ext/commonmarker/cmark/changelog.txt +85 -0
- data/ext/commonmarker/cmark/man/man3/cmark.3 +75 -34
- data/ext/commonmarker/cmark/src/CMakeLists.txt +13 -8
- data/ext/commonmarker/cmark/src/blocks.c +78 -70
- data/ext/commonmarker/cmark/src/chunk.h +5 -7
- data/ext/commonmarker/cmark/src/cmark.h +88 -34
- data/ext/commonmarker/cmark/src/cmark_ctype.c +6 -6
- data/ext/commonmarker/cmark/src/commonmark.c +24 -8
- data/ext/commonmarker/cmark/src/houdini_html_u.c +6 -5
- data/ext/commonmarker/cmark/src/html.c +33 -11
- data/ext/commonmarker/cmark/src/inlines.c +9 -10
- data/ext/commonmarker/cmark/src/iterator.c +2 -2
- data/ext/commonmarker/cmark/src/latex.c +54 -28
- data/ext/commonmarker/cmark/src/main.c +0 -9
- data/ext/commonmarker/cmark/src/man.c +17 -5
- data/ext/commonmarker/cmark/src/node.c +123 -44
- data/ext/commonmarker/cmark/src/node.h +8 -2
- data/ext/commonmarker/cmark/src/render.c +8 -1
- data/ext/commonmarker/cmark/src/render.h +1 -0
- data/ext/commonmarker/cmark/src/scanners.c +3755 -4379
- data/ext/commonmarker/cmark/src/scanners.h +7 -6
- data/ext/commonmarker/cmark/src/scanners.re +9 -10
- data/ext/commonmarker/cmark/src/utf8.c +6 -3
- data/ext/commonmarker/cmark/src/utf8.h +4 -2
- data/ext/commonmarker/cmark/src/xml.c +18 -4
- data/ext/commonmarker/cmark/test/CMakeLists.txt +11 -0
- data/ext/commonmarker/cmark/test/normalize.py +5 -1
- data/ext/commonmarker/cmark/test/roundtrip.bat +1 -0
- data/ext/commonmarker/cmark/test/roundtrip.sh +1 -1
- data/ext/commonmarker/cmark/test/spec.txt +257 -157
- data/ext/commonmarker/cmark/why-cmark-and-not-x.md +104 -0
- data/lib/commonmarker/config.rb +6 -6
- data/lib/commonmarker/version.rb +1 -1
- metadata +5 -5
- data/ext/commonmarker/cmark/src/bench.h +0 -27
- data/ext/commonmarker/cmark/wrappers/wrapper.lua +0 -239
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4cd2c7505b978c3efdfbca42870636900cf44b9
|
4
|
+
data.tar.gz: dd98c9922735c153e403f8d974f3b0a594120153
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1cd2eb95385b3fa129e20afc7a731ca12f3f7b1f68ff7bab9c1490e4565ca4fe4dc4556583014fe860c54ef9a44c1db7819cfcffaba97a2096ed021bd8393363
|
7
|
+
data.tar.gz: 0d923225fb9696618dfa5805360c9b711824de30ff3bc76b69e0fda061f7c729920a833c81bf8222eb6b22b8a9dff6323161d64153fb036ea4df7d3be632d84a
|
data/README.md
CHANGED
@@ -117,32 +117,39 @@ end
|
|
117
117
|
|
118
118
|
## Options
|
119
119
|
|
120
|
-
CommonMarker accepts the same options that CMark does, as symbols. Note that there is a distinction in CMark for "parse" options and "render" options, which are represented in the
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
|
125
|
-
|
126
|
-
| `:
|
127
|
-
| `:normalize` | Attempt to normalize the HTML.
|
128
|
-
| `:smart` | Use smart punctuation (curly quotes, etc.).
|
129
|
-
| `:validate_utf8` | Replace illegal sequences with the replacement character `U+FFFD`.
|
130
|
-
|
120
|
+
CommonMarker accepts the same options that CMark does, as symbols. Note that there is a distinction in CMark for "parse" options and "render" options, which are represented in the tables below.
|
121
|
+
|
122
|
+
### Parse options
|
123
|
+
|
124
|
+
| Name | Description |
|
125
|
+
|-------|--------------|
|
126
|
+
| `:default` | The default parsing system.
|
127
|
+
| `:normalize` | Attempt to normalize the HTML.
|
128
|
+
| `:smart` | Use smart punctuation (curly quotes, etc.).
|
129
|
+
| `:validate_utf8` | Replace illegal sequences with the replacement character `U+FFFD`.
|
130
|
+
|
131
|
+
### Render options
|
132
|
+
|
133
|
+
| Name | Description |
|
134
|
+
|-------|--------------|
|
135
|
+
| `:default` | The default rendering system.
|
136
|
+
| `:sourcepos` | Include source position in rendered HTML.
|
137
|
+
| `:hardbreaks` | Treat `\n` as hardbreaks (by adding `<br/>`).
|
138
|
+
| `:safe` | Suppress raw HTML and unsafe links.
|
139
|
+
|
140
|
+
### Passing options
|
131
141
|
|
132
142
|
To apply a single option, pass it in as a symbol argument:
|
133
143
|
|
134
144
|
``` ruby
|
135
|
-
|
136
|
-
CommonMarker.render_html("\"Hello,\" said the spider.", :smart)
|
145
|
+
CommonMarker.render_doc("\"Hello,\" said the spider.", :smart)
|
137
146
|
# <p>“Hello,” said the spider.</p>\n
|
138
147
|
```
|
139
148
|
|
140
149
|
To have multiple options applied, pass in an array of symbols:
|
141
150
|
|
142
151
|
``` ruby
|
143
|
-
|
144
|
-
CommonMarker.render_html("\"Hello,\" said the spider.\n\"'Shelob' is my name.\"", [:hardbreaks, :smart])
|
145
|
-
# <p>“Hello,” said the spider.</br>“‘Shelob’ is my name.”</p>
|
152
|
+
CommonMarker.render_html("\"'Shelob' is my name.\"", [:hardbreaks, :sourcepos])
|
146
153
|
```
|
147
154
|
|
148
155
|
For more information on these options, see [the CMark documentation](http://git.io/vlQii).
|
@@ -177,5 +184,4 @@ commonmarker with ruby HtmlRenderer
|
|
177
184
|
1.830000 0.030000 1.860000 ( 1.866203)
|
178
185
|
kramdown
|
179
186
|
4.610000 0.070000 4.680000 ( 4.678398)
|
180
|
-
|
181
187
|
```
|
@@ -9,7 +9,7 @@ endif()
|
|
9
9
|
set(PROJECT_NAME "cmark")
|
10
10
|
|
11
11
|
set(PROJECT_VERSION_MAJOR 0)
|
12
|
-
set(PROJECT_VERSION_MINOR
|
12
|
+
set(PROJECT_VERSION_MINOR 23)
|
13
13
|
set(PROJECT_VERSION_PATCH 0)
|
14
14
|
set(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH} )
|
15
15
|
|
@@ -14,13 +14,12 @@ ALLTESTS=alltests.md
|
|
14
14
|
NUMRUNS?=10
|
15
15
|
CMARK=$(BUILDDIR)/src/cmark
|
16
16
|
PROG?=$(CMARK)
|
17
|
-
BENCHINP?=README.md
|
18
17
|
VERSION?=$(SPECVERSION)
|
19
18
|
RELEASE?=CommonMark-$(VERSION)
|
20
19
|
INSTALL_PREFIX?=/usr/local
|
21
20
|
CLANG_CHECK?=clang-check
|
22
21
|
|
23
|
-
.PHONY: all cmake_build
|
22
|
+
.PHONY: all cmake_build leakcheck clean fuzztest test debug ubsan asan mingw archive bench format update-spec afl clang-check
|
24
23
|
|
25
24
|
all: cmake_build man/man3/cmark.3
|
26
25
|
|
@@ -129,9 +128,6 @@ update-spec:
|
|
129
128
|
test: $(SPEC) cmake_build
|
130
129
|
make -C $(BUILDDIR) test || (cat $(BUILDDIR)/Testing/Temporary/LastTest.log && exit 1)
|
131
130
|
|
132
|
-
roundtrip_test: $(SPEC) cmake_build
|
133
|
-
python3 test/spec_tests.py --spec $< --prog test/roundtrip.sh
|
134
|
-
|
135
131
|
$(ALLTESTS): $(SPEC)
|
136
132
|
python3 test/spec_tests.py --spec $< --dump-tests | python3 -c 'import json; import sys; tests = json.loads(sys.stdin.read()); print("\n".join([test["markdown"] for test in tests]))' > $@
|
137
133
|
|
@@ -154,25 +150,28 @@ fuzztest:
|
|
154
150
|
progit:
|
155
151
|
git clone https://github.com/progit/progit.git
|
156
152
|
|
157
|
-
$(
|
153
|
+
$(BENCHFILE): progit
|
158
154
|
echo "" > $@
|
159
155
|
for lang in ar az be ca cs de en eo es es-ni fa fi fr hi hu id it ja ko mk nl no-nb pl pt-br ro ru sr th tr uk vi zh zh-tw; do \
|
160
|
-
|
156
|
+
for i in `seq 1 10`; do \
|
157
|
+
cat progit/$$lang/*/*.markdown >> $@; \
|
158
|
+
done; \
|
161
159
|
done
|
162
160
|
|
161
|
+
# for more accurate results, run with
|
162
|
+
# sudo renice -10 $$; make bench
|
163
163
|
bench: $(BENCHFILE)
|
164
|
-
{
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
done \
|
164
|
+
{ for x in `seq 1 $(NUMRUNS)` ; do \
|
165
|
+
/usr/bin/env time -p $(PROG) </dev/null >/dev/null ; \
|
166
|
+
/usr/bin/env time -p $(PROG) $< >/dev/null ; \
|
167
|
+
done \
|
169
168
|
} 2>&1 | grep 'real' | awk '{print $$2}' | python3 'bench/stats.py'
|
170
169
|
|
171
170
|
format:
|
172
|
-
clang-format -style llvm -i src/*.c src/*.h
|
171
|
+
clang-format -style llvm -i src/*.c src/*.h api_test/*.c api_test/*.h
|
173
172
|
|
174
173
|
operf: $(CMARK)
|
175
|
-
operf $< < $(
|
174
|
+
operf $< < $(BENCHFILE) > /dev/null
|
176
175
|
|
177
176
|
distclean: clean
|
178
177
|
-rm -rf *.dSYM
|
@@ -56,6 +56,7 @@ There are also libraries that wrap `libcmark` for
|
|
56
56
|
[go](https://github.com/rhinoman/go-commonmark),
|
57
57
|
[Haskell](http://hackage.haskell.org/package/cmark),
|
58
58
|
[ruby](https://github.com/gjtorikian/commonmarker),
|
59
|
+
[lua](https://github.com/jgm/cmark-lua),
|
59
60
|
[Perl](https://metacpan.org/release/CommonMark), and
|
60
61
|
[R](http://cran.r-project.org/package=commonmark).
|
61
62
|
|
@@ -5,98 +5,79 @@
|
|
5
5
|
|
6
6
|
#include "harness.h"
|
7
7
|
|
8
|
-
test_batch_runner*
|
9
|
-
|
10
|
-
{
|
11
|
-
return (test_batch_runner *)calloc(1, sizeof(test_batch_runner));
|
8
|
+
test_batch_runner *test_batch_runner_new() {
|
9
|
+
return (test_batch_runner *)calloc(1, sizeof(test_batch_runner));
|
12
10
|
}
|
13
11
|
|
14
|
-
static void
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
++runner->num_failed;
|
27
|
-
}
|
12
|
+
static void test_result(test_batch_runner *runner, int cond, const char *msg,
|
13
|
+
va_list ap) {
|
14
|
+
++runner->test_num;
|
15
|
+
|
16
|
+
if (cond) {
|
17
|
+
++runner->num_passed;
|
18
|
+
} else {
|
19
|
+
fprintf(stderr, "FAILED test %d: ", runner->test_num);
|
20
|
+
vfprintf(stderr, msg, ap);
|
21
|
+
fprintf(stderr, "\n");
|
22
|
+
++runner->num_failed;
|
23
|
+
}
|
28
24
|
}
|
29
25
|
|
30
|
-
void
|
31
|
-
|
32
|
-
|
33
|
-
runner->test_num += num_tests;
|
34
|
-
runner->num_skipped += num_tests;
|
26
|
+
void SKIP(test_batch_runner *runner, int num_tests) {
|
27
|
+
runner->test_num += num_tests;
|
28
|
+
runner->num_skipped += num_tests;
|
35
29
|
}
|
36
30
|
|
37
|
-
void
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
test_result(runner, cond, msg, ap);
|
43
|
-
va_end(ap);
|
31
|
+
void OK(test_batch_runner *runner, int cond, const char *msg, ...) {
|
32
|
+
va_list ap;
|
33
|
+
va_start(ap, msg);
|
34
|
+
test_result(runner, cond, msg, ap);
|
35
|
+
va_end(ap);
|
44
36
|
}
|
45
37
|
|
46
|
-
void
|
47
|
-
|
48
|
-
|
49
|
-
int cond = got == expected;
|
38
|
+
void INT_EQ(test_batch_runner *runner, int got, int expected, const char *msg,
|
39
|
+
...) {
|
40
|
+
int cond = got == expected;
|
50
41
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
42
|
+
va_list ap;
|
43
|
+
va_start(ap, msg);
|
44
|
+
test_result(runner, cond, msg, ap);
|
45
|
+
va_end(ap);
|
55
46
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
47
|
+
if (!cond) {
|
48
|
+
fprintf(stderr, " Got: %d\n", got);
|
49
|
+
fprintf(stderr, " Expected: %d\n", expected);
|
50
|
+
}
|
60
51
|
}
|
61
52
|
|
62
|
-
void
|
63
|
-
|
64
|
-
|
65
|
-
{
|
66
|
-
int cond = strcmp(got, expected) == 0;
|
67
|
-
|
68
|
-
va_list ap;
|
69
|
-
va_start(ap, msg);
|
70
|
-
test_result(runner, cond, msg, ap);
|
71
|
-
va_end(ap);
|
72
|
-
|
73
|
-
if (!cond) {
|
74
|
-
fprintf(stderr, " Got: \"%s\"\n", got);
|
75
|
-
fprintf(stderr, " Expected: \"%s\"\n", expected);
|
76
|
-
}
|
77
|
-
}
|
53
|
+
void STR_EQ(test_batch_runner *runner, const char *got, const char *expected,
|
54
|
+
const char *msg, ...) {
|
55
|
+
int cond = strcmp(got, expected) == 0;
|
78
56
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
}
|
57
|
+
va_list ap;
|
58
|
+
va_start(ap, msg);
|
59
|
+
test_result(runner, cond, msg, ap);
|
60
|
+
va_end(ap);
|
84
61
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
int num_skipped = runner->num_skipped;
|
90
|
-
int num_failed = runner->num_failed;
|
91
|
-
|
92
|
-
fprintf(stderr, "%d tests passed, %d failed, %d skipped\n",
|
93
|
-
num_passed, num_failed, num_skipped);
|
94
|
-
|
95
|
-
if (test_ok(runner)) {
|
96
|
-
fprintf(stderr, "PASS\n");
|
97
|
-
}
|
98
|
-
else {
|
99
|
-
fprintf(stderr, "FAIL\n");
|
100
|
-
}
|
62
|
+
if (!cond) {
|
63
|
+
fprintf(stderr, " Got: \"%s\"\n", got);
|
64
|
+
fprintf(stderr, " Expected: \"%s\"\n", expected);
|
65
|
+
}
|
101
66
|
}
|
102
67
|
|
68
|
+
int test_ok(test_batch_runner *runner) { return runner->num_failed == 0; }
|
69
|
+
|
70
|
+
void test_print_summary(test_batch_runner *runner) {
|
71
|
+
int num_passed = runner->num_passed;
|
72
|
+
int num_skipped = runner->num_skipped;
|
73
|
+
int num_failed = runner->num_failed;
|
74
|
+
|
75
|
+
fprintf(stderr, "%d tests passed, %d failed, %d skipped\n", num_passed,
|
76
|
+
num_failed, num_skipped);
|
77
|
+
|
78
|
+
if (test_ok(runner)) {
|
79
|
+
fprintf(stderr, "PASS\n");
|
80
|
+
} else {
|
81
|
+
fprintf(stderr, "FAIL\n");
|
82
|
+
}
|
83
|
+
}
|
@@ -6,37 +6,30 @@ extern "C" {
|
|
6
6
|
#endif
|
7
7
|
|
8
8
|
typedef struct {
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
int test_num;
|
10
|
+
int num_passed;
|
11
|
+
int num_failed;
|
12
|
+
int num_skipped;
|
13
13
|
} test_batch_runner;
|
14
14
|
|
15
|
-
test_batch_runner*
|
16
|
-
test_batch_runner_new();
|
15
|
+
test_batch_runner *test_batch_runner_new();
|
17
16
|
|
18
|
-
void
|
19
|
-
SKIP(test_batch_runner *runner, int num_tests);
|
17
|
+
void SKIP(test_batch_runner *runner, int num_tests);
|
20
18
|
|
21
|
-
void
|
22
|
-
OK(test_batch_runner *runner, int cond, const char *msg, ...);
|
19
|
+
void OK(test_batch_runner *runner, int cond, const char *msg, ...);
|
23
20
|
|
24
|
-
void
|
25
|
-
|
21
|
+
void INT_EQ(test_batch_runner *runner, int got, int expected, const char *msg,
|
22
|
+
...);
|
26
23
|
|
27
|
-
void
|
28
|
-
|
29
|
-
const char *msg, ...);
|
24
|
+
void STR_EQ(test_batch_runner *runner, const char *got, const char *expected,
|
25
|
+
const char *msg, ...);
|
30
26
|
|
31
|
-
int
|
32
|
-
test_ok(test_batch_runner *runner);
|
27
|
+
int test_ok(test_batch_runner *runner);
|
33
28
|
|
34
|
-
void
|
35
|
-
test_print_summary(test_batch_runner *runner);
|
29
|
+
void test_print_summary(test_batch_runner *runner);
|
36
30
|
|
37
31
|
#ifdef __cplusplus
|
38
32
|
}
|
39
33
|
#endif
|
40
34
|
|
41
35
|
#endif
|
42
|
-
|
@@ -12,771 +12,866 @@
|
|
12
12
|
#define UTF8_REPL "\xEF\xBF\xBD"
|
13
13
|
|
14
14
|
static const cmark_node_type node_types[] = {
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
CMARK_NODE_PARAGRAPH,
|
22
|
-
CMARK_NODE_HEADER,
|
23
|
-
CMARK_NODE_HRULE,
|
24
|
-
CMARK_NODE_TEXT,
|
25
|
-
CMARK_NODE_SOFTBREAK,
|
26
|
-
CMARK_NODE_LINEBREAK,
|
27
|
-
CMARK_NODE_CODE,
|
28
|
-
CMARK_NODE_INLINE_HTML,
|
29
|
-
CMARK_NODE_EMPH,
|
30
|
-
CMARK_NODE_STRONG,
|
31
|
-
CMARK_NODE_LINK,
|
32
|
-
CMARK_NODE_IMAGE
|
33
|
-
};
|
15
|
+
CMARK_NODE_DOCUMENT, CMARK_NODE_BLOCK_QUOTE, CMARK_NODE_LIST,
|
16
|
+
CMARK_NODE_ITEM, CMARK_NODE_CODE_BLOCK, CMARK_NODE_HTML_BLOCK,
|
17
|
+
CMARK_NODE_PARAGRAPH, CMARK_NODE_HEADING, CMARK_NODE_THEMATIC_BREAK,
|
18
|
+
CMARK_NODE_TEXT, CMARK_NODE_SOFTBREAK, CMARK_NODE_LINEBREAK,
|
19
|
+
CMARK_NODE_CODE, CMARK_NODE_HTML_INLINE, CMARK_NODE_EMPH,
|
20
|
+
CMARK_NODE_STRONG, CMARK_NODE_LINK, CMARK_NODE_IMAGE};
|
34
21
|
static const int num_node_types = sizeof(node_types) / sizeof(*node_types);
|
35
22
|
|
36
|
-
static void
|
37
|
-
|
38
|
-
const char *expected_html, const char *msg);
|
23
|
+
static void test_md_to_html(test_batch_runner *runner, const char *markdown,
|
24
|
+
const char *expected_html, const char *msg);
|
39
25
|
|
40
|
-
static void
|
41
|
-
|
42
|
-
int allowed_content);
|
26
|
+
static void test_content(test_batch_runner *runner, cmark_node_type type,
|
27
|
+
int allowed_content);
|
43
28
|
|
44
|
-
static void
|
45
|
-
|
46
|
-
const char *msg);
|
29
|
+
static void test_char(test_batch_runner *runner, int valid, const char *utf8,
|
30
|
+
const char *msg);
|
47
31
|
|
48
|
-
static void
|
49
|
-
|
50
|
-
const char *msg);
|
32
|
+
static void test_incomplete_char(test_batch_runner *runner, const char *utf8,
|
33
|
+
const char *msg);
|
51
34
|
|
52
|
-
static void
|
53
|
-
test_continuation_byte(test_batch_runner *runner, const char *utf8);
|
35
|
+
static void test_continuation_byte(test_batch_runner *runner, const char *utf8);
|
54
36
|
|
55
|
-
static void
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
STR_EQ(runner, cmark_version_string(), CMARK_VERSION_STRING,
|
60
|
-
"cmark_version_string");
|
37
|
+
static void version(test_batch_runner *runner) {
|
38
|
+
INT_EQ(runner, cmark_version(), CMARK_VERSION, "cmark_version");
|
39
|
+
STR_EQ(runner, cmark_version_string(), CMARK_VERSION_STRING,
|
40
|
+
"cmark_version_string");
|
61
41
|
}
|
62
42
|
|
63
|
-
static void
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
break;
|
95
|
-
}
|
96
|
-
|
97
|
-
cmark_node_free(node);
|
98
|
-
}
|
43
|
+
static void constructor(test_batch_runner *runner) {
|
44
|
+
for (int i = 0; i < num_node_types; ++i) {
|
45
|
+
cmark_node_type type = node_types[i];
|
46
|
+
cmark_node *node = cmark_node_new(type);
|
47
|
+
OK(runner, node != NULL, "new type %d", type);
|
48
|
+
INT_EQ(runner, cmark_node_get_type(node), type, "get_type %d", type);
|
49
|
+
|
50
|
+
switch (node->type) {
|
51
|
+
case CMARK_NODE_HEADING:
|
52
|
+
INT_EQ(runner, cmark_node_get_heading_level(node), 1,
|
53
|
+
"default heading level is 1");
|
54
|
+
node->as.heading.level = 1;
|
55
|
+
break;
|
56
|
+
|
57
|
+
case CMARK_NODE_LIST:
|
58
|
+
INT_EQ(runner, cmark_node_get_list_type(node), CMARK_BULLET_LIST,
|
59
|
+
"default is list type is bullet");
|
60
|
+
INT_EQ(runner, cmark_node_get_list_delim(node), CMARK_NO_DELIM,
|
61
|
+
"default is list delim is NO_DELIM");
|
62
|
+
INT_EQ(runner, cmark_node_get_list_start(node), 1,
|
63
|
+
"default is list start is 1");
|
64
|
+
INT_EQ(runner, cmark_node_get_list_tight(node), 0,
|
65
|
+
"default is list is loose");
|
66
|
+
break;
|
67
|
+
|
68
|
+
default:
|
69
|
+
break;
|
70
|
+
}
|
71
|
+
|
72
|
+
cmark_node_free(node);
|
73
|
+
}
|
99
74
|
}
|
100
75
|
|
101
|
-
static void
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
OK(runner, !cmark_node_set_header_level(bullet_list, 3),
|
265
|
-
"set_header_level error");
|
266
|
-
OK(runner, !cmark_node_set_list_type(header, CMARK_ORDERED_LIST),
|
267
|
-
"set_list_type error");
|
268
|
-
OK(runner, !cmark_node_set_list_start(code, 3),
|
269
|
-
"set_list_start error");
|
270
|
-
OK(runner, !cmark_node_set_list_tight(fenced, 0),
|
271
|
-
"set_list_tight error");
|
272
|
-
OK(runner, !cmark_node_set_literal(ordered_list, "content\n"),
|
273
|
-
"set_literal error");
|
274
|
-
OK(runner, !cmark_node_set_fence_info(paragraph, "lang"),
|
275
|
-
"set_fence_info error");
|
276
|
-
OK(runner, !cmark_node_set_url(html, "url"),
|
277
|
-
"set_url error");
|
278
|
-
OK(runner, !cmark_node_set_title(header, "title"),
|
279
|
-
"set_title error");
|
280
|
-
|
281
|
-
OK(runner, !cmark_node_set_header_level(header, 0),
|
282
|
-
"set_header_level too small");
|
283
|
-
OK(runner, !cmark_node_set_header_level(header, 7),
|
284
|
-
"set_header_level too large");
|
285
|
-
OK(runner, !cmark_node_set_list_type(bullet_list, CMARK_NO_LIST),
|
286
|
-
"set_list_type invalid");
|
287
|
-
OK(runner, !cmark_node_set_list_start(bullet_list, -1),
|
288
|
-
"set_list_start negative");
|
289
|
-
|
290
|
-
cmark_node_free(doc);
|
76
|
+
static void accessors(test_batch_runner *runner) {
|
77
|
+
static const char markdown[] = "## Header\n"
|
78
|
+
"\n"
|
79
|
+
"* Item 1\n"
|
80
|
+
"* Item 2\n"
|
81
|
+
"\n"
|
82
|
+
"2. Item 1\n"
|
83
|
+
"\n"
|
84
|
+
"3. Item 2\n"
|
85
|
+
"\n"
|
86
|
+
"\n"
|
87
|
+
" code\n"
|
88
|
+
"\n"
|
89
|
+
"``` lang\n"
|
90
|
+
"fenced\n"
|
91
|
+
"```\n"
|
92
|
+
"\n"
|
93
|
+
"<div>html</div>\n"
|
94
|
+
"\n"
|
95
|
+
"[link](url 'title')\n";
|
96
|
+
|
97
|
+
cmark_node *doc =
|
98
|
+
cmark_parse_document(markdown, sizeof(markdown) - 1, CMARK_OPT_DEFAULT);
|
99
|
+
|
100
|
+
// Getters
|
101
|
+
|
102
|
+
cmark_node *heading = cmark_node_first_child(doc);
|
103
|
+
INT_EQ(runner, cmark_node_get_heading_level(heading), 2, "get_heading_level");
|
104
|
+
|
105
|
+
cmark_node *bullet_list = cmark_node_next(heading);
|
106
|
+
INT_EQ(runner, cmark_node_get_list_type(bullet_list), CMARK_BULLET_LIST,
|
107
|
+
"get_list_type bullet");
|
108
|
+
INT_EQ(runner, cmark_node_get_list_tight(bullet_list), 1,
|
109
|
+
"get_list_tight tight");
|
110
|
+
|
111
|
+
cmark_node *ordered_list = cmark_node_next(bullet_list);
|
112
|
+
INT_EQ(runner, cmark_node_get_list_type(ordered_list), CMARK_ORDERED_LIST,
|
113
|
+
"get_list_type ordered");
|
114
|
+
INT_EQ(runner, cmark_node_get_list_delim(ordered_list), CMARK_PERIOD_DELIM,
|
115
|
+
"get_list_delim ordered");
|
116
|
+
INT_EQ(runner, cmark_node_get_list_start(ordered_list), 2, "get_list_start");
|
117
|
+
INT_EQ(runner, cmark_node_get_list_tight(ordered_list), 0,
|
118
|
+
"get_list_tight loose");
|
119
|
+
|
120
|
+
cmark_node *code = cmark_node_next(ordered_list);
|
121
|
+
STR_EQ(runner, cmark_node_get_literal(code), "code\n",
|
122
|
+
"get_literal indented code");
|
123
|
+
|
124
|
+
cmark_node *fenced = cmark_node_next(code);
|
125
|
+
STR_EQ(runner, cmark_node_get_literal(fenced), "fenced\n",
|
126
|
+
"get_literal fenced code");
|
127
|
+
STR_EQ(runner, cmark_node_get_fence_info(fenced), "lang", "get_fence_info");
|
128
|
+
|
129
|
+
cmark_node *html = cmark_node_next(fenced);
|
130
|
+
STR_EQ(runner, cmark_node_get_literal(html), "<div>html</div>\n",
|
131
|
+
"get_literal html");
|
132
|
+
|
133
|
+
cmark_node *paragraph = cmark_node_next(html);
|
134
|
+
INT_EQ(runner, cmark_node_get_start_line(paragraph), 19, "get_start_line");
|
135
|
+
INT_EQ(runner, cmark_node_get_start_column(paragraph), 1, "get_start_column");
|
136
|
+
INT_EQ(runner, cmark_node_get_end_line(paragraph), 19, "get_end_line");
|
137
|
+
|
138
|
+
cmark_node *link = cmark_node_first_child(paragraph);
|
139
|
+
STR_EQ(runner, cmark_node_get_url(link), "url", "get_url");
|
140
|
+
STR_EQ(runner, cmark_node_get_title(link), "title", "get_title");
|
141
|
+
|
142
|
+
cmark_node *string = cmark_node_first_child(link);
|
143
|
+
STR_EQ(runner, cmark_node_get_literal(string), "link", "get_literal string");
|
144
|
+
|
145
|
+
// Setters
|
146
|
+
|
147
|
+
OK(runner, cmark_node_set_heading_level(heading, 3), "set_heading_level");
|
148
|
+
|
149
|
+
OK(runner, cmark_node_set_list_type(bullet_list, CMARK_ORDERED_LIST),
|
150
|
+
"set_list_type ordered");
|
151
|
+
OK(runner, cmark_node_set_list_delim(bullet_list, CMARK_PAREN_DELIM),
|
152
|
+
"set_list_delim paren");
|
153
|
+
OK(runner, cmark_node_set_list_start(bullet_list, 3), "set_list_start");
|
154
|
+
OK(runner, cmark_node_set_list_tight(bullet_list, 0), "set_list_tight loose");
|
155
|
+
|
156
|
+
OK(runner, cmark_node_set_list_type(ordered_list, CMARK_BULLET_LIST),
|
157
|
+
"set_list_type bullet");
|
158
|
+
OK(runner, cmark_node_set_list_tight(ordered_list, 1),
|
159
|
+
"set_list_tight tight");
|
160
|
+
|
161
|
+
OK(runner, cmark_node_set_literal(code, "CODE\n"),
|
162
|
+
"set_literal indented code");
|
163
|
+
|
164
|
+
OK(runner, cmark_node_set_literal(fenced, "FENCED\n"),
|
165
|
+
"set_literal fenced code");
|
166
|
+
OK(runner, cmark_node_set_fence_info(fenced, "LANG"), "set_fence_info");
|
167
|
+
|
168
|
+
OK(runner, cmark_node_set_literal(html, "<div>HTML</div>\n"),
|
169
|
+
"set_literal html");
|
170
|
+
|
171
|
+
OK(runner, cmark_node_set_url(link, "URL"), "set_url");
|
172
|
+
OK(runner, cmark_node_set_title(link, "TITLE"), "set_title");
|
173
|
+
|
174
|
+
OK(runner, cmark_node_set_literal(string, "LINK"), "set_literal string");
|
175
|
+
|
176
|
+
char *rendered_html = cmark_render_html(doc, CMARK_OPT_DEFAULT);
|
177
|
+
static const char expected_html[] =
|
178
|
+
"<h3>Header</h3>\n"
|
179
|
+
"<ol start=\"3\">\n"
|
180
|
+
"<li>\n"
|
181
|
+
"<p>Item 1</p>\n"
|
182
|
+
"</li>\n"
|
183
|
+
"<li>\n"
|
184
|
+
"<p>Item 2</p>\n"
|
185
|
+
"</li>\n"
|
186
|
+
"</ol>\n"
|
187
|
+
"<ul>\n"
|
188
|
+
"<li>Item 1</li>\n"
|
189
|
+
"<li>Item 2</li>\n"
|
190
|
+
"</ul>\n"
|
191
|
+
"<pre><code>CODE\n"
|
192
|
+
"</code></pre>\n"
|
193
|
+
"<pre><code class=\"language-LANG\">FENCED\n"
|
194
|
+
"</code></pre>\n"
|
195
|
+
"<div>HTML</div>\n"
|
196
|
+
"<p><a href=\"URL\" title=\"TITLE\">LINK</a></p>\n";
|
197
|
+
STR_EQ(runner, rendered_html, expected_html, "setters work");
|
198
|
+
free(rendered_html);
|
199
|
+
|
200
|
+
// Getter errors
|
201
|
+
|
202
|
+
INT_EQ(runner, cmark_node_get_heading_level(bullet_list), 0,
|
203
|
+
"get_heading_level error");
|
204
|
+
INT_EQ(runner, cmark_node_get_list_type(heading), CMARK_NO_LIST,
|
205
|
+
"get_list_type error");
|
206
|
+
INT_EQ(runner, cmark_node_get_list_start(code), 0, "get_list_start error");
|
207
|
+
INT_EQ(runner, cmark_node_get_list_tight(fenced), 0, "get_list_tight error");
|
208
|
+
OK(runner, cmark_node_get_literal(ordered_list) == NULL, "get_literal error");
|
209
|
+
OK(runner, cmark_node_get_fence_info(paragraph) == NULL,
|
210
|
+
"get_fence_info error");
|
211
|
+
OK(runner, cmark_node_get_url(html) == NULL, "get_url error");
|
212
|
+
OK(runner, cmark_node_get_title(heading) == NULL, "get_title error");
|
213
|
+
|
214
|
+
// Setter errors
|
215
|
+
|
216
|
+
OK(runner, !cmark_node_set_heading_level(bullet_list, 3),
|
217
|
+
"set_heading_level error");
|
218
|
+
OK(runner, !cmark_node_set_list_type(heading, CMARK_ORDERED_LIST),
|
219
|
+
"set_list_type error");
|
220
|
+
OK(runner, !cmark_node_set_list_start(code, 3), "set_list_start error");
|
221
|
+
OK(runner, !cmark_node_set_list_tight(fenced, 0), "set_list_tight error");
|
222
|
+
OK(runner, !cmark_node_set_literal(ordered_list, "content\n"),
|
223
|
+
"set_literal error");
|
224
|
+
OK(runner, !cmark_node_set_fence_info(paragraph, "lang"),
|
225
|
+
"set_fence_info error");
|
226
|
+
OK(runner, !cmark_node_set_url(html, "url"), "set_url error");
|
227
|
+
OK(runner, !cmark_node_set_title(heading, "title"), "set_title error");
|
228
|
+
|
229
|
+
OK(runner, !cmark_node_set_heading_level(heading, 0),
|
230
|
+
"set_heading_level too small");
|
231
|
+
OK(runner, !cmark_node_set_heading_level(heading, 7),
|
232
|
+
"set_heading_level too large");
|
233
|
+
OK(runner, !cmark_node_set_list_type(bullet_list, CMARK_NO_LIST),
|
234
|
+
"set_list_type invalid");
|
235
|
+
OK(runner, !cmark_node_set_list_start(bullet_list, -1),
|
236
|
+
"set_list_start negative");
|
237
|
+
|
238
|
+
cmark_node_free(doc);
|
291
239
|
}
|
292
240
|
|
293
|
-
static void
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
p1->next = p2;
|
241
|
+
static void node_check(test_batch_runner *runner) {
|
242
|
+
// Construct an incomplete tree.
|
243
|
+
cmark_node *doc = cmark_node_new(CMARK_NODE_DOCUMENT);
|
244
|
+
cmark_node *p1 = cmark_node_new(CMARK_NODE_PARAGRAPH);
|
245
|
+
cmark_node *p2 = cmark_node_new(CMARK_NODE_PARAGRAPH);
|
246
|
+
doc->first_child = p1;
|
247
|
+
p1->next = p2;
|
301
248
|
|
302
|
-
|
303
|
-
|
304
|
-
"node_check fixes tree");
|
249
|
+
INT_EQ(runner, cmark_node_check(doc, NULL), 4, "node_check works");
|
250
|
+
INT_EQ(runner, cmark_node_check(doc, NULL), 0, "node_check fixes tree");
|
305
251
|
|
306
|
-
|
252
|
+
cmark_node_free(doc);
|
307
253
|
}
|
308
254
|
|
309
|
-
static void
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
cmark_iter_free(iter);
|
327
|
-
cmark_node_free(doc);
|
255
|
+
static void iterator(test_batch_runner *runner) {
|
256
|
+
cmark_node *doc = cmark_parse_document("> a *b*\n\nc", 10, CMARK_OPT_DEFAULT);
|
257
|
+
int parnodes = 0;
|
258
|
+
cmark_event_type ev_type;
|
259
|
+
cmark_iter *iter = cmark_iter_new(doc);
|
260
|
+
cmark_node *cur;
|
261
|
+
|
262
|
+
while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) {
|
263
|
+
cur = cmark_iter_get_node(iter);
|
264
|
+
if (cur->type == CMARK_NODE_PARAGRAPH && ev_type == CMARK_EVENT_ENTER) {
|
265
|
+
parnodes += 1;
|
266
|
+
}
|
267
|
+
}
|
268
|
+
INT_EQ(runner, parnodes, 2, "iterate correctly counts paragraphs");
|
269
|
+
|
270
|
+
cmark_iter_free(iter);
|
271
|
+
cmark_node_free(doc);
|
328
272
|
}
|
329
273
|
|
330
|
-
static void
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
"<p>a c</p>\n"
|
363
|
-
"<p>a c</p>\n";
|
364
|
-
STR_EQ(runner, html, expected, "iterate and delete nodes");
|
365
|
-
|
366
|
-
free(html);
|
367
|
-
cmark_iter_free(iter);
|
368
|
-
cmark_node_free(doc);
|
274
|
+
static void iterator_delete(test_batch_runner *runner) {
|
275
|
+
static const char md[] = "a *b* c\n"
|
276
|
+
"\n"
|
277
|
+
"* item1\n"
|
278
|
+
"* item2\n"
|
279
|
+
"\n"
|
280
|
+
"a `b` c\n"
|
281
|
+
"\n"
|
282
|
+
"* item1\n"
|
283
|
+
"* item2\n";
|
284
|
+
cmark_node *doc = cmark_parse_document(md, sizeof(md) - 1, CMARK_OPT_DEFAULT);
|
285
|
+
cmark_iter *iter = cmark_iter_new(doc);
|
286
|
+
cmark_event_type ev_type;
|
287
|
+
|
288
|
+
while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) {
|
289
|
+
cmark_node *node = cmark_iter_get_node(iter);
|
290
|
+
// Delete list, emph, and code nodes.
|
291
|
+
if ((ev_type == CMARK_EVENT_EXIT && node->type == CMARK_NODE_LIST) ||
|
292
|
+
(ev_type == CMARK_EVENT_EXIT && node->type == CMARK_NODE_EMPH) ||
|
293
|
+
(ev_type == CMARK_EVENT_ENTER && node->type == CMARK_NODE_CODE)) {
|
294
|
+
cmark_node_free(node);
|
295
|
+
}
|
296
|
+
}
|
297
|
+
|
298
|
+
char *html = cmark_render_html(doc, CMARK_OPT_DEFAULT);
|
299
|
+
static const char expected[] = "<p>a c</p>\n"
|
300
|
+
"<p>a c</p>\n";
|
301
|
+
STR_EQ(runner, html, expected, "iterate and delete nodes");
|
302
|
+
|
303
|
+
free(html);
|
304
|
+
cmark_iter_free(iter);
|
305
|
+
cmark_node_free(doc);
|
369
306
|
}
|
370
307
|
|
371
|
-
static void
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
html = cmark_render_html(doc, CMARK_OPT_DEFAULT);
|
437
|
-
STR_EQ(runner, html, "<p>Hello, !</p>\n",
|
438
|
-
"render_html after shuffling");
|
439
|
-
free(html);
|
440
|
-
|
441
|
-
cmark_node_free(doc);
|
442
|
-
|
443
|
-
// TODO: Test that the contents of an unlinked inline are valid
|
444
|
-
// after the parent block was destroyed. This doesn't work so far.
|
445
|
-
cmark_node_free(emph);
|
308
|
+
static void create_tree(test_batch_runner *runner) {
|
309
|
+
char *html;
|
310
|
+
cmark_node *doc = cmark_node_new(CMARK_NODE_DOCUMENT);
|
311
|
+
|
312
|
+
cmark_node *p = cmark_node_new(CMARK_NODE_PARAGRAPH);
|
313
|
+
OK(runner, !cmark_node_insert_before(doc, p), "insert before root fails");
|
314
|
+
OK(runner, !cmark_node_insert_after(doc, p), "insert after root fails");
|
315
|
+
OK(runner, cmark_node_append_child(doc, p), "append1");
|
316
|
+
INT_EQ(runner, cmark_node_check(doc, NULL), 0, "append1 consistent");
|
317
|
+
OK(runner, cmark_node_parent(p) == doc, "node_parent");
|
318
|
+
|
319
|
+
cmark_node *emph = cmark_node_new(CMARK_NODE_EMPH);
|
320
|
+
OK(runner, cmark_node_prepend_child(p, emph), "prepend1");
|
321
|
+
INT_EQ(runner, cmark_node_check(doc, NULL), 0, "prepend1 consistent");
|
322
|
+
|
323
|
+
cmark_node *str1 = cmark_node_new(CMARK_NODE_TEXT);
|
324
|
+
cmark_node_set_literal(str1, "Hello, ");
|
325
|
+
OK(runner, cmark_node_prepend_child(p, str1), "prepend2");
|
326
|
+
INT_EQ(runner, cmark_node_check(doc, NULL), 0, "prepend2 consistent");
|
327
|
+
|
328
|
+
cmark_node *str3 = cmark_node_new(CMARK_NODE_TEXT);
|
329
|
+
cmark_node_set_literal(str3, "!");
|
330
|
+
OK(runner, cmark_node_append_child(p, str3), "append2");
|
331
|
+
INT_EQ(runner, cmark_node_check(doc, NULL), 0, "append2 consistent");
|
332
|
+
|
333
|
+
cmark_node *str2 = cmark_node_new(CMARK_NODE_TEXT);
|
334
|
+
cmark_node_set_literal(str2, "world");
|
335
|
+
OK(runner, cmark_node_append_child(emph, str2), "append3");
|
336
|
+
INT_EQ(runner, cmark_node_check(doc, NULL), 0, "append3 consistent");
|
337
|
+
|
338
|
+
html = cmark_render_html(doc, CMARK_OPT_DEFAULT);
|
339
|
+
STR_EQ(runner, html, "<p>Hello, <em>world</em>!</p>\n", "render_html");
|
340
|
+
free(html);
|
341
|
+
|
342
|
+
OK(runner, cmark_node_insert_before(str1, str3), "ins before1");
|
343
|
+
INT_EQ(runner, cmark_node_check(doc, NULL), 0, "ins before1 consistent");
|
344
|
+
// 31e
|
345
|
+
OK(runner, cmark_node_first_child(p) == str3, "ins before1 works");
|
346
|
+
|
347
|
+
OK(runner, cmark_node_insert_before(str1, emph), "ins before2");
|
348
|
+
INT_EQ(runner, cmark_node_check(doc, NULL), 0, "ins before2 consistent");
|
349
|
+
// 3e1
|
350
|
+
OK(runner, cmark_node_last_child(p) == str1, "ins before2 works");
|
351
|
+
|
352
|
+
OK(runner, cmark_node_insert_after(str1, str3), "ins after1");
|
353
|
+
INT_EQ(runner, cmark_node_check(doc, NULL), 0, "ins after1 consistent");
|
354
|
+
// e13
|
355
|
+
OK(runner, cmark_node_next(str1) == str3, "ins after1 works");
|
356
|
+
|
357
|
+
OK(runner, cmark_node_insert_after(str1, emph), "ins after2");
|
358
|
+
INT_EQ(runner, cmark_node_check(doc, NULL), 0, "ins after2 consistent");
|
359
|
+
// 1e3
|
360
|
+
OK(runner, cmark_node_previous(emph) == str1, "ins after2 works");
|
361
|
+
|
362
|
+
cmark_node_unlink(emph);
|
363
|
+
|
364
|
+
html = cmark_render_html(doc, CMARK_OPT_DEFAULT);
|
365
|
+
STR_EQ(runner, html, "<p>Hello, !</p>\n", "render_html after shuffling");
|
366
|
+
free(html);
|
367
|
+
|
368
|
+
cmark_node_free(doc);
|
369
|
+
|
370
|
+
// TODO: Test that the contents of an unlinked inline are valid
|
371
|
+
// after the parent block was destroyed. This doesn't work so far.
|
372
|
+
cmark_node_free(emph);
|
446
373
|
}
|
447
374
|
|
448
|
-
void
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
(1 << CMARK_NODE_TEXT) |
|
481
|
-
(1 << CMARK_NODE_SOFTBREAK) |
|
482
|
-
(1 << CMARK_NODE_LINEBREAK) |
|
483
|
-
(1 << CMARK_NODE_CODE) |
|
484
|
-
(1 << CMARK_NODE_INLINE_HTML) |
|
485
|
-
(1 << CMARK_NODE_EMPH) |
|
486
|
-
(1 << CMARK_NODE_STRONG) |
|
487
|
-
(1 << CMARK_NODE_LINK) |
|
488
|
-
(1 << CMARK_NODE_IMAGE);
|
489
|
-
|
490
|
-
test_content(runner, CMARK_NODE_DOCUMENT, top_level_blocks);
|
491
|
-
test_content(runner, CMARK_NODE_BLOCK_QUOTE, top_level_blocks);
|
492
|
-
test_content(runner, CMARK_NODE_LIST, list_item_flag);
|
493
|
-
test_content(runner, CMARK_NODE_ITEM, top_level_blocks);
|
494
|
-
test_content(runner, CMARK_NODE_CODE_BLOCK , 0);
|
495
|
-
test_content(runner, CMARK_NODE_HTML, 0);
|
496
|
-
test_content(runner, CMARK_NODE_PARAGRAPH, all_inlines);
|
497
|
-
test_content(runner, CMARK_NODE_HEADER, all_inlines);
|
498
|
-
test_content(runner, CMARK_NODE_HRULE, 0);
|
499
|
-
test_content(runner, CMARK_NODE_TEXT, 0);
|
500
|
-
test_content(runner, CMARK_NODE_SOFTBREAK, 0);
|
501
|
-
test_content(runner, CMARK_NODE_LINEBREAK, 0);
|
502
|
-
test_content(runner, CMARK_NODE_CODE, 0);
|
503
|
-
test_content(runner, CMARK_NODE_INLINE_HTML, 0);
|
504
|
-
test_content(runner, CMARK_NODE_EMPH, all_inlines);
|
505
|
-
test_content(runner, CMARK_NODE_STRONG, all_inlines);
|
506
|
-
test_content(runner, CMARK_NODE_LINK, all_inlines);
|
507
|
-
test_content(runner, CMARK_NODE_IMAGE, all_inlines);
|
375
|
+
static void custom_nodes(test_batch_runner *runner) {
|
376
|
+
char *html;
|
377
|
+
char *man;
|
378
|
+
cmark_node *doc = cmark_node_new(CMARK_NODE_DOCUMENT);
|
379
|
+
cmark_node *p = cmark_node_new(CMARK_NODE_PARAGRAPH);
|
380
|
+
cmark_node_append_child(doc, p);
|
381
|
+
cmark_node *ci = cmark_node_new(CMARK_NODE_CUSTOM_INLINE);
|
382
|
+
cmark_node *str1 = cmark_node_new(CMARK_NODE_TEXT);
|
383
|
+
cmark_node_set_literal(str1, "Hello");
|
384
|
+
OK(runner, cmark_node_append_child(ci, str1), "append1");
|
385
|
+
OK(runner, cmark_node_set_on_enter(ci, "<ON ENTER|"), "set_on_enter");
|
386
|
+
OK(runner, cmark_node_set_on_exit(ci, "|ON EXIT>"), "set_on_exit");
|
387
|
+
STR_EQ(runner, cmark_node_get_on_enter(ci), "<ON ENTER|", "get_on_enter");
|
388
|
+
STR_EQ(runner, cmark_node_get_on_exit(ci), "|ON EXIT>", "get_on_exit");
|
389
|
+
cmark_node_append_child(p, ci);
|
390
|
+
cmark_node *cb = cmark_node_new(CMARK_NODE_CUSTOM_BLOCK);
|
391
|
+
cmark_node_set_on_enter(cb, "<on enter|");
|
392
|
+
// leave on_exit unset
|
393
|
+
STR_EQ(runner, cmark_node_get_on_exit(cb), "", "get_on_exit (empty)");
|
394
|
+
cmark_node_append_child(doc, cb);
|
395
|
+
|
396
|
+
html = cmark_render_html(doc, CMARK_OPT_DEFAULT);
|
397
|
+
STR_EQ(runner, html, "<p><ON ENTER|Hello|ON EXIT></p>\n<on enter|\n",
|
398
|
+
"render_html");
|
399
|
+
free(html);
|
400
|
+
|
401
|
+
man = cmark_render_man(doc, CMARK_OPT_DEFAULT, 0);
|
402
|
+
STR_EQ(runner, man, ".PP\n<ON ENTER|Hello|ON EXIT>\n<on enter|\n",
|
403
|
+
"render_man");
|
404
|
+
free(man);
|
405
|
+
|
406
|
+
cmark_node_free(doc);
|
508
407
|
}
|
509
408
|
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
409
|
+
void hierarchy(test_batch_runner *runner) {
|
410
|
+
cmark_node *bquote1 = cmark_node_new(CMARK_NODE_BLOCK_QUOTE);
|
411
|
+
cmark_node *bquote2 = cmark_node_new(CMARK_NODE_BLOCK_QUOTE);
|
412
|
+
cmark_node *bquote3 = cmark_node_new(CMARK_NODE_BLOCK_QUOTE);
|
413
|
+
|
414
|
+
OK(runner, cmark_node_append_child(bquote1, bquote2), "append bquote2");
|
415
|
+
OK(runner, cmark_node_append_child(bquote2, bquote3), "append bquote3");
|
416
|
+
OK(runner, !cmark_node_append_child(bquote3, bquote3),
|
417
|
+
"adding a node as child of itself fails");
|
418
|
+
OK(runner, !cmark_node_append_child(bquote3, bquote1),
|
419
|
+
"adding a parent as child fails");
|
420
|
+
|
421
|
+
cmark_node_free(bquote1);
|
422
|
+
|
423
|
+
int max_node_type = CMARK_NODE_LAST_BLOCK > CMARK_NODE_LAST_INLINE
|
424
|
+
? CMARK_NODE_LAST_BLOCK
|
425
|
+
: CMARK_NODE_LAST_INLINE;
|
426
|
+
OK(runner, max_node_type < 32, "all node types < 32");
|
427
|
+
|
428
|
+
int list_item_flag = 1 << CMARK_NODE_ITEM;
|
429
|
+
int top_level_blocks =
|
430
|
+
(1 << CMARK_NODE_BLOCK_QUOTE) | (1 << CMARK_NODE_LIST) |
|
431
|
+
(1 << CMARK_NODE_CODE_BLOCK) | (1 << CMARK_NODE_HTML_BLOCK) |
|
432
|
+
(1 << CMARK_NODE_PARAGRAPH) | (1 << CMARK_NODE_HEADING) |
|
433
|
+
(1 << CMARK_NODE_THEMATIC_BREAK);
|
434
|
+
int all_inlines = (1 << CMARK_NODE_TEXT) | (1 << CMARK_NODE_SOFTBREAK) |
|
435
|
+
(1 << CMARK_NODE_LINEBREAK) | (1 << CMARK_NODE_CODE) |
|
436
|
+
(1 << CMARK_NODE_HTML_INLINE) | (1 << CMARK_NODE_EMPH) |
|
437
|
+
(1 << CMARK_NODE_STRONG) | (1 << CMARK_NODE_LINK) |
|
438
|
+
(1 << CMARK_NODE_IMAGE);
|
439
|
+
|
440
|
+
test_content(runner, CMARK_NODE_DOCUMENT, top_level_blocks);
|
441
|
+
test_content(runner, CMARK_NODE_BLOCK_QUOTE, top_level_blocks);
|
442
|
+
test_content(runner, CMARK_NODE_LIST, list_item_flag);
|
443
|
+
test_content(runner, CMARK_NODE_ITEM, top_level_blocks);
|
444
|
+
test_content(runner, CMARK_NODE_CODE_BLOCK, 0);
|
445
|
+
test_content(runner, CMARK_NODE_HTML_BLOCK, 0);
|
446
|
+
test_content(runner, CMARK_NODE_PARAGRAPH, all_inlines);
|
447
|
+
test_content(runner, CMARK_NODE_HEADING, all_inlines);
|
448
|
+
test_content(runner, CMARK_NODE_THEMATIC_BREAK, 0);
|
449
|
+
test_content(runner, CMARK_NODE_TEXT, 0);
|
450
|
+
test_content(runner, CMARK_NODE_SOFTBREAK, 0);
|
451
|
+
test_content(runner, CMARK_NODE_LINEBREAK, 0);
|
452
|
+
test_content(runner, CMARK_NODE_CODE, 0);
|
453
|
+
test_content(runner, CMARK_NODE_HTML_INLINE, 0);
|
454
|
+
test_content(runner, CMARK_NODE_EMPH, all_inlines);
|
455
|
+
test_content(runner, CMARK_NODE_STRONG, all_inlines);
|
456
|
+
test_content(runner, CMARK_NODE_LINK, all_inlines);
|
457
|
+
test_content(runner, CMARK_NODE_IMAGE, all_inlines);
|
458
|
+
}
|
459
|
+
|
460
|
+
static void test_content(test_batch_runner *runner, cmark_node_type type,
|
461
|
+
int allowed_content) {
|
462
|
+
cmark_node *node = cmark_node_new(type);
|
463
|
+
|
464
|
+
for (int i = 0; i < num_node_types; ++i) {
|
465
|
+
cmark_node_type child_type = node_types[i];
|
466
|
+
cmark_node *child = cmark_node_new(child_type);
|
467
|
+
|
468
|
+
int got = cmark_node_append_child(node, child);
|
469
|
+
int expected = (allowed_content >> child_type) & 1;
|
515
470
|
|
516
|
-
|
517
|
-
cmark_node_type child_type = node_types[i];
|
518
|
-
cmark_node *child = cmark_node_new(child_type);
|
471
|
+
INT_EQ(runner, got, expected, "add %d as child of %d", child_type, type);
|
519
472
|
|
520
|
-
|
521
|
-
|
473
|
+
cmark_node_free(child);
|
474
|
+
}
|
475
|
+
|
476
|
+
cmark_node_free(node);
|
477
|
+
}
|
478
|
+
|
479
|
+
static void parser(test_batch_runner *runner) {
|
480
|
+
test_md_to_html(runner, "No newline", "<p>No newline</p>\n",
|
481
|
+
"document without trailing newline");
|
482
|
+
}
|
522
483
|
|
523
|
-
|
524
|
-
|
484
|
+
static void render_html(test_batch_runner *runner) {
|
485
|
+
char *html;
|
525
486
|
|
526
|
-
|
527
|
-
|
487
|
+
static const char markdown[] = "foo *bar*\n"
|
488
|
+
"\n"
|
489
|
+
"paragraph 2\n";
|
490
|
+
cmark_node *doc =
|
491
|
+
cmark_parse_document(markdown, sizeof(markdown) - 1, CMARK_OPT_DEFAULT);
|
492
|
+
|
493
|
+
cmark_node *paragraph = cmark_node_first_child(doc);
|
494
|
+
html = cmark_render_html(paragraph, CMARK_OPT_DEFAULT);
|
495
|
+
STR_EQ(runner, html, "<p>foo <em>bar</em></p>\n", "render single paragraph");
|
496
|
+
free(html);
|
497
|
+
|
498
|
+
cmark_node *string = cmark_node_first_child(paragraph);
|
499
|
+
html = cmark_render_html(string, CMARK_OPT_DEFAULT);
|
500
|
+
STR_EQ(runner, html, "foo ", "render single inline");
|
501
|
+
free(html);
|
502
|
+
|
503
|
+
cmark_node *emph = cmark_node_next(string);
|
504
|
+
html = cmark_render_html(emph, CMARK_OPT_DEFAULT);
|
505
|
+
STR_EQ(runner, html, "<em>bar</em>", "render inline with children");
|
506
|
+
free(html);
|
507
|
+
|
508
|
+
cmark_node_free(doc);
|
509
|
+
}
|
510
|
+
|
511
|
+
static void render_xml(test_batch_runner *runner) {
|
512
|
+
char *xml;
|
513
|
+
|
514
|
+
static const char markdown[] = "foo *bar*\n"
|
515
|
+
"\n"
|
516
|
+
"paragraph 2\n";
|
517
|
+
cmark_node *doc =
|
518
|
+
cmark_parse_document(markdown, sizeof(markdown) - 1, CMARK_OPT_DEFAULT);
|
519
|
+
|
520
|
+
xml = cmark_render_xml(doc, CMARK_OPT_DEFAULT);
|
521
|
+
STR_EQ(runner, xml,
|
522
|
+
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
523
|
+
"<!DOCTYPE document SYSTEM \"CommonMark.dtd\">\n"
|
524
|
+
"<document xmlns=\"http://commonmark.org/xml/1.0\">\n"
|
525
|
+
" <paragraph>\n"
|
526
|
+
" <text>foo </text>\n"
|
527
|
+
" <emph>\n"
|
528
|
+
" <text>bar</text>\n"
|
529
|
+
" </emph>\n"
|
530
|
+
" </paragraph>\n"
|
531
|
+
" <paragraph>\n"
|
532
|
+
" <text>paragraph 2</text>\n"
|
533
|
+
" </paragraph>\n"
|
534
|
+
"</document>\n",
|
535
|
+
"render document");
|
536
|
+
free(xml);
|
537
|
+
cmark_node *paragraph = cmark_node_first_child(doc);
|
538
|
+
xml = cmark_render_xml(paragraph, CMARK_OPT_DEFAULT | CMARK_OPT_SOURCEPOS);
|
539
|
+
STR_EQ(runner, xml,
|
540
|
+
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
541
|
+
"<!DOCTYPE document SYSTEM \"CommonMark.dtd\">\n"
|
542
|
+
"<paragraph sourcepos=\"1:1-1:9\">\n"
|
543
|
+
" <text>foo </text>\n"
|
544
|
+
" <emph>\n"
|
545
|
+
" <text>bar</text>\n"
|
546
|
+
" </emph>\n"
|
547
|
+
"</paragraph>\n",
|
548
|
+
"render first paragraph with source pos");
|
549
|
+
free(xml);
|
550
|
+
cmark_node_free(doc);
|
551
|
+
}
|
528
552
|
|
529
|
-
|
553
|
+
static void render_man(test_batch_runner *runner) {
|
554
|
+
char *man;
|
555
|
+
|
556
|
+
static const char markdown[] = "foo *bar*\n"
|
557
|
+
"\n"
|
558
|
+
"- Lorem ipsum dolor sit amet,\n"
|
559
|
+
" consectetur adipiscing elit,\n"
|
560
|
+
"- sed do eiusmod tempor incididunt\n"
|
561
|
+
" ut labore et dolore magna aliqua.\n";
|
562
|
+
cmark_node *doc =
|
563
|
+
cmark_parse_document(markdown, sizeof(markdown) - 1, CMARK_OPT_DEFAULT);
|
564
|
+
|
565
|
+
man = cmark_render_man(doc, CMARK_OPT_DEFAULT, 20);
|
566
|
+
STR_EQ(runner, man,
|
567
|
+
".PP\n"
|
568
|
+
"foo \\f[I]bar\\f[]\n"
|
569
|
+
".IP \\[bu] 2\n"
|
570
|
+
"Lorem ipsum dolor\n"
|
571
|
+
"sit amet,\n"
|
572
|
+
"consectetur\n"
|
573
|
+
"adipiscing elit,\n"
|
574
|
+
".IP \\[bu] 2\n"
|
575
|
+
"sed do eiusmod\n"
|
576
|
+
"tempor incididunt ut\n"
|
577
|
+
"labore et dolore\n"
|
578
|
+
"magna aliqua.\n",
|
579
|
+
"render document with wrapping");
|
580
|
+
free(man);
|
581
|
+
man = cmark_render_man(doc, CMARK_OPT_DEFAULT, 0);
|
582
|
+
STR_EQ(runner, man,
|
583
|
+
".PP\n"
|
584
|
+
"foo \\f[I]bar\\f[]\n"
|
585
|
+
".IP \\[bu] 2\n"
|
586
|
+
"Lorem ipsum dolor sit amet,\n"
|
587
|
+
"consectetur adipiscing elit,\n"
|
588
|
+
".IP \\[bu] 2\n"
|
589
|
+
"sed do eiusmod tempor incididunt\n"
|
590
|
+
"ut labore et dolore magna aliqua.\n",
|
591
|
+
"render document without wrapping");
|
592
|
+
free(man);
|
593
|
+
cmark_node_free(doc);
|
530
594
|
}
|
531
595
|
|
532
|
-
static void
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
596
|
+
static void render_latex(test_batch_runner *runner) {
|
597
|
+
char *latex;
|
598
|
+
|
599
|
+
static const char markdown[] = "foo *bar* $%\n"
|
600
|
+
"\n"
|
601
|
+
"- Lorem ipsum dolor sit amet,\n"
|
602
|
+
" consectetur adipiscing elit,\n"
|
603
|
+
"- sed do eiusmod tempor incididunt\n"
|
604
|
+
" ut labore et dolore magna aliqua.\n";
|
605
|
+
cmark_node *doc =
|
606
|
+
cmark_parse_document(markdown, sizeof(markdown) - 1, CMARK_OPT_DEFAULT);
|
607
|
+
|
608
|
+
latex = cmark_render_latex(doc, CMARK_OPT_DEFAULT, 20);
|
609
|
+
STR_EQ(runner, latex,
|
610
|
+
"foo \\emph{bar} \\$\\%\n"
|
611
|
+
"\n"
|
612
|
+
"\\begin{itemize}\n"
|
613
|
+
"\\item Lorem ipsum\n"
|
614
|
+
"dolor sit amet,\n"
|
615
|
+
"consectetur\n"
|
616
|
+
"adipiscing elit,\n"
|
617
|
+
"\n"
|
618
|
+
"\\item sed do eiusmod\n"
|
619
|
+
"tempor incididunt ut\n"
|
620
|
+
"labore et dolore\n"
|
621
|
+
"magna aliqua.\n"
|
622
|
+
"\n"
|
623
|
+
"\\end{itemize}\n",
|
624
|
+
"render document with wrapping");
|
625
|
+
free(latex);
|
626
|
+
latex = cmark_render_latex(doc, CMARK_OPT_DEFAULT, 0);
|
627
|
+
STR_EQ(runner, latex,
|
628
|
+
"foo \\emph{bar} \\$\\%\n"
|
629
|
+
"\n"
|
630
|
+
"\\begin{itemize}\n"
|
631
|
+
"\\item Lorem ipsum dolor sit amet,\n"
|
632
|
+
"consectetur adipiscing elit,\n"
|
633
|
+
"\n"
|
634
|
+
"\\item sed do eiusmod tempor incididunt\n"
|
635
|
+
"ut labore et dolore magna aliqua.\n"
|
636
|
+
"\n"
|
637
|
+
"\\end{itemize}\n",
|
638
|
+
"render document without wrapping");
|
639
|
+
free(latex);
|
640
|
+
cmark_node_free(doc);
|
537
641
|
}
|
538
642
|
|
539
|
-
static void
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
643
|
+
static void render_commonmark(test_batch_runner *runner) {
|
644
|
+
char *commonmark;
|
645
|
+
|
646
|
+
static const char markdown[] = "> \\- foo *bar* \\*bar\\*\n"
|
647
|
+
"\n"
|
648
|
+
"- Lorem ipsum dolor sit amet,\n"
|
649
|
+
" consectetur adipiscing elit,\n"
|
650
|
+
"- sed do eiusmod tempor incididunt\n"
|
651
|
+
" ut labore et dolore magna aliqua.\n";
|
652
|
+
cmark_node *doc =
|
653
|
+
cmark_parse_document(markdown, sizeof(markdown) - 1, CMARK_OPT_DEFAULT);
|
654
|
+
|
655
|
+
commonmark = cmark_render_commonmark(doc, CMARK_OPT_DEFAULT, 24);
|
656
|
+
STR_EQ(runner, commonmark,
|
657
|
+
"> \\- foo *bar* \\*bar\\*\n"
|
658
|
+
"\n"
|
659
|
+
"* Lorem ipsum dolor sit\n"
|
660
|
+
" amet, consectetur\n"
|
661
|
+
" adipiscing elit,\n"
|
662
|
+
"* sed do eiusmod tempor\n"
|
663
|
+
" incididunt ut labore\n"
|
664
|
+
" et dolore magna\n"
|
665
|
+
" aliqua.\n",
|
666
|
+
"render document with wrapping");
|
667
|
+
free(commonmark);
|
668
|
+
commonmark = cmark_render_commonmark(doc, CMARK_OPT_DEFAULT, 0);
|
669
|
+
STR_EQ(runner, commonmark, "> \\- foo *bar* \\*bar\\*\n"
|
670
|
+
"\n"
|
671
|
+
"* Lorem ipsum dolor sit amet,\n"
|
672
|
+
" consectetur adipiscing elit,\n"
|
673
|
+
"* sed do eiusmod tempor incididunt\n"
|
674
|
+
" ut labore et dolore magna aliqua.\n",
|
675
|
+
"render document without wrapping");
|
676
|
+
free(commonmark);
|
677
|
+
cmark_node_free(doc);
|
568
678
|
}
|
569
679
|
|
570
|
-
static void
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
CMARK_OPT_DEFAULT);
|
611
|
-
STR_EQ(runner, html, "<p>((((" UTF8_REPL "))))</p>\n",
|
612
|
-
"utf8 with U+0000");
|
613
|
-
free(html);
|
680
|
+
static void utf8(test_batch_runner *runner) {
|
681
|
+
// Ranges
|
682
|
+
test_char(runner, 1, "\x01", "valid utf8 01");
|
683
|
+
test_char(runner, 1, "\x7F", "valid utf8 7F");
|
684
|
+
test_char(runner, 0, "\x80", "invalid utf8 80");
|
685
|
+
test_char(runner, 0, "\xBF", "invalid utf8 BF");
|
686
|
+
test_char(runner, 0, "\xC0\x80", "invalid utf8 C080");
|
687
|
+
test_char(runner, 0, "\xC1\xBF", "invalid utf8 C1BF");
|
688
|
+
test_char(runner, 1, "\xC2\x80", "valid utf8 C280");
|
689
|
+
test_char(runner, 1, "\xDF\xBF", "valid utf8 DFBF");
|
690
|
+
test_char(runner, 0, "\xE0\x80\x80", "invalid utf8 E08080");
|
691
|
+
test_char(runner, 0, "\xE0\x9F\xBF", "invalid utf8 E09FBF");
|
692
|
+
test_char(runner, 1, "\xE0\xA0\x80", "valid utf8 E0A080");
|
693
|
+
test_char(runner, 1, "\xED\x9F\xBF", "valid utf8 ED9FBF");
|
694
|
+
test_char(runner, 0, "\xED\xA0\x80", "invalid utf8 EDA080");
|
695
|
+
test_char(runner, 0, "\xED\xBF\xBF", "invalid utf8 EDBFBF");
|
696
|
+
test_char(runner, 0, "\xF0\x80\x80\x80", "invalid utf8 F0808080");
|
697
|
+
test_char(runner, 0, "\xF0\x8F\xBF\xBF", "invalid utf8 F08FBFBF");
|
698
|
+
test_char(runner, 1, "\xF0\x90\x80\x80", "valid utf8 F0908080");
|
699
|
+
test_char(runner, 1, "\xF4\x8F\xBF\xBF", "valid utf8 F48FBFBF");
|
700
|
+
test_char(runner, 0, "\xF4\x90\x80\x80", "invalid utf8 F4908080");
|
701
|
+
test_char(runner, 0, "\xF7\xBF\xBF\xBF", "invalid utf8 F7BFBFBF");
|
702
|
+
test_char(runner, 0, "\xF8", "invalid utf8 F8");
|
703
|
+
test_char(runner, 0, "\xFF", "invalid utf8 FF");
|
704
|
+
|
705
|
+
// Incomplete byte sequences at end of input
|
706
|
+
test_incomplete_char(runner, "\xE0\xA0", "invalid utf8 E0A0");
|
707
|
+
test_incomplete_char(runner, "\xF0\x90\x80", "invalid utf8 F09080");
|
708
|
+
|
709
|
+
// Invalid continuation bytes
|
710
|
+
test_continuation_byte(runner, "\xC2\x80");
|
711
|
+
test_continuation_byte(runner, "\xE0\xA0\x80");
|
712
|
+
test_continuation_byte(runner, "\xF0\x90\x80\x80");
|
713
|
+
|
714
|
+
// Test string containing null character
|
715
|
+
static const char string_with_null[] = "((((\0))))";
|
716
|
+
char *html = cmark_markdown_to_html(
|
717
|
+
string_with_null, sizeof(string_with_null) - 1, CMARK_OPT_DEFAULT);
|
718
|
+
STR_EQ(runner, html, "<p>((((" UTF8_REPL "))))</p>\n", "utf8 with U+0000");
|
719
|
+
free(html);
|
614
720
|
}
|
615
721
|
|
616
|
-
static void
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
else {
|
629
|
-
test_md_to_html(runner, buf, "<p>((((" UTF8_REPL "))))</p>\n",
|
630
|
-
msg);
|
631
|
-
}
|
722
|
+
static void test_char(test_batch_runner *runner, int valid, const char *utf8,
|
723
|
+
const char *msg) {
|
724
|
+
char buf[20];
|
725
|
+
sprintf(buf, "((((%s))))", utf8);
|
726
|
+
|
727
|
+
if (valid) {
|
728
|
+
char expected[30];
|
729
|
+
sprintf(expected, "<p>((((%s))))</p>\n", utf8);
|
730
|
+
test_md_to_html(runner, buf, expected, msg);
|
731
|
+
} else {
|
732
|
+
test_md_to_html(runner, buf, "<p>((((" UTF8_REPL "))))</p>\n", msg);
|
733
|
+
}
|
632
734
|
}
|
633
735
|
|
634
|
-
static void
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
sprintf(buf, "----%s", utf8);
|
640
|
-
test_md_to_html(runner, buf, "<p>----" UTF8_REPL "</p>\n", msg);
|
736
|
+
static void test_incomplete_char(test_batch_runner *runner, const char *utf8,
|
737
|
+
const char *msg) {
|
738
|
+
char buf[20];
|
739
|
+
sprintf(buf, "----%s", utf8);
|
740
|
+
test_md_to_html(runner, buf, "<p>----" UTF8_REPL "</p>\n", msg);
|
641
741
|
}
|
642
742
|
|
643
|
-
static void
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
}
|
743
|
+
static void test_continuation_byte(test_batch_runner *runner,
|
744
|
+
const char *utf8) {
|
745
|
+
size_t len = strlen(utf8);
|
746
|
+
|
747
|
+
for (size_t pos = 1; pos < len; ++pos) {
|
748
|
+
char buf[20];
|
749
|
+
sprintf(buf, "((((%s))))", utf8);
|
750
|
+
buf[4 + pos] = '\x20';
|
751
|
+
|
752
|
+
char expected[50];
|
753
|
+
strcpy(expected, "<p>((((" UTF8_REPL "\x20");
|
754
|
+
for (size_t i = pos + 1; i < len; ++i) {
|
755
|
+
strcat(expected, UTF8_REPL);
|
756
|
+
}
|
757
|
+
strcat(expected, "))))</p>\n");
|
758
|
+
|
759
|
+
char *html =
|
760
|
+
cmark_markdown_to_html(buf, strlen(buf), CMARK_OPT_VALIDATE_UTF8);
|
761
|
+
STR_EQ(runner, html, expected, "invalid utf8 continuation byte %d/%d", pos,
|
762
|
+
len);
|
763
|
+
free(html);
|
764
|
+
}
|
666
765
|
}
|
667
766
|
|
668
|
-
static void
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
sizeof(no_line_ending) - 1,
|
692
|
-
CMARK_OPT_DEFAULT);
|
693
|
-
STR_EQ(runner, html, "<pre><code>line\n</code></pre>\n",
|
694
|
-
"fenced code block with no final newline");
|
695
|
-
free(html);
|
767
|
+
static void line_endings(test_batch_runner *runner) {
|
768
|
+
// Test list with different line endings
|
769
|
+
static const char list_with_endings[] = "- a\n- b\r\n- c\r- d";
|
770
|
+
char *html = cmark_markdown_to_html(
|
771
|
+
list_with_endings, sizeof(list_with_endings) - 1, CMARK_OPT_DEFAULT);
|
772
|
+
STR_EQ(runner, html,
|
773
|
+
"<ul>\n<li>a</li>\n<li>b</li>\n<li>c</li>\n<li>d</li>\n</ul>\n",
|
774
|
+
"list with different line endings");
|
775
|
+
free(html);
|
776
|
+
|
777
|
+
static const char crlf_lines[] = "line\r\nline\r\n";
|
778
|
+
html = cmark_markdown_to_html(crlf_lines, sizeof(crlf_lines) - 1,
|
779
|
+
CMARK_OPT_DEFAULT | CMARK_OPT_HARDBREAKS);
|
780
|
+
STR_EQ(runner, html, "<p>line<br />\nline</p>\n",
|
781
|
+
"crlf endings with CMARK_OPT_HARDBREAKS");
|
782
|
+
free(html);
|
783
|
+
|
784
|
+
static const char no_line_ending[] = "```\nline\n```";
|
785
|
+
html = cmark_markdown_to_html(no_line_ending, sizeof(no_line_ending) - 1,
|
786
|
+
CMARK_OPT_DEFAULT);
|
787
|
+
STR_EQ(runner, html, "<pre><code>line\n</code></pre>\n",
|
788
|
+
"fenced code block with no final newline");
|
789
|
+
free(html);
|
696
790
|
}
|
697
791
|
|
698
|
-
static void
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
test_md_to_html(runner, "A", "<p>&#x000000041;</p>\n",
|
729
|
-
"Max hexadecimal entity length");
|
792
|
+
static void numeric_entities(test_batch_runner *runner) {
|
793
|
+
test_md_to_html(runner, "�", "<p>" UTF8_REPL "</p>\n",
|
794
|
+
"Invalid numeric entity 0");
|
795
|
+
test_md_to_html(runner, "퟿", "<p>\xED\x9F\xBF</p>\n",
|
796
|
+
"Valid numeric entity 0xD7FF");
|
797
|
+
test_md_to_html(runner, "�", "<p>" UTF8_REPL "</p>\n",
|
798
|
+
"Invalid numeric entity 0xD800");
|
799
|
+
test_md_to_html(runner, "�", "<p>" UTF8_REPL "</p>\n",
|
800
|
+
"Invalid numeric entity 0xDFFF");
|
801
|
+
test_md_to_html(runner, "", "<p>\xEE\x80\x80</p>\n",
|
802
|
+
"Valid numeric entity 0xE000");
|
803
|
+
test_md_to_html(runner, "", "<p>\xF4\x8F\xBF\xBF</p>\n",
|
804
|
+
"Valid numeric entity 0x10FFFF");
|
805
|
+
test_md_to_html(runner, "�", "<p>" UTF8_REPL "</p>\n",
|
806
|
+
"Invalid numeric entity 0x110000");
|
807
|
+
test_md_to_html(runner, "�", "<p>" UTF8_REPL "</p>\n",
|
808
|
+
"Invalid numeric entity 0x80000000");
|
809
|
+
test_md_to_html(runner, "�", "<p>" UTF8_REPL "</p>\n",
|
810
|
+
"Invalid numeric entity 0xFFFFFFFF");
|
811
|
+
test_md_to_html(runner, "�", "<p>" UTF8_REPL "</p>\n",
|
812
|
+
"Invalid numeric entity 99999999");
|
813
|
+
|
814
|
+
test_md_to_html(runner, "&#;", "<p>&#;</p>\n",
|
815
|
+
"Min decimal entity length");
|
816
|
+
test_md_to_html(runner, "&#x;", "<p>&#x;</p>\n",
|
817
|
+
"Min hexadecimal entity length");
|
818
|
+
test_md_to_html(runner, "�", "<p>&#999999999;</p>\n",
|
819
|
+
"Max decimal entity length");
|
820
|
+
test_md_to_html(runner, "A", "<p>&#x000000041;</p>\n",
|
821
|
+
"Max hexadecimal entity length");
|
730
822
|
}
|
731
823
|
|
732
|
-
static void
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
824
|
+
static void test_safe(test_batch_runner *runner) {
|
825
|
+
// Test safe mode
|
826
|
+
static const char raw_html[] = "<div>\nhi\n</div>\n\n<a>hi</"
|
827
|
+
"a>\n[link](JAVAscript:alert('hi'))\n![image]("
|
828
|
+
"file:my.js)\n";
|
829
|
+
char *html = cmark_markdown_to_html(raw_html, sizeof(raw_html) - 1,
|
830
|
+
CMARK_OPT_DEFAULT | CMARK_OPT_SAFE);
|
831
|
+
STR_EQ(runner, html, "<!-- raw HTML omitted -->\n<p><!-- raw HTML omitted "
|
832
|
+
"-->hi<!-- raw HTML omitted -->\n<a "
|
833
|
+
"href=\"\">link</a>\n<img src=\"\" alt=\"image\" "
|
834
|
+
"/></p>\n",
|
835
|
+
"input with raw HTML and dangerous links");
|
836
|
+
free(html);
|
745
837
|
}
|
746
838
|
|
747
|
-
static void
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
STR_EQ(runner, html, expected_html, msg);
|
754
|
-
free(html);
|
839
|
+
static void test_md_to_html(test_batch_runner *runner, const char *markdown,
|
840
|
+
const char *expected_html, const char *msg) {
|
841
|
+
char *html = cmark_markdown_to_html(markdown, strlen(markdown),
|
842
|
+
CMARK_OPT_VALIDATE_UTF8);
|
843
|
+
STR_EQ(runner, html, expected_html, msg);
|
844
|
+
free(html);
|
755
845
|
}
|
756
846
|
|
757
847
|
int main() {
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
848
|
+
int retval;
|
849
|
+
test_batch_runner *runner = test_batch_runner_new();
|
850
|
+
|
851
|
+
version(runner);
|
852
|
+
constructor(runner);
|
853
|
+
accessors(runner);
|
854
|
+
node_check(runner);
|
855
|
+
iterator(runner);
|
856
|
+
iterator_delete(runner);
|
857
|
+
create_tree(runner);
|
858
|
+
custom_nodes(runner);
|
859
|
+
hierarchy(runner);
|
860
|
+
parser(runner);
|
861
|
+
render_html(runner);
|
862
|
+
render_xml(runner);
|
863
|
+
render_man(runner);
|
864
|
+
render_latex(runner);
|
865
|
+
render_commonmark(runner);
|
866
|
+
utf8(runner);
|
867
|
+
line_endings(runner);
|
868
|
+
numeric_entities(runner);
|
869
|
+
test_cplusplus(runner);
|
870
|
+
test_safe(runner);
|
871
|
+
|
872
|
+
test_print_summary(runner);
|
873
|
+
retval = test_ok(runner) ? 0 : 1;
|
874
|
+
free(runner);
|
875
|
+
|
876
|
+
return retval;
|
782
877
|
}
|