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.

Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +23 -17
  3. data/ext/commonmarker/cmark/CMakeLists.txt +1 -1
  4. data/ext/commonmarker/cmark/Makefile +13 -14
  5. data/ext/commonmarker/cmark/README.md +1 -0
  6. data/ext/commonmarker/cmark/api_test/cplusplus.h +1 -2
  7. data/ext/commonmarker/cmark/api_test/harness.c +60 -79
  8. data/ext/commonmarker/cmark/api_test/harness.h +13 -20
  9. data/ext/commonmarker/cmark/api_test/main.c +809 -714
  10. data/ext/commonmarker/cmark/build/CMakeCache.txt +3 -0
  11. data/ext/commonmarker/cmark/build/CMakeFiles/Makefile.cmake +0 -67
  12. data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/build.make +1 -1
  13. data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/link.txt +1 -1
  14. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/DependInfo.cmake +1 -1
  15. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/build.make +23 -23
  16. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/cmake_clean.cmake +1 -1
  17. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/link.txt +1 -1
  18. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/blocks.c.o +0 -0
  19. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/cmark.c.o +0 -0
  20. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/cmark_ctype.c.o +0 -0
  21. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/commonmark.c.o +0 -0
  22. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/html.c.o +0 -0
  23. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/inlines.c.o +0 -0
  24. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/iterator.c.o +0 -0
  25. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/latex.c.o +0 -0
  26. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/man.c.o +0 -0
  27. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/node.c.o +0 -0
  28. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/render.c.o +0 -0
  29. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/scanners.c.o +0 -0
  30. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/xml.c.o +0 -0
  31. data/ext/commonmarker/cmark/build/src/cmake_install.cmake +10 -2
  32. data/ext/commonmarker/cmark/build/src/cmark_version.h +2 -2
  33. data/ext/commonmarker/cmark/build/src/libcmark.a +0 -0
  34. data/ext/commonmarker/cmark/build/src/libcmark.pc +1 -1
  35. data/ext/commonmarker/cmark/build/testdir/CTestTestfile.cmake +1 -0
  36. data/ext/commonmarker/cmark/changelog.txt +85 -0
  37. data/ext/commonmarker/cmark/man/man3/cmark.3 +75 -34
  38. data/ext/commonmarker/cmark/src/CMakeLists.txt +13 -8
  39. data/ext/commonmarker/cmark/src/blocks.c +78 -70
  40. data/ext/commonmarker/cmark/src/chunk.h +5 -7
  41. data/ext/commonmarker/cmark/src/cmark.h +88 -34
  42. data/ext/commonmarker/cmark/src/cmark_ctype.c +6 -6
  43. data/ext/commonmarker/cmark/src/commonmark.c +24 -8
  44. data/ext/commonmarker/cmark/src/houdini_html_u.c +6 -5
  45. data/ext/commonmarker/cmark/src/html.c +33 -11
  46. data/ext/commonmarker/cmark/src/inlines.c +9 -10
  47. data/ext/commonmarker/cmark/src/iterator.c +2 -2
  48. data/ext/commonmarker/cmark/src/latex.c +54 -28
  49. data/ext/commonmarker/cmark/src/main.c +0 -9
  50. data/ext/commonmarker/cmark/src/man.c +17 -5
  51. data/ext/commonmarker/cmark/src/node.c +123 -44
  52. data/ext/commonmarker/cmark/src/node.h +8 -2
  53. data/ext/commonmarker/cmark/src/render.c +8 -1
  54. data/ext/commonmarker/cmark/src/render.h +1 -0
  55. data/ext/commonmarker/cmark/src/scanners.c +3755 -4379
  56. data/ext/commonmarker/cmark/src/scanners.h +7 -6
  57. data/ext/commonmarker/cmark/src/scanners.re +9 -10
  58. data/ext/commonmarker/cmark/src/utf8.c +6 -3
  59. data/ext/commonmarker/cmark/src/utf8.h +4 -2
  60. data/ext/commonmarker/cmark/src/xml.c +18 -4
  61. data/ext/commonmarker/cmark/test/CMakeLists.txt +11 -0
  62. data/ext/commonmarker/cmark/test/normalize.py +5 -1
  63. data/ext/commonmarker/cmark/test/roundtrip.bat +1 -0
  64. data/ext/commonmarker/cmark/test/roundtrip.sh +1 -1
  65. data/ext/commonmarker/cmark/test/spec.txt +257 -157
  66. data/ext/commonmarker/cmark/why-cmark-and-not-x.md +104 -0
  67. data/lib/commonmarker/config.rb +6 -6
  68. data/lib/commonmarker/version.rb +1 -1
  69. metadata +5 -5
  70. data/ext/commonmarker/cmark/src/bench.h +0 -27
  71. data/ext/commonmarker/cmark/wrappers/wrapper.lua +0 -239
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a66c5652272370d30158a0d782b4afc3ae20d0a7
4
- data.tar.gz: e7d00d957306b78b59474726c7b3e80fb653193b
3
+ metadata.gz: e4cd2c7505b978c3efdfbca42870636900cf44b9
4
+ data.tar.gz: dd98c9922735c153e403f8d974f3b0a594120153
5
5
  SHA512:
