commonmarker 0.10.0 → 0.11.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 (161) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +3 -0
  3. data/bin/commonmarker +19 -3
  4. data/ext/commonmarker/cmark/CMakeLists.txt +1 -0
  5. data/ext/commonmarker/cmark/COPYING +2 -24
  6. data/ext/commonmarker/cmark/Makefile +25 -5
  7. data/ext/commonmarker/cmark/README.md +1 -1
  8. data/ext/commonmarker/cmark/api_test/CMakeLists.txt +1 -1
  9. data/ext/commonmarker/cmark/api_test/main.c +25 -27
  10. data/ext/commonmarker/cmark/build/CMakeCache.txt +12 -9
  11. data/ext/commonmarker/cmark/build/CMakeFiles/{3.6.0 → 3.6.1}/CMakeCCompiler.cmake +0 -0
  12. data/ext/commonmarker/cmark/build/CMakeFiles/{3.6.0 → 3.6.1}/CMakeCXXCompiler.cmake +0 -0
  13. data/ext/commonmarker/cmark/build/CMakeFiles/{3.6.0 → 3.6.1}/CMakeDetermineCompilerABI_C.bin +0 -0
  14. data/ext/commonmarker/cmark/build/CMakeFiles/{3.6.0 → 3.6.1}/CMakeDetermineCompilerABI_CXX.bin +0 -0
  15. data/ext/commonmarker/cmark/build/CMakeFiles/{3.6.0 → 3.6.1}/CMakeSystem.cmake +4 -4
  16. data/ext/commonmarker/cmark/build/CMakeFiles/{3.6.0 → 3.6.1}/CompilerIdC/CMakeCCompilerId.c +0 -0
  17. data/ext/commonmarker/cmark/build/CMakeFiles/{3.6.0 → 3.6.1}/CompilerIdC/a.out +0 -0
  18. data/ext/commonmarker/cmark/build/CMakeFiles/{3.6.0 → 3.6.1}/CompilerIdCXX/CMakeCXXCompilerId.cpp +0 -0
  19. data/ext/commonmarker/cmark/build/CMakeFiles/{3.6.0 → 3.6.1}/CompilerIdCXX/a.out +0 -0
  20. data/ext/commonmarker/cmark/build/CMakeFiles/CMakeError.log +6 -6
  21. data/ext/commonmarker/cmark/build/CMakeFiles/CMakeOutput.log +148 -148
  22. data/ext/commonmarker/cmark/build/CMakeFiles/Makefile.cmake +41 -109
  23. data/ext/commonmarker/cmark/build/CMakeFiles/Makefile2 +66 -10
  24. data/ext/commonmarker/cmark/build/CMakeFiles/TargetDirectories.txt +8 -0
  25. data/ext/commonmarker/cmark/build/CMakeFiles/progress.marks +1 -1
  26. data/ext/commonmarker/cmark/build/CTestTestfile.cmake +1 -0
  27. data/ext/commonmarker/cmark/build/Makefile +23 -9
  28. data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/build.make +2 -2
  29. data/ext/commonmarker/cmark/build/api_test/CMakeFiles/progress.marks +1 -1
  30. data/ext/commonmarker/cmark/build/api_test/Makefile +9 -9
  31. data/ext/commonmarker/cmark/build/cmake_install.cmake +1 -0
  32. data/ext/commonmarker/cmark/build/extensions/CMakeFiles/CMakeDirectoryInformation.cmake +16 -0
  33. data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmarkextensions_static.dir/C.includecache +190 -0
  34. data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmarkextensions_static.dir/DependInfo.cmake +29 -0
  35. data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmarkextensions_static.dir/autolink.c.o +0 -0
  36. data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmarkextensions_static.dir/build.make +249 -0
  37. data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmarkextensions_static.dir/cmake_clean.cmake +15 -0
  38. data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmarkextensions_static.dir/cmake_clean_target.cmake +3 -0
  39. data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmarkextensions_static.dir/core-extensions.c.o +0 -0
  40. data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmarkextensions_static.dir/depend.internal +92 -0
  41. data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmarkextensions_static.dir/depend.make +92 -0
  42. data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmarkextensions_static.dir/ext_scanners.c.o +0 -0
  43. data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmarkextensions_static.dir/flags.make +10 -0
  44. data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmarkextensions_static.dir/link.txt +2 -0
  45. data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmarkextensions_static.dir/progress.make +8 -0
  46. data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmarkextensions_static.dir/strikethrough.c.o +0 -0
  47. data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmarkextensions_static.dir/table.c.o +0 -0
  48. data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmarkextensions_static.dir/whitelist.c.o +0 -0
  49. data/ext/commonmarker/cmark/build/extensions/CMakeFiles/progress.marks +1 -0
  50. data/ext/commonmarker/cmark/build/extensions/Makefile +390 -0
  51. data/ext/commonmarker/cmark/build/extensions/cmake_install.cmake +29 -0
  52. data/ext/commonmarker/cmark/build/extensions/libcmarkextensions.a +0 -0
  53. data/ext/commonmarker/cmark/build/man/Makefile +9 -9
  54. data/ext/commonmarker/cmark/build/src/CMakeFiles/Export/lib/cmake/cmark.cmake +1 -1
  55. data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/DependInfo.cmake +7 -19
  56. data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/build.make +6 -517
  57. data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/cmake_clean.cmake +0 -19
  58. data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/flags.make +1 -1
  59. data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/link.txt +1 -1
  60. data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/progress.make +0 -19
  61. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/DependInfo.cmake +9 -0
  62. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/build.make +112 -4
  63. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/cmake_clean.cmake +4 -0
  64. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/flags.make +1 -1
  65. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/link.txt +1 -1
  66. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/progress.make +24 -20
  67. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/C.includecache +144 -10
  68. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/DependInfo.cmake +9 -0
  69. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/blocks.c.o +0 -0
  70. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/build.make +112 -4
  71. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/cmake_clean.cmake +4 -0
  72. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/cmark.c.o +0 -0
  73. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/commonmark.c.o +0 -0
  74. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/depend.internal +74 -0
  75. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/depend.make +74 -0
  76. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/flags.make +1 -1
  77. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/html.c.o +0 -0
  78. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/inlines.c.o +0 -0
  79. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/iterator.c.o +0 -0
  80. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/latex.c.o +0 -0
  81. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/link.txt +1 -1
  82. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/linked_list.c.o +0 -0
  83. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/man.c.o +0 -0
  84. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/node.c.o +0 -0
  85. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/plugin.c.o +0 -0
  86. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/progress.make +24 -20
  87. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/registry.c.o +0 -0
  88. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/scanners.c.o +0 -0
  89. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/syntax_extension.c.o +0 -0
  90. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/xml.c.o +0 -0
  91. data/ext/commonmarker/cmark/build/src/CMakeFiles/progress.marks +1 -1
  92. data/ext/commonmarker/cmark/build/src/Makefile +141 -66
  93. data/ext/commonmarker/cmark/build/src/cmake_install.cmake +4 -0
  94. data/ext/commonmarker/cmark/build/src/libcmark.a +0 -0
  95. data/ext/commonmarker/cmark/build/testdir/CTestTestfile.cmake +3 -1
  96. data/ext/commonmarker/cmark/build/testdir/Makefile +9 -9
  97. data/ext/commonmarker/cmark/extensions/CMakeLists.txt +82 -0
  98. data/ext/commonmarker/cmark/extensions/autolink.c +338 -0
  99. data/ext/commonmarker/cmark/extensions/autolink.h +8 -0
  100. data/ext/commonmarker/cmark/extensions/core-extensions.c +16 -0
  101. data/ext/commonmarker/cmark/extensions/core-extensions.h +16 -0
  102. data/ext/commonmarker/cmark/extensions/ext_scanners.c +585 -0
  103. data/ext/commonmarker/cmark/extensions/ext_scanners.h +20 -0
  104. data/ext/commonmarker/cmark/extensions/ext_scanners.re +65 -0
  105. data/ext/commonmarker/cmark/extensions/strikethrough.c +142 -0
  106. data/ext/commonmarker/cmark/extensions/strikethrough.h +9 -0
  107. data/ext/commonmarker/cmark/extensions/table.c +493 -0
  108. data/ext/commonmarker/cmark/extensions/table.h +8 -0
  109. data/ext/commonmarker/cmark/extensions/whitelist.c +59 -0
  110. data/ext/commonmarker/cmark/extensions/whitelist.h +8 -0
  111. data/ext/commonmarker/cmark/man/man3/cmark.3 +98 -34
  112. data/ext/commonmarker/cmark/src/CMakeLists.txt +16 -1
  113. data/ext/commonmarker/cmark/src/blocks.c +219 -40
  114. data/ext/commonmarker/cmark/src/buffer.h +36 -0
  115. data/ext/commonmarker/cmark/src/cmark.c +5 -1
  116. data/ext/commonmarker/cmark/src/cmark.h +91 -34
  117. data/ext/commonmarker/cmark/src/cmark_ctype.h +7 -0
  118. data/ext/commonmarker/cmark/src/cmark_extension_api.h +655 -0
  119. data/ext/commonmarker/cmark/src/commonmark.c +7 -2
  120. data/ext/commonmarker/cmark/src/houdini.h +12 -6
  121. data/ext/commonmarker/cmark/src/houdini_html_e.c +1 -1
  122. data/ext/commonmarker/cmark/src/html.c +102 -54
  123. data/ext/commonmarker/cmark/src/html.h +27 -0
  124. data/ext/commonmarker/cmark/src/inlines.c +261 -53
  125. data/ext/commonmarker/cmark/src/inlines.h +7 -2
  126. data/ext/commonmarker/cmark/src/iterator.c +12 -7
  127. data/ext/commonmarker/cmark/src/latex.c +5 -2
  128. data/ext/commonmarker/cmark/src/linked_list.c +37 -0
  129. data/ext/commonmarker/cmark/src/main.c +91 -27
  130. data/ext/commonmarker/cmark/src/man.c +18 -2
  131. data/ext/commonmarker/cmark/src/node.c +157 -58
  132. data/ext/commonmarker/cmark/src/node.h +23 -0
  133. data/ext/commonmarker/cmark/src/parser.h +19 -2
  134. data/ext/commonmarker/cmark/src/plugin.c +33 -0
  135. data/ext/commonmarker/cmark/src/plugin.h +34 -0
  136. data/ext/commonmarker/cmark/src/registry.c +60 -0
  137. data/ext/commonmarker/cmark/src/registry.h +24 -0
  138. data/ext/commonmarker/cmark/src/render.h +9 -0
  139. data/ext/commonmarker/cmark/src/scanners.c +265 -391
  140. data/ext/commonmarker/cmark/src/scanners.h +5 -0
  141. data/ext/commonmarker/cmark/src/scanners.re +2 -2
  142. data/ext/commonmarker/cmark/src/syntax_extension.c +110 -0
  143. data/ext/commonmarker/cmark/src/syntax_extension.h +27 -0
  144. data/ext/commonmarker/cmark/suppressions +28 -0
  145. data/ext/commonmarker/cmark/test/CMakeLists.txt +12 -1
  146. data/ext/commonmarker/cmark/test/extensions.txt +173 -0
  147. data/ext/commonmarker/cmark/test/regression.txt +24 -0
  148. data/ext/commonmarker/cmark/test/spec.txt +27 -26
  149. data/ext/commonmarker/cmark/toolchain-mingw32.cmake +1 -1
  150. data/ext/commonmarker/commonmarker.c +132 -15
  151. data/ext/commonmarker/commonmarker.h +4 -0
  152. data/ext/commonmarker/extconf.rb +12 -5
  153. data/lib/commonmarker.rb +8 -6
  154. data/lib/commonmarker/node.rb +13 -2
  155. data/lib/commonmarker/renderer.rb +1 -1
  156. data/lib/commonmarker/version.rb +1 -1
  157. data/test/test_commonmark.rb +34 -0
  158. data/test/test_encoding.rb +2 -1
  159. data/test/test_extensions.rb +50 -0
  160. data/test/test_helper.rb +2 -1
  161. metadata +65 -11
@@ -32,22 +32,32 @@ extern unsigned char cmark_strbuf__initbuf[];
32
32
  * For the cases where CMARK_BUF_INIT cannot be used to do static
33
33
  * initialization.
34
34
  */
35
+ CMARK_EXPORT
35
36
  void cmark_strbuf_init(cmark_mem *mem, cmark_strbuf *buf,
36
37
  bufsize_t initial_size);
37
38
 
38
39
  /**
39
40
  * Grow the buffer to hold at least `target_size` bytes.
40
41
  */
42
+ CMARK_EXPORT
41
43
  void cmark_strbuf_grow(cmark_strbuf *buf, bufsize_t target_size);
42
44
 
45
+ CMARK_EXPORT
43
46
  void cmark_strbuf_free(cmark_strbuf *buf);
47
+
48
+ CMARK_EXPORT
44
49
  void cmark_strbuf_swap(cmark_strbuf *buf_a, cmark_strbuf *buf_b);
45
50
 
51
+ CMARK_EXPORT
46
52
  bufsize_t cmark_strbuf_len(const cmark_strbuf *buf);
47
53
 
54
+ CMARK_EXPORT
48
55
  int cmark_strbuf_cmp(const cmark_strbuf *a, const cmark_strbuf *b);
49
56
 
57
+ CMARK_EXPORT
50
58
  unsigned char *cmark_strbuf_detach(cmark_strbuf *buf);
59
+
60
+ CMARK_EXPORT
51
61
  void cmark_strbuf_copy_cstr(char *data, bufsize_t datasize,
52
62
  const cmark_strbuf *buf);
53
63
 