6
- metadata.gz: b6aad00929e06864b840e8a6fbba2c55d205fe766cab5197c7e52b4c3c072a6d290cfbdddfd3b2ada3384ba4c39154497ece240e606dd2c4983813000b6755c4
7
- data.tar.gz: dc8c33fad6c9106c312b37b33e97881dbf4b8b63aca5bbe43f6238c3525b7232370dca1326b21339cb8f27694382abad894f4be18785dcb70447ca3834b6d0b8
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 table below.
121
-
122
- | Name | Description | Type |
123
- |-------|--------------|-------|
124
- | `:default` | The default rendering system. | Both `parse` and `render`.
125
- | `:sourcepos` | Include source position in rendered HTML. | `render`
126
- | `:hardbreaks` | Treat `\n` as hardbreaks (by adding `<br/>`). | `render`
127
- | `:normalize` | Attempt to normalize the HTML. | `parse`
128
- | `:smart` | Use smart punctuation (curly quotes, etc.). | `parse`
129
- | `:validate_utf8` | Replace illegal sequences with the replacement character `U+FFFD`. | `parse`
130
- | `:safe` | Suppress raw HTML and unsafe links. | `render`
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
- require 'commonmarker'
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
- require 'commonmarker'
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 22)
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 spec leakcheck clean fuzztest dingus upload test update-site upload-site debug ubsan asan mingw archive bench format update-spec afl clang-check
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
- $(BENCHDIR)/benchinput.md: progit
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
- cat progit/$$lang/*/*.markdown >> $@; \
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
- { sudo renice -10 $$$$; \
165
- for x in `seq 1 $(NUMRUNS)` ; do \
166
- /usr/bin/env time -p $(PROG) </dev/null >/dev/null ; \
167
- /usr/bin/env time -p $(PROG) $< >/dev/null ; \
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 $< < $(BENCHINP) > /dev/null
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
 
@@ -7,8 +7,7 @@
7
7
  extern "C" {
8
8
  #endif
9
9
 
10
- void
11
- test_cplusplus(test_batch_runner *runner);
10
+ void test_cplusplus(test_batch_runner *runner);
12
11
 
13
12
  #ifdef __cplusplus
14
13
  }
@@ -5,98 +5,79 @@
5
5
 
6
6
  #include "harness.h"
7
7
 
8
- test_batch_runner*
9
- test_batch_runner_new()
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
- test_result(test_batch_runner *runner, int cond, const char *msg, va_list ap)
16
- {
17
- ++runner->test_num;
18
-
19
- if (cond) {
20
- ++runner->num_passed;
21
- }
22
- else {
23
- fprintf(stderr, "FAILED test %d: ", runner->test_num);
24
- vfprintf(stderr, msg, ap);
25
- fprintf(stderr, "\n");
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
- SKIP(test_batch_runner *runner, int num_tests)
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
- OK(test_batch_runner *runner, int cond, const char *msg, ...)
39
- {
40
- va_list ap;
41
- va_start(ap, msg);
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
- INT_EQ(test_batch_runner *runner, int got, int expected, const char *msg, ...)
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
- va_list ap;
52
- va_start(ap, msg);
53
- test_result(runner, cond, msg, ap);
54
- va_end(ap);
42
+ va_list ap;
43
+ va_start(ap, msg);
44
+ test_result(runner, cond, msg, ap);
45
+ va_end(ap);
55
46
 
56
- if (!cond) {
57
- fprintf(stderr, " Got: %d\n", got);
58
- fprintf(stderr, " Expected: %d\n", expected);
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
- STR_EQ(test_batch_runner *runner, const char *got, const char *expected,
64
- const char *msg, ...)
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
- int
80
- test_ok(test_batch_runner *runner)
81
- {
82
- return runner->num_failed == 0;
83
- }
57
+ va_list ap;
58
+ va_start(ap, msg);
59
+ test_result(runner, cond, msg, ap);
60
+ va_end(ap);
84
61
 
85
- void
86
- test_print_summary(test_batch_runner *runner)
87
- {
88
- int num_passed = runner->num_passed;
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
- int test_num;
10
- int num_passed;
11
- int num_failed;
12
- int num_skipped;
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
- INT_EQ(test_batch_runner *runner, int got, int expected, const char *msg, ...);
21
+ void INT_EQ(test_batch_runner *runner, int got, int expected, const char *msg,
22
+ ...);
26
23
 
27
- void
28
- STR_EQ(test_batch_runner *runner, const char *got, const char *expected,
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
- CMARK_NODE_DOCUMENT,
16
- CMARK_NODE_BLOCK_QUOTE,
17
- CMARK_NODE_LIST,
18
- CMARK_NODE_ITEM,
19
- CMARK_NODE_CODE_BLOCK,
20
- CMARK_NODE_HTML,
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
- test_md_to_html(test_batch_runner *runner, const char *markdown,
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
- test_content(test_batch_runner *runner, cmark_node_type type,
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
- test_char(test_batch_runner *runner, int valid, const char *utf8,
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
- test_incomplete_char(test_batch_runner *runner, const char *utf8,
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
- version(test_batch_runner *runner)
57
- {
58
- INT_EQ(runner, cmark_version(), CMARK_VERSION, "cmark_version");
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
- constructor(test_batch_runner *runner)
65
- {
66
- for (int i = 0; i < num_node_types; ++i) {
67
- cmark_node_type type = node_types[i];
68
- cmark_node *node = cmark_node_new(type);
69
- OK(runner, node != NULL, "new type %d", type);
70
- INT_EQ(runner, cmark_node_get_type(node), type,
71
- "get_type %d", type);
72
-
73
- switch (node->type) {
74
- case CMARK_NODE_HEADER:
75
- INT_EQ(runner, cmark_node_get_header_level(node), 1,
76
- "default header level is 1");
77
- node->as.header.level = 1;
78
- break;
79
-
80
- case CMARK_NODE_LIST:
81
- INT_EQ(runner, cmark_node_get_list_type(node),
82
- CMARK_BULLET_LIST,
83
- "default is list type is bullet");
84
- INT_EQ(runner, cmark_node_get_list_delim(node),
85
- CMARK_NO_DELIM,
86
- "default is list delim is NO_DELIM");
87
- INT_EQ(runner, cmark_node_get_list_start(node), 1,
88
- "default is list start is 1");
89
- INT_EQ(runner, cmark_node_get_list_tight(node), 0,
90
- "default is list is loose");
91
- break;
92
-
93
- default:
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
- accessors(test_batch_runner *runner)
103
- {
104
- static const char markdown[] =
105
- "## Header\n"
106
- "\n"
107
- "* Item 1\n"
108
- "* Item 2\n"
109
- "\n"
110
- "2. Item 1\n"
111
- "\n"
112
- "3. Item 2\n"
113
- "\n"
114
- "\n"
115
- " code\n"
116
- "\n"
117
- "``` lang\n"
118
- "fenced\n"
119
- "```\n"
120
- "\n"
121
- "<div>html</div>\n"
122
- "\n"
123
- "[link](url 'title')\n";
124
-
125
- cmark_node *doc = cmark_parse_document(markdown, sizeof(markdown) - 1, CMARK_OPT_DEFAULT);
126
-
127
- // Getters
128
-
129
- cmark_node *header = cmark_node_first_child(doc);
130
- INT_EQ(runner, cmark_node_get_header_level(header), 2,
131
- "get_header_level");
132
-
133
- cmark_node *bullet_list = cmark_node_next(header);
134
- INT_EQ(runner, cmark_node_get_list_type(bullet_list),
135
- CMARK_BULLET_LIST, "get_list_type bullet");
136
- INT_EQ(runner, cmark_node_get_list_tight(bullet_list), 1,
137
- "get_list_tight tight");
138
-
139
- cmark_node *ordered_list = cmark_node_next(bullet_list);
140
- INT_EQ(runner, cmark_node_get_list_type(ordered_list),
141
- CMARK_ORDERED_LIST, "get_list_type ordered");
142
- INT_EQ(runner, cmark_node_get_list_delim(ordered_list),
143
- CMARK_PERIOD_DELIM, "get_list_delim ordered");
144
- INT_EQ(runner, cmark_node_get_list_start(ordered_list), 2,
145
- "get_list_start");
146
- INT_EQ(runner, cmark_node_get_list_tight(ordered_list), 0,
147
- "get_list_tight loose");
148
-
149
- cmark_node *code = cmark_node_next(ordered_list);
150
- STR_EQ(runner, cmark_node_get_literal(code), "code\n",
151
- "get_literal indented code");
152
-
153
- cmark_node *fenced = cmark_node_next(code);
154
- STR_EQ(runner, cmark_node_get_literal(fenced), "fenced\n",
155
- "get_literal fenced code");
156
- STR_EQ(runner, cmark_node_get_fence_info(fenced), "lang",
157
- "get_fence_info");
158
-
159
- cmark_node *html = cmark_node_next(fenced);
160
- STR_EQ(runner, cmark_node_get_literal(html),
161
- "<div>html</div>\n", "get_literal html");
162
-
163
- cmark_node *paragraph = cmark_node_next(html);
164
- INT_EQ(runner, cmark_node_get_start_line(paragraph), 19,
165
- "get_start_line");
166
- INT_EQ(runner, cmark_node_get_start_column(paragraph), 1,
167
- "get_start_column");
168
- INT_EQ(runner, cmark_node_get_end_line(paragraph), 19,
169
- "get_end_line");
170
-
171
- cmark_node *link = cmark_node_first_child(paragraph);
172
- STR_EQ(runner, cmark_node_get_url(link), "url",
173
- "get_url");
174
- STR_EQ(runner, cmark_node_get_title(link), "title",
175
- "get_title");
176
-
177
- cmark_node *string = cmark_node_first_child(link);
178
- STR_EQ(runner, cmark_node_get_literal(string), "link",
179
- "get_literal string");
180
-
181
- // Setters
182
-
183
- OK(runner, cmark_node_set_header_level(header, 3),
184
- "set_header_level");
185
-
186
- OK(runner, cmark_node_set_list_type(bullet_list, CMARK_ORDERED_LIST),
187
- "set_list_type ordered");
188
- OK(runner, cmark_node_set_list_delim(bullet_list, CMARK_PAREN_DELIM),
189
- "set_list_delim paren");
190
- OK(runner, cmark_node_set_list_start(bullet_list, 3),
191
- "set_list_start");
192
- OK(runner, cmark_node_set_list_tight(bullet_list, 0),
193
- "set_list_tight loose");
194
-
195
- OK(runner, cmark_node_set_list_type(ordered_list, CMARK_BULLET_LIST),
196
- "set_list_type bullet");
197
- OK(runner, cmark_node_set_list_tight(ordered_list, 1),
198
- "set_list_tight tight");
199
-
200
- OK(runner, cmark_node_set_literal(code, "CODE\n"),
201
- "set_literal indented code");
202
-
203
- OK(runner, cmark_node_set_literal(fenced, "FENCED\n"),
204
- "set_literal fenced code");
205
- OK(runner, cmark_node_set_fence_info(fenced, "LANG"),
206
- "set_fence_info");
207
-
208
- OK(runner, cmark_node_set_literal(html, "<div>HTML</div>\n"),
209
- "set_literal html");
210
-
211
- OK(runner, cmark_node_set_url(link, "URL"),
212
- "set_url");
213
- OK(runner, cmark_node_set_title(link, "TITLE"),
214
- "set_title");
215
-
216
- OK(runner, cmark_node_set_literal(string, "LINK"),
217
- "set_literal string");
218
-
219
- char *rendered_html = cmark_render_html(doc, CMARK_OPT_DEFAULT);
220
- static const char expected_html[] =
221
- "<h3>Header</h3>\n"
222
- "<ol start=\"3\">\n"
223
- "<li>\n"
224
- "<p>Item 1</p>\n"
225
- "</li>\n"
226
- "<li>\n"
227
- "<p>Item 2</p>\n"
228
- "</li>\n"
229
- "</ol>\n"
230
- "<ul>\n"
231
- "<li>Item 1</li>\n"
232
- "<li>Item 2</li>\n"
233
- "</ul>\n"
234
- "<pre><code>CODE\n"
235
- "</code></pre>\n"
236
- "<pre><code class=\"language-LANG\">FENCED\n"
237
- "</code></pre>\n"
238
- "<div>HTML</div>\n"
239
- "<p><a href=\"URL\" title=\"TITLE\">LINK</a></p>\n";
240
- STR_EQ(runner, rendered_html, expected_html, "setters work");
241
- free(rendered_html);
242
-
243
- // Getter errors
244
-
245
- INT_EQ(runner, cmark_node_get_header_level(bullet_list), 0,
246
- "get_header_level error");
247
- INT_EQ(runner, cmark_node_get_list_type(header), CMARK_NO_LIST,
248
- "get_list_type error");
249
- INT_EQ(runner, cmark_node_get_list_start(code), 0,
250
- "get_list_start error");
251
- INT_EQ(runner, cmark_node_get_list_tight(fenced), 0,
252
- "get_list_tight error");
253
- OK(runner, cmark_node_get_literal(ordered_list) == NULL,
254
- "get_literal error");
255
- OK(runner, cmark_node_get_fence_info(paragraph) == NULL,
256
- "get_fence_info error");
257
- OK(runner, cmark_node_get_url(html) == NULL,
258
- "get_url error");
259
- OK(runner, cmark_node_get_title(header) == NULL,
260
- "get_title error");
261
-
262
- // Setter errors
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
- node_check(test_batch_runner *runner) {
295
- // Construct an incomplete tree.
296
- cmark_node *doc = cmark_node_new(CMARK_NODE_DOCUMENT);
297
- cmark_node *p1 = cmark_node_new(CMARK_NODE_PARAGRAPH);
298
- cmark_node *p2 = cmark_node_new(CMARK_NODE_PARAGRAPH);
299
- doc->first_child = p1;
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
- INT_EQ(runner, cmark_node_check(doc, NULL), 4, "node_check works");
303
- INT_EQ(runner, cmark_node_check(doc, NULL), 0,
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
- cmark_node_free(doc);
252
+ cmark_node_free(doc);
307
253
  }
308
254
 
309
- static void
310
- iterator(test_batch_runner *runner) {
311
- cmark_node *doc = cmark_parse_document("> a *b*\n\nc", 10, CMARK_OPT_DEFAULT);
312
- int parnodes = 0;
313
- cmark_event_type ev_type;
314
- cmark_iter *iter = cmark_iter_new(doc);
315
- cmark_node *cur;
316
-
317
- while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) {
318
- cur = cmark_iter_get_node(iter);
319
- if (cur->type == CMARK_NODE_PARAGRAPH &&
320
- ev_type == CMARK_EVENT_ENTER) {
321
- parnodes += 1;
322
- }
323
- }
324
- INT_EQ(runner, parnodes, 2, "iterate correctly counts paragraphs");
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
- iterator_delete(test_batch_runner *runner) {
332
- static const char md[] =
333
- "a *b* c\n"
334
- "\n"
335
- "* item1\n"
336
- "* item2\n"
337
- "\n"
338
- "a `b` c\n"
339
- "\n"
340
- "* item1\n"
341
- "* item2\n";
342
- cmark_node *doc = cmark_parse_document(md, sizeof(md) - 1,
343
- CMARK_OPT_DEFAULT);
344
- cmark_iter *iter = cmark_iter_new(doc);
345
- cmark_event_type ev_type;
346
-
347
- while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) {
348
- cmark_node *node = cmark_iter_get_node(iter);
349
- // Delete list, emph, and code nodes.
350
- if ((ev_type == CMARK_EVENT_EXIT &&
351
- node->type == CMARK_NODE_LIST) ||
352
- (ev_type == CMARK_EVENT_EXIT &&
353
- node->type == CMARK_NODE_EMPH) ||
354
- (ev_type == CMARK_EVENT_ENTER &&
355
- node->type == CMARK_NODE_CODE)) {
356
- cmark_node_free(node);
357
- }
358
- }
359
-
360
- char *html = cmark_render_html(doc, CMARK_OPT_DEFAULT);
361
- static const char expected[] =
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
- create_tree(test_batch_runner *runner)
373
- {
374
- char *html;
375
- cmark_node *doc = cmark_node_new(CMARK_NODE_DOCUMENT);
376
-
377
- cmark_node *p = cmark_node_new(CMARK_NODE_PARAGRAPH);
378
- OK(runner, !cmark_node_insert_before(doc, p),
379
- "insert before root fails");
380
- OK(runner, !cmark_node_insert_after(doc, p),
381
- "insert after root fails");
382
- OK(runner, cmark_node_append_child(doc, p), "append1");
383
- INT_EQ(runner, cmark_node_check(doc, NULL), 0, "append1 consistent");
384
- OK(runner, cmark_node_parent(p) == doc, "node_parent");
385
-
386
- cmark_node *emph = cmark_node_new(CMARK_NODE_EMPH);
387
- OK(runner, cmark_node_prepend_child(p, emph), "prepend1");
388
- INT_EQ(runner, cmark_node_check(doc, NULL), 0, "prepend1 consistent");
389
-
390
- cmark_node *str1 = cmark_node_new(CMARK_NODE_TEXT);
391
- cmark_node_set_literal(str1, "Hello, ");
392
- OK(runner, cmark_node_prepend_child(p, str1), "prepend2");
393
- INT_EQ(runner, cmark_node_check(doc, NULL), 0, "prepend2 consistent");
394
-
395
- cmark_node *str3 = cmark_node_new(CMARK_NODE_TEXT);
396
- cmark_node_set_literal(str3, "!");
397
- OK(runner, cmark_node_append_child(p, str3), "append2");
398
- INT_EQ(runner, cmark_node_check(doc, NULL), 0, "append2 consistent");
399
-
400
- cmark_node *str2 = cmark_node_new(CMARK_NODE_TEXT);
401
- cmark_node_set_literal(str2, "world");
402
- OK(runner, cmark_node_append_child(emph, str2), "append3");
403
- INT_EQ(runner, cmark_node_check(doc, NULL), 0, "append3 consistent");
404
-
405
- html = cmark_render_html(doc, CMARK_OPT_DEFAULT);
406
- STR_EQ(runner, html, "<p>Hello, <em>world</em>!</p>\n",
407
- "render_html");
408
- free(html);
409
-
410
- OK(runner, cmark_node_insert_before(str1, str3), "ins before1");
411
- INT_EQ(runner, cmark_node_check(doc, NULL), 0,
412
- "ins before1 consistent");
413
- // 31e
414
- OK(runner, cmark_node_first_child(p) == str3, "ins before1 works");
415
-
416
- OK(runner, cmark_node_insert_before(str1, emph), "ins before2");
417
- INT_EQ(runner, cmark_node_check(doc, NULL), 0,
418
- "ins before2 consistent");
419
- // 3e1
420
- OK(runner, cmark_node_last_child(p) == str1, "ins before2 works");
421
-
422
- OK(runner, cmark_node_insert_after(str1, str3), "ins after1");
423
- INT_EQ(runner, cmark_node_check(doc, NULL), 0,
424
- "ins after1 consistent");
425
- // e13
426
- OK(runner, cmark_node_next(str1) == str3, "ins after1 works");
427
-
428
- OK(runner, cmark_node_insert_after(str1, emph), "ins after2");
429
- INT_EQ(runner, cmark_node_check(doc, NULL), 0,
430
- "ins after2 consistent");
431
- // 1e3
432
- OK(runner, cmark_node_previous(emph) == str1, "ins after2 works");
433
-
434
- cmark_node_unlink(emph);
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
- hierarchy(test_batch_runner *runner)
450
- {
451
- cmark_node *bquote1 = cmark_node_new(CMARK_NODE_BLOCK_QUOTE);
452
- cmark_node *bquote2 = cmark_node_new(CMARK_NODE_BLOCK_QUOTE);
453
- cmark_node *bquote3 = cmark_node_new(CMARK_NODE_BLOCK_QUOTE);
454
-
455
- OK(runner, cmark_node_append_child(bquote1, bquote2),
456
- "append bquote2");
457
- OK(runner, cmark_node_append_child(bquote2, bquote3),
458
- "append bquote3");
459
- OK(runner, !cmark_node_append_child(bquote3, bquote3),
460
- "adding a node as child of itself fails");
461
- OK(runner, !cmark_node_append_child(bquote3, bquote1),
462
- "adding a parent as child fails");
463
-
464
- cmark_node_free(bquote1);
465
-
466
- int max_node_type = CMARK_NODE_LAST_BLOCK > CMARK_NODE_LAST_INLINE
467
- ? CMARK_NODE_LAST_BLOCK : CMARK_NODE_LAST_INLINE;
468
- OK(runner, max_node_type < 32, "all node types < 32");
469
-
470
- int list_item_flag = 1 << CMARK_NODE_ITEM;
471
- int top_level_blocks =
472
- (1 << CMARK_NODE_BLOCK_QUOTE) |
473
- (1 << CMARK_NODE_LIST) |
474
- (1 << CMARK_NODE_CODE_BLOCK) |
475
- (1 << CMARK_NODE_HTML) |
476
- (1 << CMARK_NODE_PARAGRAPH) |
477
- (1 << CMARK_NODE_HEADER) |
478
- (1 << CMARK_NODE_HRULE);
479
- int all_inlines =
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
- static void
511
- test_content(test_batch_runner *runner, cmark_node_type type,
512
- int allowed_content)
513
- {
514
- cmark_node *node = cmark_node_new(type);
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
- for (int i = 0; i < num_node_types; ++i) {
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
- int got = cmark_node_append_child(node, child);
521
- int expected = (allowed_content >> child_type) & 1;
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
- INT_EQ(runner, got, expected,
524
- "add %d as child of %d", child_type, type);
484
+ static void render_html(test_batch_runner *runner) {
485
+ char *html;
525
486
 
526
- cmark_node_free(child);
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
- cmark_node_free(node);
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
- parser(test_batch_runner *runner)
534
- {
535
- test_md_to_html(runner, "No newline", "<p>No newline</p>\n",
536
- "document without trailing newline");
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
- render_html(test_batch_runner *runner)
541
- {
542
- char *html;
543
-
544
- static const char markdown[] =
545
- "foo *bar*\n"
546
- "\n"
547
- "paragraph 2\n";
548
- cmark_node *doc = cmark_parse_document(markdown, sizeof(markdown) - 1,
549
- CMARK_OPT_DEFAULT);
550
-
551
- cmark_node *paragraph = cmark_node_first_child(doc);
552
- html = cmark_render_html(paragraph, CMARK_OPT_DEFAULT);
553
- STR_EQ(runner, html, "<p>foo <em>bar</em></p>\n",
554
- "render single paragraph");
555
- free(html);
556
-
557
- cmark_node *string = cmark_node_first_child(paragraph);
558
- html = cmark_render_html(string, CMARK_OPT_DEFAULT);
559
- STR_EQ(runner, html, "foo ", "render single inline");
560
- free(html);
561
-
562
- cmark_node *emph = cmark_node_next(string);
563
- html = cmark_render_html(emph, CMARK_OPT_DEFAULT);
564
- STR_EQ(runner, html, "<em>bar</em>", "render inline with children");
565
- free(html);
566
-
567
- cmark_node_free(doc);
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
- utf8(test_batch_runner *runner)
572
- {
573
- // Ranges
574
- test_char(runner, 1, "\x01", "valid utf8 01");
575
- test_char(runner, 1, "\x7F", "valid utf8 7F");
576
- test_char(runner, 0, "\x80", "invalid utf8 80");
577
- test_char(runner, 0, "\xBF", "invalid utf8 BF");
578
- test_char(runner, 0, "\xC0\x80", "invalid utf8 C080");
579
- test_char(runner, 0, "\xC1\xBF", "invalid utf8 C1BF");
580
- test_char(runner, 1, "\xC2\x80", "valid utf8 C280");
581
- test_char(runner, 1, "\xDF\xBF", "valid utf8 DFBF");
582
- test_char(runner, 0, "\xE0\x80\x80", "invalid utf8 E08080");
583
- test_char(runner, 0, "\xE0\x9F\xBF", "invalid utf8 E09FBF");
584
- test_char(runner, 1, "\xE0\xA0\x80", "valid utf8 E0A080");
585
- test_char(runner, 1, "\xED\x9F\xBF", "valid utf8 ED9FBF");
586
- test_char(runner, 0, "\xED\xA0\x80", "invalid utf8 EDA080");
587
- test_char(runner, 0, "\xED\xBF\xBF", "invalid utf8 EDBFBF");
588
- test_char(runner, 0, "\xF0\x80\x80\x80", "invalid utf8 F0808080");
589
- test_char(runner, 0, "\xF0\x8F\xBF\xBF", "invalid utf8 F08FBFBF");
590
- test_char(runner, 1, "\xF0\x90\x80\x80", "valid utf8 F0908080");
591
- test_char(runner, 1, "\xF4\x8F\xBF\xBF", "valid utf8 F48FBFBF");
592
- test_char(runner, 0, "\xF4\x90\x80\x80", "invalid utf8 F4908080");
593
- test_char(runner, 0, "\xF7\xBF\xBF\xBF", "invalid utf8 F7BFBFBF");
594
- test_char(runner, 0, "\xF8", "invalid utf8 F8");
595
- test_char(runner, 0, "\xFF", "invalid utf8 FF");
596
-
597
- // Incomplete byte sequences at end of input
598
- test_incomplete_char(runner, "\xE0\xA0", "invalid utf8 E0A0");
599
- test_incomplete_char(runner, "\xF0\x90\x80", "invalid utf8 F09080");
600
-
601
- // Invalid continuation bytes
602
- test_continuation_byte(runner, "\xC2\x80");
603
- test_continuation_byte(runner, "\xE0\xA0\x80");
604
- test_continuation_byte(runner, "\xF0\x90\x80\x80");
605
-
606
- // Test string containing null character
607
- static const char string_with_null[] = "((((\0))))";
608
- char *html = cmark_markdown_to_html(string_with_null,
609
- sizeof(string_with_null) - 1,
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
- test_char(test_batch_runner *runner, int valid, const char *utf8,
618
- const char *msg)
619
- {
620
- char buf[20];
621
- sprintf(buf, "((((%s))))", utf8);
622
-
623
- if (valid) {
624
- char expected[30];
625
- sprintf(expected, "<p>((((%s))))</p>\n", utf8);
626
- test_md_to_html(runner, buf, expected, msg);
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
- test_incomplete_char(test_batch_runner *runner, const char *utf8,
636
- const char *msg)
637
- {
638
- char buf[20];
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
- test_continuation_byte(test_batch_runner *runner, const char *utf8)
645
- {
646
- size_t len = strlen(utf8);
647
-
648
- for (size_t pos = 1; pos < len; ++pos) {
649
- char buf[20];
650
- sprintf(buf, "((((%s))))", utf8);
651
- buf[4+pos] = '\x20';
652
-
653
- char expected[50];
654
- strcpy(expected, "<p>((((" UTF8_REPL "\x20");
655
- for (size_t i = pos + 1; i < len; ++i) {
656
- strcat(expected, UTF8_REPL);
657
- }
658
- strcat(expected, "))))</p>\n");
659
-
660
- char *html = cmark_markdown_to_html(buf, strlen(buf),
661
- CMARK_OPT_VALIDATE_UTF8);
662
- STR_EQ(runner, html, expected,
663
- "invalid utf8 continuation byte %d/%d", pos, len);
664
- free(html);
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
- line_endings(test_batch_runner *runner)
670
- {
671
- // Test list with different line endings
672
- static const char list_with_endings[] =
673
- "- a\n- b\r\n- c\r- d";
674
- char *html = cmark_markdown_to_html(list_with_endings,
675
- sizeof(list_with_endings) - 1,
676
- CMARK_OPT_DEFAULT);
677
- STR_EQ(runner, html, "<ul>\n<li>a</li>\n<li>b</li>\n<li>c</li>\n<li>d</li>\n</ul>\n",
678
- "list with different line endings");
679
- free(html);
680
-
681
- static const char crlf_lines[] = "line\r\nline\r\n";
682
- html = cmark_markdown_to_html(crlf_lines,
683
- sizeof(crlf_lines) - 1,
684
- CMARK_OPT_DEFAULT | CMARK_OPT_HARDBREAKS);
685
- STR_EQ(runner, html, "<p>line<br />\nline</p>\n",
686
- "crlf endings with CMARK_OPT_HARDBREAKS");
687
- free(html);
688
-
689
- static const char no_line_ending[] = "```\nline\n```";
690
- html = cmark_markdown_to_html(no_line_ending,
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
- numeric_entities(test_batch_runner *runner)
700
- {
701
- test_md_to_html(runner, "&#0;", "<p>" UTF8_REPL "</p>\n",
702
- "Invalid numeric entity 0");
703
- test_md_to_html(runner, "&#55295;", "<p>\xED\x9F\xBF</p>\n",
704
- "Valid numeric entity 0xD7FF");
705
- test_md_to_html(runner, "&#xD800;", "<p>" UTF8_REPL "</p>\n",
706
- "Invalid numeric entity 0xD800");
707
- test_md_to_html(runner, "&#xDFFF;", "<p>" UTF8_REPL "</p>\n",
708
- "Invalid numeric entity 0xDFFF");
709
- test_md_to_html(runner, "&#57344;", "<p>\xEE\x80\x80</p>\n",
710
- "Valid numeric entity 0xE000");
711
- test_md_to_html(runner, "&#x10FFFF;", "<p>\xF4\x8F\xBF\xBF</p>\n",
712
- "Valid numeric entity 0x10FFFF");
713
- test_md_to_html(runner, "&#x110000;", "<p>" UTF8_REPL "</p>\n",
714
- "Invalid numeric entity 0x110000");
715
- test_md_to_html(runner, "&#x80000000;", "<p>" UTF8_REPL "</p>\n",
716
- "Invalid numeric entity 0x80000000");
717
- test_md_to_html(runner, "&#xFFFFFFFF;", "<p>" UTF8_REPL "</p>\n",
718
- "Invalid numeric entity 0xFFFFFFFF");
719
- test_md_to_html(runner, "&#99999999;", "<p>" UTF8_REPL "</p>\n",
720
- "Invalid numeric entity 99999999");
721
-
722
- test_md_to_html(runner, "&#;", "<p>&amp;#;</p>\n",
723
- "Min decimal entity length");
724
- test_md_to_html(runner, "&#x;", "<p>&amp;#x;</p>\n",
725
- "Min hexadecimal entity length");
726
- test_md_to_html(runner, "&#999999999;", "<p>&amp;#999999999;</p>\n",
727
- "Max decimal entity length");
728
- test_md_to_html(runner, "&#x000000041;", "<p>&amp;#x000000041;</p>\n",
729
- "Max hexadecimal entity length");
792
+ static void numeric_entities(test_batch_runner *runner) {
793
+ test_md_to_html(runner, "&#0;", "<p>" UTF8_REPL "</p>\n",
794
+ "Invalid numeric entity 0");
795
+ test_md_to_html(runner, "&#55295;", "<p>\xED\x9F\xBF</p>\n",
796
+ "Valid numeric entity 0xD7FF");
797
+ test_md_to_html(runner, "&#xD800;", "<p>" UTF8_REPL "</p>\n",
798
+ "Invalid numeric entity 0xD800");
799
+ test_md_to_html(runner, "&#xDFFF;", "<p>" UTF8_REPL "</p>\n",
800
+ "Invalid numeric entity 0xDFFF");
801
+ test_md_to_html(runner, "&#57344;", "<p>\xEE\x80\x80</p>\n",
802
+ "Valid numeric entity 0xE000");
803
+ test_md_to_html(runner, "&#x10FFFF;", "<p>\xF4\x8F\xBF\xBF</p>\n",
804
+ "Valid numeric entity 0x10FFFF");
805
+ test_md_to_html(runner, "&#x110000;", "<p>" UTF8_REPL "</p>\n",
806
+ "Invalid numeric entity 0x110000");
807
+ test_md_to_html(runner, "&#x80000000;", "<p>" UTF8_REPL "</p>\n",
808
+ "Invalid numeric entity 0x80000000");
809
+ test_md_to_html(runner, "&#xFFFFFFFF;", "<p>" UTF8_REPL "</p>\n",
810
+ "Invalid numeric entity 0xFFFFFFFF");
811
+ test_md_to_html(runner, "&#99999999;", "<p>" UTF8_REPL "</p>\n",
812
+ "Invalid numeric entity 99999999");
813
+
814
+ test_md_to_html(runner, "&#;", "<p>&amp;#;</p>\n",
815
+ "Min decimal entity length");
816
+ test_md_to_html(runner, "&#x;", "<p>&amp;#x;</p>\n",
817
+ "Min hexadecimal entity length");
818
+ test_md_to_html(runner, "&#999999999;", "<p>&amp;#999999999;</p>\n",
819
+ "Max decimal entity length");
820
+ test_md_to_html(runner, "&#x000000041;", "<p>&amp;#x000000041;</p>\n",
821
+ "Max hexadecimal entity length");
730
822
  }
731
823
 
732
- static void
733
- test_safe(test_batch_runner *runner)
734
- {
735
- // Test safe mode
736
- static const char raw_html[] =
737
- "<div>\nhi\n</div>\n\n<a>hi</a>\n[link](JAVAscript:alert('hi'))\n![image](file:my.js)\n";
738
- char *html = cmark_markdown_to_html(raw_html,
739
- sizeof(raw_html) - 1,
740
- CMARK_OPT_DEFAULT |
741
- CMARK_OPT_SAFE);
742
- STR_EQ(runner, html, "<!-- raw HTML omitted -->\n<p><!-- raw HTML omitted -->hi<!-- raw HTML omitted -->\n<a href=\"\">link</a>\n<img src=\"\" alt=\"image\" /></p>\n",
743
- "input with raw HTML and dangerous links");
744
- free(html);
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
- test_md_to_html(test_batch_runner *runner, const char *markdown,
749
- const char *expected_html, const char *msg)
750
- {
751
- char *html = cmark_markdown_to_html(markdown, strlen(markdown),
752
- CMARK_OPT_VALIDATE_UTF8);
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
- int retval;
759
- test_batch_runner *runner = test_batch_runner_new();
760
-
761
- version(runner);
762
- constructor(runner);
763
- accessors(runner);
764
- node_check(runner);
765
- iterator(runner);
766
- iterator_delete(runner);
767
- create_tree(runner);
768
- hierarchy(runner);
769
- parser(runner);
770
- render_html(runner);
771
- utf8(runner);
772
- line_endings(runner);
773
- numeric_entities(runner);
774
- test_cplusplus(runner);
775
- test_safe(runner);
776
-
777
- test_print_summary(runner);
778
- retval = test_ok(runner) ? 0 : 1;
779
- free(runner);
780
-
781
- return retval;
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
  }