@@ -57,22 +67,48 @@ static CMARK_INLINE const char *cmark_strbuf_cstr(const cmark_strbuf *buf) {
57
67
 
58
68
  #define cmark_strbuf_at(buf, n) ((buf)->ptr[n])
59
69
 
70
+ CMARK_EXPORT
60
71
  void cmark_strbuf_set(cmark_strbuf *buf, const unsigned char *data,
61
72
  bufsize_t len);
73
+
74
+ CMARK_EXPORT
62
75
  void cmark_strbuf_sets(cmark_strbuf *buf, const char *string);
76
+
77
+ CMARK_EXPORT
63
78
  void cmark_strbuf_putc(cmark_strbuf *buf, int c);
79
+
80
+ CMARK_EXPORT
64
81
  void cmark_strbuf_put(cmark_strbuf *buf, const unsigned char *data,
65
82
  bufsize_t len);
83
+
84
+ CMARK_EXPORT
66
85
  void cmark_strbuf_puts(cmark_strbuf *buf, const char *string);
86
+
87
+ CMARK_EXPORT
67
88
  void cmark_strbuf_clear(cmark_strbuf *buf);
68
89
 
90
+ CMARK_EXPORT
69
91
  bufsize_t cmark_strbuf_strchr(const cmark_strbuf *buf, int c, bufsize_t pos);
92
+
93
+ CMARK_EXPORT
70
94
  bufsize_t cmark_strbuf_strrchr(const cmark_strbuf *buf, int c, bufsize_t pos);
95
+
96
+ CMARK_EXPORT
71
97
  void cmark_strbuf_drop(cmark_strbuf *buf, bufsize_t n);
98
+
99
+ CMARK_EXPORT
72
100
  void cmark_strbuf_truncate(cmark_strbuf *buf, bufsize_t len);
101
+
102
+ CMARK_EXPORT
73
103
  void cmark_strbuf_rtrim(cmark_strbuf *buf);
104
+
105
+ CMARK_EXPORT
74
106
  void cmark_strbuf_trim(cmark_strbuf *buf);
107
+
108
+ CMARK_EXPORT
75
109
  void cmark_strbuf_normalize_whitespace(cmark_strbuf *s);
110
+
111
+ CMARK_EXPORT
76
112
  void cmark_strbuf_unescape(cmark_strbuf *s);
77
113
 
78
114
  #ifdef __cplusplus
@@ -1,11 +1,15 @@
1
1
  #include <stdlib.h>
2
2
  #include <assert.h>
3
3
  #include <stdio.h>
4
+ #include "registry.h"
4
5
  #include "node.h"
5
6
  #include "houdini.h"
6
7
  #include "cmark.h"
7
8
  #include "buffer.h"
8
9
 
10
+ cmark_node_type CMARK_NODE_LAST_BLOCK = CMARK_NODE_THEMATIC_BREAK;
11
+ cmark_node_type CMARK_NODE_LAST_INLINE = CMARK_NODE_IMAGE;
12
+
9
13
  int cmark_version() { return CMARK_VERSION; }
10
14
 
11
15
  const char *cmark_version_string() { return CMARK_VERSION_STRING; }
@@ -32,7 +36,7 @@ char *cmark_markdown_to_html(const char *text, size_t len, int options) {
32
36
 
33
37
  doc = cmark_parse_document(text, len, options);
34
38
 
35
- result = cmark_render_html(doc, options);
39
+ result = cmark_render_html(doc, options, NULL);
36
40
  cmark_node_free(doc);
37
41
 
38
42
  return result;
@@ -1,9 +1,9 @@
1
- #ifndef CMARK_H
2
- #define CMARK_H
1
+ #ifndef CMARK_CMARK_H
2
+ #define CMARK_CMARK_H
3
3
 
4
4
  #include <stdio.h>
5
- #include <cmark_export.h>
6
- #include <cmark_version.h>
5
+ #include "cmark_export.h"
6
+ #include "cmark_version.h"
7
7
 
8
8
  #ifdef __cplusplus
9
9
  extern "C" {
@@ -30,41 +30,44 @@ char *cmark_markdown_to_html(const char *text, size_t len, int options);
30
30
  /** ## Node Structure
31
31
  */
32
32
 
33
+ #define CMARK_NODE_TYPE_PRESENT (0x8000)
34
+ #define CMARK_NODE_TYPE_BLOCK (CMARK_NODE_TYPE_PRESENT | 0x0000)
35
+ #define CMARK_NODE_TYPE_INLINE (CMARK_NODE_TYPE_PRESENT | 0x4000)
36
+ #define CMARK_NODE_TYPE_MASK (0xc000)
37
+ #define CMARK_NODE_VALUE_MASK (0x3fff)
38
+
33
39
  typedef enum {
34
40
  /* Error status */
35
- CMARK_NODE_NONE,
41
+ CMARK_NODE_NONE = 0x0000,
36
42
 
37
43
  /* Block */
38
- CMARK_NODE_DOCUMENT,
39
- CMARK_NODE_BLOCK_QUOTE,
40
- CMARK_NODE_LIST,
41
- CMARK_NODE_ITEM,
42
- CMARK_NODE_CODE_BLOCK,
43
- CMARK_NODE_HTML_BLOCK,
44
- CMARK_NODE_CUSTOM_BLOCK,
45
- CMARK_NODE_PARAGRAPH,
46
- CMARK_NODE_HEADING,
47
- CMARK_NODE_THEMATIC_BREAK,
48
-
49
- CMARK_NODE_FIRST_BLOCK = CMARK_NODE_DOCUMENT,
50
- CMARK_NODE_LAST_BLOCK = CMARK_NODE_THEMATIC_BREAK,
44
+ CMARK_NODE_DOCUMENT = CMARK_NODE_TYPE_BLOCK | 0x0001,
45
+ CMARK_NODE_BLOCK_QUOTE = CMARK_NODE_TYPE_BLOCK | 0x0002,
46
+ CMARK_NODE_LIST = CMARK_NODE_TYPE_BLOCK | 0x0003,
47
+ CMARK_NODE_ITEM = CMARK_NODE_TYPE_BLOCK | 0x0004,
48
+ CMARK_NODE_CODE_BLOCK = CMARK_NODE_TYPE_BLOCK | 0x0005,
49
+ CMARK_NODE_HTML_BLOCK = CMARK_NODE_TYPE_BLOCK | 0x0006,
50
+ CMARK_NODE_CUSTOM_BLOCK = CMARK_NODE_TYPE_BLOCK | 0x0007,
51
+ CMARK_NODE_PARAGRAPH = CMARK_NODE_TYPE_BLOCK | 0x0008,
52
+ CMARK_NODE_HEADING = CMARK_NODE_TYPE_BLOCK | 0x0009,
53
+ CMARK_NODE_THEMATIC_BREAK = CMARK_NODE_TYPE_BLOCK | 0x000a,
51
54
 
52
55
  /* Inline */
53
- CMARK_NODE_TEXT,
54
- CMARK_NODE_SOFTBREAK,
55
- CMARK_NODE_LINEBREAK,
56
- CMARK_NODE_CODE,
57
- CMARK_NODE_HTML_INLINE,
58
- CMARK_NODE_CUSTOM_INLINE,
59
- CMARK_NODE_EMPH,
60
- CMARK_NODE_STRONG,
61
- CMARK_NODE_LINK,
62
- CMARK_NODE_IMAGE,
63
-
64
- CMARK_NODE_FIRST_INLINE = CMARK_NODE_TEXT,
65
- CMARK_NODE_LAST_INLINE = CMARK_NODE_IMAGE,
56
+ CMARK_NODE_TEXT = CMARK_NODE_TYPE_INLINE | 0x0001,
57
+ CMARK_NODE_SOFTBREAK = CMARK_NODE_TYPE_INLINE | 0x0002,
58
+ CMARK_NODE_LINEBREAK = CMARK_NODE_TYPE_INLINE | 0x0003,
59
+ CMARK_NODE_CODE = CMARK_NODE_TYPE_INLINE | 0x0004,
60
+ CMARK_NODE_HTML_INLINE = CMARK_NODE_TYPE_INLINE | 0x0005,
61
+ CMARK_NODE_CUSTOM_INLINE = CMARK_NODE_TYPE_INLINE | 0x0006,
62
+ CMARK_NODE_EMPH = CMARK_NODE_TYPE_INLINE | 0x0007,
63
+ CMARK_NODE_STRONG = CMARK_NODE_TYPE_INLINE | 0x0008,
64
+ CMARK_NODE_LINK = CMARK_NODE_TYPE_INLINE | 0x0009,
65
+ CMARK_NODE_IMAGE = CMARK_NODE_TYPE_INLINE | 0x000a,
66
66
  } cmark_node_type;
67
67
 
68
+ extern cmark_node_type CMARK_NODE_LAST_BLOCK;
69
+ extern cmark_node_type CMARK_NODE_LAST_INLINE;
70
+
68
71
  /* For backwards compatibility: */
69
72
  #define CMARK_NODE_HEADER CMARK_NODE_HEADING
70
73
  #define CMARK_NODE_HRULE CMARK_NODE_THEMATIC_BREAK
@@ -87,6 +90,8 @@ typedef struct cmark_node cmark_node;
87
90
  typedef struct cmark_parser cmark_parser;
88
91
  typedef struct cmark_iter cmark_iter;
89
92
 
93
+ typedef void (*cmark_free_func) (void *user_data);
94
+
90
95
  /**
91
96
  * ## Custom memory allocator support
92
97
  */
@@ -100,6 +105,44 @@ typedef struct cmark_mem {
100
105
  void (*free)(void *);
101
106
  } cmark_mem;
102
107
 
108
+ /*
109
+ * ## Basic data structures
110
+ *
111
+ * To keep dependencies to the strict minimum, libcmark implements
112
+ * its own versions of "classic" data structures.
113
+ */
114
+
115
+ /**
116
+ * ### Linked list
117
+ */
118
+
119
+ /** A generic singly linked list.
120
+ */
121
+ typedef struct _cmark_llist
122
+ {
123
+ struct _cmark_llist *next;
124
+ void *data;
125
+ } cmark_llist;
126
+
127
+ /** Append an element to the linked list, return the possibly modified
128
+ * head of the list.
129
+ */
130
+ CMARK_EXPORT
131
+ cmark_llist * cmark_llist_append (cmark_llist * head,
132
+ void * data);
133
+
134
+ /** Free the list starting with 'head', calling 'free_func' with the
135
+ * data pointer of each of its elements
136
+ */
137
+ CMARK_EXPORT
138
+ void cmark_llist_free_full (cmark_llist * head,
139
+ cmark_free_func free_func);
140
+
141
+ /** Free the list starting with 'head'
142
+ */
143
+ CMARK_EXPORT
144
+ void cmark_llist_free (cmark_llist * head);
145
+
103
146
  /**
104
147
  * ## Creating and Destroying Nodes
105
148
  */
@@ -254,6 +297,11 @@ CMARK_EXPORT void *cmark_node_get_user_data(cmark_node *node);
254
297
  */
255
298
  CMARK_EXPORT int cmark_node_set_user_data(cmark_node *node, void *user_data);
256
299
 
300
+ /** Set free function for user data */
301
+ CMARK_EXPORT
302
+ int cmark_node_set_user_data_free_func(cmark_node *node,
303
+ cmark_free_func free_func);
304
+
257
305
  /** Returns the type of 'node', or `CMARK_NODE_NONE` on error.
258
306
  */
259
307
  CMARK_EXPORT cmark_node_type cmark_node_get_type(cmark_node *node);
@@ -333,6 +381,15 @@ CMARK_EXPORT const char *cmark_node_get_fence_info(cmark_node *node);
333
381
  */
334
382
  CMARK_EXPORT int cmark_node_set_fence_info(cmark_node *node, const char *info);
335
383
 
384
+ /** Sets code blocks fencing details
385
+ */
386
+ CMARK_EXPORT int cmark_node_set_fenced(cmark_node * node, int fenced,
387
+ int length, int offset, char character);
388
+
389
+ /** Returns code blocks fencing details
390
+ */
391
+ CMARK_EXPORT int cmark_node_get_fenced(cmark_node *node, int *length, int *offset, char *character);
392
+
336
393
  /** Returns the URL of a link or image 'node', or an empty string
337
394
  if no URL is set.
338
395
  */
@@ -507,7 +564,7 @@ char *cmark_render_xml(cmark_node *root, int options);
507
564
  * responsibility to free the returned buffer.
508
565
  */
509
566
  CMARK_EXPORT
510
- char *cmark_render_html(cmark_node *root, int options);
567
+ char *cmark_render_html(cmark_node *root, int options, cmark_llist *extensions);
511
568
 
512
569
  /** Render a 'node' tree as a groff man page, without the header.
513
570
  * It is the caller's responsibility to free the returned buffer.
@@ -590,13 +647,13 @@ char *cmark_render_latex(cmark_node *root, int options, int width);
590
647
  * In hexadecimal format, the number 0x010203 represents version 1.2.3.
591
648
  */
592
649
  CMARK_EXPORT
593
- int cmark_version();
650
+ int cmark_version(void);
594
651
 
595
652
  /** The library version string for runtime checks. Also available as
596
653
  * macro CMARK_VERSION_STRING for compile time checks.
597
654
  */
598
655
  CMARK_EXPORT
599
- const char *cmark_version_string();
656
+ const char *cmark_version_string(void);
600
657
 
601
658
  /** # AUTHORS
602
659
  *
@@ -5,18 +5,25 @@
5
5
  extern "C" {
6
6
  #endif
7
7
 
8
+ #include "cmark_export.h"
9
+
8
10
  /** Locale-independent versions of functions from ctype.h.
9
11
  * We want cmark to behave the same no matter what the system locale.
10
12
  */
11
13
 
14
+ CMARK_EXPORT
12
15
  int cmark_isspace(char c);
13
16
 
17
+ CMARK_EXPORT
14
18
  int cmark_ispunct(char c);
15
19
 
20
+ CMARK_EXPORT
16
21
  int cmark_isalnum(char c);
17
22
 
23
+ CMARK_EXPORT
18
24
  int cmark_isdigit(char c);
19
25
 
26
+ CMARK_EXPORT
20
27
  int cmark_isalpha(char c);
21
28
 
22
29
  #ifdef __cplusplus
@@ -0,0 +1,655 @@
1
+ #ifndef CMARK_CMARK_EXTENSION_API_H
2
+ #define CMARK_CMARK_EXTENSION_API_H
3
+
4
+ #ifdef __cplusplus
5
+ extern "C" {
6
+ #endif
7
+
8
+ #include <cmark.h>
9
+ #include <render.h>
10
+
11
+ /**
12
+ * ## Extension Support
13
+ *
14
+ * While the "core" of libcmark is strictly compliant with the
15
+ * specification, an API is provided for extension writers to
16
+ * hook into the parsing process.
17
+ *
18
+ * It should be noted that the cmark_node API already offers
19
+ * room for customization, with methods offered to traverse and
20
+ * modify the AST, and even define custom blocks.
21
+ * When the desired customization is achievable in an error-proof
22
+ * way using that API, it should be the preferred method.
23
+ *
24
+ * The following API requires a more in-depth understanding
25
+ * of libcmark's parsing strategy, which is exposed
26
+ * [here](http://spec.commonmark.org/0.24/#appendix-a-parsing-strategy).
27
+ *
28
+ * It should be used when "a posteriori" modification of the AST
29
+ * proves to be too difficult / impossible to implement correctly.
30
+ *
31
+ * It can also serve as an intermediary step before extending
32
+ * the specification, as an extension implemented using this API
33
+ * will be trivially integrated in the core if it proves to be
34
+ * desirable.
35
+ */
36
+
37
+ typedef struct cmark_plugin cmark_plugin;
38
+
39
+ /** A syntax extension that can be attached to a cmark_parser
40
+ * with cmark_parser_attach_syntax_extension().
41
+ *
42
+ * Extension writers should assign functions matching
43
+ * the signature of the following 'virtual methods' to
44
+ * implement new functionality.
45
+ *
46
+ * Their calling order and expected behaviour match the procedure outlined
47
+ * at <http://spec.commonmark.org/0.24/#phase-1-block-structure>:
48
+ *
49
+ * During step 1, cmark will call the function provided through
50
+ * 'cmark_syntax_extension_set_match_block_func' when it
51
+ * iterates over an open block created by this extension,
52
+ * to determine whether it could contain the new line.
53
+ * If no function was provided, cmark will close the block.
54
+ *
55
+ * During step 2, if and only if the new line doesn't match any
56
+ * of the standard syntax rules, cmark will call the function
57
+ * provided through 'cmark_syntax_extension_set_open_block_func'
58
+ * to let the extension determine whether that new line matches
59
+ * one of its syntax rules.
60
+ * It is the responsibility of the parser to create and add the
61
+ * new block with cmark_parser_make_block and cmark_parser_add_child.
62
+ * If no function was provided is NULL, the extension will have
63
+ * no effect at all on the final block structure of the AST.
64
+ *
65
+ * #### Inline parsing phase hooks
66
+ *
67
+ * For each character provided by the extension through
68
+ * 'cmark_syntax_extension_set_special_inline_chars',
69
+ * the function provided by the extension through
70
+ * 'cmark_syntax_extension_set_match_inline_func'
71
+ * will get called, it is the responsibility of the extension
72
+ * to scan the characters located at the current inline parsing offset
73
+ * with the cmark_inline_parser API.
74
+ *
75
+ * Depending on the type of the extension, it can either:
76
+ *
77
+ * * Scan forward, determine that the syntax matches and return
78
+ * a newly-created inline node with the appropriate type.
79
+ * This is the technique that would be used if inline code
80
+ * (with backticks) was implemented as an extension.
81
+ * * Scan only the character(s) that its syntax rules require
82
+ * for opening and closing nodes, push a delimiter on the
83
+ * delimiter stack, and return a simple text node with its
84
+ * contents set to the character(s) consumed.
85
+ * This is the technique that would be used if emphasis
86
+ * inlines were implemented as an extension.
87
+ *
88
+ * When an extension has pushed delimiters on the stack,
89
+ * the function provided through
90
+ * 'cmark_syntax_extension_set_inline_from_delim_func'
91
+ * will get called in a latter phase,
92
+ * when the inline parser has matched opener and closer delimiters
93
+ * created by the extension together.
94
+ *
95
+ * It is then the responsibility of the extension to modify
96
+ * and populate the opener inline text node, and to remove
97
+ * the necessary delimiters from the delimiter stack.
98
+ *
99
+ * Finally, the extension should return NULL if its scan didn't
100
+ * match its syntax rules.
101
+ *
102
+ * The extension can store whatever private data it might need
103
+ * with 'cmark_syntax_extension_set_private',
104
+ * and optionally define a free function for this data.
105
+ */
106
+ typedef struct cmark_syntax_extension cmark_syntax_extension;
107
+
108
+ typedef struct subject cmark_inline_parser;
109
+
110
+ /** Exposed raw for now */
111
+
112
+ typedef struct delimiter {
113
+ struct delimiter *previous;
114
+ struct delimiter *next;
115
+ cmark_node *inl_text;
116
+ int position;
117
+ unsigned char delim_char;
118
+ int can_open;
119
+ int can_close;
120
+ int active;
121
+ } delimiter;
122
+
123
+ /**
124
+ * ### Plugin API.
125
+ *
126
+ * Extensions should be distributed as dynamic libraries,
127
+ * with a single exported function named after the distributed
128
+ * filename.
129
+ *
130
+ * When discovering extensions (see cmark_init), cmark will
131
+ * try to load a symbol named "init_{{filename}}" in all the
132
+ * dynamic libraries it encounters.
133
+ *
134
+ * For example, given a dynamic library named myextension.so
135
+ * (or myextension.dll), cmark will try to load the symbol
136
+ * named "init_myextension". This means that the filename
137
+ * must lend itself to forming a valid C identifier, with
138
+ * the notable exception of dashes, which will be translated
139
+ * to underscores, which means cmark will look for a function
140
+ * named "init_my_extension" if it encounters a dynamic library
141
+ * named "my-extension.so".
142
+ *
143
+ * See the 'cmark_plugin_init_func' typedef for the exact prototype
144
+ * this function should follow.
145
+ *
146
+ * For now the extensibility of cmark is not complete, as
147
+ * it only offers API to hook into the block parsing phase
148
+ * (<http://spec.commonmark.org/0.24/#phase-1-block-structure>).
149
+ *
150
+ * See 'cmark_plugin_register_syntax_extension' for more information.
151
+ */
152
+
153
+ /** The prototype plugins' init function should follow.
154
+ */
155
+ typedef int (*cmark_plugin_init_func)(cmark_plugin *plugin);
156
+
157
+ /** Register a syntax 'extension' with the 'plugin', it will be made
158
+ * available as an extension and, if attached to a cmark_parser
159
+ * with 'cmark_parser_attach_syntax_extension', it will contribute
160
+ * to the block parsing process.
161
+ *
162
+ * See the documentation for 'cmark_syntax_extension' for information
163
+ * on how to implement one.
164
+ *
165
+ * This function will typically be called from the init function
166
+ * of external modules.
167
+ *
168
+ * This takes ownership of 'extension', one should not call
169
+ * 'cmark_syntax_extension_free' on a registered extension.
170
+ */
171
+ CMARK_EXPORT
172
+ int cmark_plugin_register_syntax_extension(cmark_plugin *plugin,
173
+ cmark_syntax_extension *extension);
174
+
175
+ /** This will search for the syntax extension named 'name' among the
176
+ * registered syntax extensions.
177
+ *
178
+ * It can then be attached to a cmark_parser
179
+ * with the cmark_parser_attach_syntax_extension method.
180
+ */
181
+ CMARK_EXPORT
182
+ cmark_syntax_extension *cmark_find_syntax_extension(const char *name);
183
+
184
+ /** Should create and add a new open block to 'parent_container' if
185
+ * 'input' matches a syntax rule for that block type. It is allowed
186
+ * to modify the type of 'parent_container'.
187
+ *
188
+ * Should return the newly created block if there is one, or
189
+ * 'parent_container' if its type was modified, or NULL.
190
+ */
191
+ typedef cmark_node * (*cmark_open_block_func) (cmark_syntax_extension *extension,
192
+ int indented,
193
+ cmark_parser *parser,
194
+ cmark_node *parent_container,
195
+ unsigned char *input,
196
+ int len);
197
+
198
+ typedef cmark_node *(*cmark_match_inline_func)(cmark_syntax_extension *extension,
199
+ cmark_parser *parser,
200
+ cmark_node *parent,
201
+ unsigned char character,
202
+ cmark_inline_parser *inline_parser);
203
+
204
+ typedef delimiter *(*cmark_inline_from_delim_func)(cmark_syntax_extension *extension,
205
+ cmark_parser *parser,
206
+ cmark_inline_parser *inline_parser,
207
+ delimiter *opener,
208
+ delimiter *closer);
209
+
210
+ /** Should return 'true' if 'input' can be contained in 'container',
211
+ * 'false' otherwise.
212
+ */
213
+ typedef int (*cmark_match_block_func) (cmark_syntax_extension *extension,
214
+ cmark_parser *parser,
215
+ unsigned char *input,
216
+ int len,
217
+ cmark_node *container);
218
+
219
+ typedef const char *(*cmark_get_type_string_func) (cmark_syntax_extension *extension,
220
+ cmark_node *node);
221
+
222
+ typedef int (*cmark_can_contain_func) (cmark_syntax_extension *extension,
223
+ cmark_node *node,
224
+ cmark_node_type child);
225
+
226
+ typedef int (*cmark_contains_inlines_func) (cmark_syntax_extension *extension,
227
+ cmark_node *node);
228
+
229
+ typedef void (*cmark_common_render_func) (cmark_syntax_extension *extension,
230
+ cmark_renderer *renderer,
231
+ cmark_node *node,
232
+ cmark_event_type ev_type,
233
+ int options);
234
+
235
+ typedef void (*cmark_html_render_func) (cmark_syntax_extension *extension,
236
+ cmark_html_renderer *renderer,
237
+ cmark_node *node,
238
+ cmark_event_type ev_type,
239
+ int options);
240
+
241
+ typedef int (*cmark_html_filter_func) (cmark_syntax_extension *extension,
242
+ const unsigned char *tag,
243
+ size_t tag_len);
244
+
245
+ typedef cmark_node *(*cmark_postprocess_func) (cmark_syntax_extension *extension,
246
+ cmark_node *root);
247
+
248
+ /** Free a cmark_syntax_extension.
249
+ */
250
+ CMARK_EXPORT
251
+ void cmark_syntax_extension_free (cmark_syntax_extension *extension);
252
+
253
+ /** Return a newly-constructed cmark_syntax_extension, named 'name'.
254
+ */
255
+ CMARK_EXPORT
256
+ cmark_syntax_extension *cmark_syntax_extension_new (const char *name);
257
+
258
+ CMARK_EXPORT
259
+ cmark_node_type cmark_syntax_extension_add_node(int is_inline);
260
+
261
+ /** See the documentation for 'cmark_syntax_extension'
262
+ */
263
+ CMARK_EXPORT
264
+ void cmark_syntax_extension_set_open_block_func(cmark_syntax_extension *extension,
265
+ cmark_open_block_func func);
266
+
267
+ /** See the documentation for 'cmark_syntax_extension'
268
+ */
269
+ CMARK_EXPORT
270
+ void cmark_syntax_extension_set_match_block_func(cmark_syntax_extension *extension,
271
+ cmark_match_block_func func);
272
+
273
+ /** See the documentation for 'cmark_syntax_extension'
274
+ */
275
+ CMARK_EXPORT
276
+ void cmark_syntax_extension_set_match_inline_func(cmark_syntax_extension *extension,
277
+ cmark_match_inline_func func);
278
+
279
+ /** See the documentation for 'cmark_syntax_extension'
280
+ */
281
+ CMARK_EXPORT
282
+ void cmark_syntax_extension_set_inline_from_delim_func(cmark_syntax_extension *extension,
283
+ cmark_inline_from_delim_func func);
284
+
285
+ /** See the documentation for 'cmark_syntax_extension'
286
+ */
287
+ CMARK_EXPORT
288
+ void cmark_syntax_extension_set_special_inline_chars(cmark_syntax_extension *extension,
289
+ cmark_llist *special_chars);
290
+
291
+ /** See the documentation for 'cmark_syntax_extension'
292
+ */
293
+ CMARK_EXPORT
294
+ void cmark_syntax_extension_set_get_type_string_func(cmark_syntax_extension *extension,
295
+ cmark_get_type_string_func func);
296
+
297
+ /** See the documentation for 'cmark_syntax_extension'
298
+ */
299
+ CMARK_EXPORT
300
+ void cmark_syntax_extension_set_can_contain_func(cmark_syntax_extension *extension,
301
+ cmark_can_contain_func func);
302
+
303
+ /** See the documentation for 'cmark_syntax_extension'
304
+ */
305
+ CMARK_EXPORT
306
+ void cmark_syntax_extension_set_contains_inlines_func(cmark_syntax_extension *extension,
307
+ cmark_contains_inlines_func func);
308
+
309
+ /** See the documentation for 'cmark_syntax_extension'
310
+ */
311
+ CMARK_EXPORT
312
+ void cmark_syntax_extension_set_commonmark_render_func(cmark_syntax_extension *extension,
313
+ cmark_common_render_func func);
314
+
315
+ /** See the documentation for 'cmark_syntax_extension'
316
+ */
317
+ CMARK_EXPORT
318
+ void cmark_syntax_extension_set_latex_render_func(cmark_syntax_extension *extension,
319
+ cmark_common_render_func func);
320
+
321
+ /** See the documentation for 'cmark_syntax_extension'
322
+ */
323
+ CMARK_EXPORT
324
+ void cmark_syntax_extension_set_man_render_func(cmark_syntax_extension *extension,
325
+ cmark_common_render_func func);
326
+
327
+ /** See the documentation for 'cmark_syntax_extension'
328
+ */
329
+ CMARK_EXPORT
330
+ void cmark_syntax_extension_set_html_render_func(cmark_syntax_extension *extension,
331
+ cmark_html_render_func func);
332
+
333
+ /** See the documentation for 'cmark_syntax_extension'
334
+ */
335
+ CMARK_EXPORT
336
+ void cmark_syntax_extension_set_html_filter_func(cmark_syntax_extension *extension,
337
+ cmark_html_filter_func func);
338
+
339
+ /** See the documentation for 'cmark_syntax_extension'
340
+ */
341
+ CMARK_EXPORT
342
+ void cmark_syntax_extension_set_private(cmark_syntax_extension *extension,
343
+ void *priv,
344
+ cmark_free_func free_func);
345
+
346
+ /** See the documentation for 'cmark_syntax_extension'
347
+ */
348
+ CMARK_EXPORT
349
+ void cmark_syntax_extension_set_postprocess_func(cmark_syntax_extension *extension,
350
+ cmark_postprocess_func func);
351
+
352
+ /** Return the index of the line currently being parsed, starting with 1.
353
+ */
354
+ CMARK_EXPORT
355
+ int cmark_parser_get_line_number(cmark_parser *parser);
356
+
357
+ /** Return the offset in bytes in the line being processed.
358
+ *
359
+ * Example:
360
+ *
361
+ * ### foo
362
+ *
363
+ * Here, offset will first be 0, then 5 (the index of the 'f' character).
364
+ */
365
+ CMARK_EXPORT
366
+ int cmark_parser_get_offset(cmark_parser *parser);
367
+
368
+ /**
369
+ * Return the offset in 'columns' in the line being processed.
370
+ *
371
+ * This value may differ from the value returned by
372
+ * cmark_parser_get_offset() in that it accounts for tabs,
373
+ * and as such should not be used as an index in the current line's
374
+ * buffer.
375
+ *
376
+ * Example:
377
+ *
378
+ * cmark_parser_advance_offset() can be called to advance the
379
+ * offset by a number of columns, instead of a number of bytes.
380
+ *
381
+ * In that case, if offset falls "in the middle" of a tab
382
+ * character, 'column' and offset will differ.
383
+ *
384
+ * ```
385
+ * foo \t bar
386
+ * ^ ^^
387
+ * offset (0) 20
388
+ * ```
389
+ *
390
+ * If cmark_parser_advance_offset is called here with 'columns'
391
+ * set to 'true' and 'offset' set to 22, cmark_parser_get_offset()
392
+ * will return 20, whereas cmark_parser_get_column() will return
393
+ * 22.
394
+ *
395
+ * Additionally, as tabs expand to the next multiple of 4 column,
396
+ * cmark_parser_has_partially_consumed_tab() will now return
397
+ * 'true'.
398
+ */
399
+ CMARK_EXPORT
400
+ int cmark_parser_get_column(cmark_parser *parser);
401
+
402
+ /** Return the absolute index in bytes of the first nonspace
403
+ * character coming after the offset as returned by
404
+ * cmark_parser_get_offset() in the line currently being processed.
405
+ *
406
+ * Example:
407
+ *
408
+ * ```
409
+ * foo bar baz \n
410
+ * ^ ^ ^
411
+ * 0 offset (16) first_nonspace (28)
412
+ * ```
413
+ */
414
+ CMARK_EXPORT
415
+ int cmark_parser_get_first_nonspace(cmark_parser *parser);
416
+
417
+ /** Return the absolute index of the first nonspace column coming after 'offset'
418
+ * in the line currently being processed, counting tabs as multiple
419
+ * columns as appropriate.
420
+ *
421
+ * See the documentation for cmark_parser_get_first_nonspace() and
422
+ * cmark_parser_get_column() for more information.
423
+ */
424
+ CMARK_EXPORT
425
+ int cmark_parser_get_first_nonspace_column(cmark_parser *parser);
426
+
427
+ /** Return the difference between the values returned by
428
+ * cmark_parser_get_first_nonspace_column() and
429
+ * cmark_parser_get_column().
430
+ *
431
+ * This is not a byte offset, as it can count one tab as multiple
432
+ * characters.
433
+ */
434
+ CMARK_EXPORT
435
+ int cmark_parser_get_indent(cmark_parser *parser);
436
+
437
+ /** Return 'true' if the line currently being processed has been entirely
438
+ * consumed, 'false' otherwise.
439
+ *
440
+ * Example:
441
+ *
442
+ * ```
443
+ * foo bar baz \n
444
+ * ^
445
+ * offset
446
+ * ```
447
+ *
448
+ * This function will return 'false' here.
449
+ *
450
+ * ```
451
+ * foo bar baz \n
452
+ * ^
453
+ * offset
454
+ * ```
455
+ * This function will still return 'false'.
456
+ *
457
+ * ```
458
+ * foo bar baz \n
459
+ * ^
460
+ * offset
461
+ * ```
462
+ *
463
+ * At this point, this function will now return 'true'.
464
+ */
465
+ CMARK_EXPORT
466
+ int cmark_parser_is_blank(cmark_parser *parser);
467
+
468
+ /** Return 'true' if the value returned by cmark_parser_get_offset()
469
+ * is 'inside' an expanded tab.
470
+ *
471
+ * See the documentation for cmark_parser_get_column() for more
472
+ * information.
473
+ */
474
+ CMARK_EXPORT
475
+ int cmark_parser_has_partially_consumed_tab(cmark_parser *parser);
476
+
477
+ /** Return the length in bytes of the previously processed line, excluding potential
478
+ * newline (\n) and carriage return (\r) trailing characters.
479
+ */
480
+ CMARK_EXPORT
481
+ int cmark_parser_get_last_line_length(cmark_parser *parser);
482
+
483
+ /** Add a child to 'parent' during the parsing process.
484
+ *
485
+ * If 'parent' isn't the kind of node that can accept this child,
486
+ * this function will back up till it hits a node that can, closing
487
+ * blocks as appropriate.
488
+ */
489
+ CMARK_EXPORT
490
+ cmark_node*cmark_parser_add_child(cmark_parser *parser,
491
+ cmark_node *parent,
492
+ cmark_node_type block_type,
493
+ int start_column);
494
+
495
+ /** Advance the 'offset' of the parser in the current line.
496
+ *
497
+ * See the documentation of cmark_parser_get_offset() and
498
+ * cmark_parser_get_column() for more information.
499
+ */
500
+ CMARK_EXPORT
501
+ void cmark_parser_advance_offset(cmark_parser *parser,
502
+ const char *input,
503
+ int count,
504
+ int columns);
505
+
506
+
507
+ CMARK_EXPORT
508
+ void cmark_parser_feed_reentrant(cmark_parser *parser, const char *buffer, size_t len);
509
+
510
+ /** Attach the syntax 'extension' to the 'parser', to provide extra syntax
511
+ * rules.
512
+ * See the documentation for cmark_syntax_extension for more information.
513
+ *
514
+ * Returns 'true' if the 'extension' was successfully attached,
515
+ * 'false' otherwise.
516
+ */
517
+ CMARK_EXPORT
518
+ int cmark_parser_attach_syntax_extension(cmark_parser *parser, cmark_syntax_extension *extension);
519
+
520
+ /** Change the type of 'node'.
521
+ *
522
+ * Return 0 if the type could be changed, 1 otherwise.
523
+ */
524
+ CMARK_EXPORT int cmark_node_set_type(cmark_node *node, cmark_node_type type);
525
+
526
+ /** Return the string content for all types of 'node'.
527
+ * The pointer stays valid as long as 'node' isn't freed.
528
+ */
529
+ CMARK_EXPORT const char *cmark_node_get_string_content(cmark_node *node);
530
+
531
+ /** Set the string 'content' for all types of 'node'.
532
+ * Copies 'content'.
533
+ */
534
+ CMARK_EXPORT int cmark_node_set_string_content(cmark_node *node, const char *content);
535
+
536
+ /** Get the syntax extension responsible for the creation of 'node'.
537
+ * Return NULL if 'node' was created because it matched standard syntax rules.
538
+ */
539
+ CMARK_EXPORT cmark_syntax_extension *cmark_node_get_syntax_extension(cmark_node *node);
540
+
541
+ /** Set the syntax extension responsible for creating 'node'.
542
+ */
543
+ CMARK_EXPORT int cmark_node_set_syntax_extension(cmark_node *node,
544
+ cmark_syntax_extension *extension);
545
+
546
+ /**
547
+ * ## Inline syntax extension helpers
548
+ *
549
+ * The inline parsing process is described in detail at
550
+ * <http://spec.commonmark.org/0.24/#phase-2-inline-structure>
551
+ */
552
+
553
+ /** Should return 'true' if the predicate matches 'c', 'false' otherwise
554
+ */
555
+ typedef int (*cmark_inline_predicate)(int c);
556
+
557
+ /** Advance the current inline parsing offset */
558
+ CMARK_EXPORT
559
+ void cmark_inline_parser_advance_offset(cmark_inline_parser *parser);
560
+
561
+ /** Get the current inline parsing offset */
562
+ CMARK_EXPORT
563
+ int cmark_inline_parser_get_offset(cmark_inline_parser *parser);
564
+
565
+ /** Set the offset in bytes in the chunk being processed by the given inline parser.
566
+ */
567
+ CMARK_EXPORT
568
+ void cmark_inline_parser_set_offset(cmark_inline_parser *parser, int offset);
569
+
570
+ /** Gets the cmark_chunk being operated on by the given inline parser.
571
+ * Use cmark_inline_parser_get_offset to get our current position in the chunk.
572
+ */
573
+ CMARK_EXPORT
574
+ cmark_chunk *cmark_inline_parser_get_chunk(cmark_inline_parser *parser);
575
+
576
+ /** Returns 1 if the inline parser is currently in a bracket; pass 1 for 'image'
577
+ * if you want to know about an image-type bracket, 0 for link-type. */
578
+ CMARK_EXPORT
579
+ int cmark_inline_parser_in_bracket(cmark_inline_parser *parser, int image);
580
+
581
+ /** Remove the last n characters from the last child of the given node.
582
+ * This only works where all n characters are in the single last child, and the last
583
+ * child is CMARK_NODE_TEXT.
584
+ */
585
+ CMARK_EXPORT
586
+ void cmark_node_unput(cmark_node *node, int n);
587
+
588
+
589
+ /** Get the character located at the current inline parsing offset
590
+ */
591
+ CMARK_EXPORT
592
+ unsigned char cmark_inline_parser_peek_char(cmark_inline_parser *parser);
593
+
594
+ /** Get the character located 'pos' bytes in the current line.
595
+ */
596
+ CMARK_EXPORT
597
+ unsigned char cmark_inline_parser_peek_at(cmark_inline_parser *parser, int pos);
598
+
599
+ /** Whether the inline parser has reached the end of the current line
600
+ */
601
+ CMARK_EXPORT
602
+ int cmark_inline_parser_is_eof(cmark_inline_parser *parser);
603
+
604
+ /** Get the characters located after the current inline parsing offset
605
+ * while 'pred' matches. Free after usage.
606
+ */
607
+ CMARK_EXPORT
608
+ char *cmark_inline_parser_take_while(cmark_inline_parser *parser, cmark_inline_predicate pred);
609
+
610
+ /** Push a delimiter on the delimiter stack.
611
+ * See <<http://spec.commonmark.org/0.24/#phase-2-inline-structure> for
612
+ * more information on the parameters
613
+ */
614
+ CMARK_EXPORT
615
+ void cmark_inline_parser_push_delimiter(cmark_inline_parser *parser,
616
+ unsigned char c,
617
+ int can_open,
618
+ int can_close,
619
+ cmark_node *inl_text);
620
+
621
+ /** Remove 'delim' from the delimiter stack
622
+ */
623
+ CMARK_EXPORT
624
+ void cmark_inline_parser_remove_delimiter(cmark_inline_parser *parser, delimiter *delim);
625
+
626
+ CMARK_EXPORT
627
+ delimiter *cmark_inline_parser_get_last_delimiter(cmark_inline_parser *parser);
628
+
629
+ /** Convenience function to scan a given delimiter.
630
+ *
631
+ * 'left_flanking' and 'right_flanking' will be set to true if they
632
+ * respectively precede and follow a non-space, non-punctuation
633
+ * character.
634
+ *
635
+ * Additionally, 'punct_before' and 'punct_after' will respectively be set
636
+ * if the preceding or following character is a punctuation character.
637
+ *
638
+ * Note that 'left_flanking' and 'right_flanking' can both be 'true'.
639
+ *
640
+ * Returns the number of delimiters encountered, in the limit
641
+ * of 'max_delims', and advances the inline parsing offset.
642
+ */
643
+ CMARK_EXPORT
644
+ int cmark_inline_parser_scan_delimiters(cmark_inline_parser *parser,
645
+ int max_delims,
646
+ unsigned char c,
647
+ int *left_flanking,
648
+ int *right_flanking,
649
+ int *punct_before,
650
+ int *punct_after);
651
+ #ifdef __cplusplus
652
+ }
653
+ #endif
654
+
655
+ #endif