commonmarker 0.0.1

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 (291) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +8 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.md +119 -0
  5. data/Rakefile +39 -0
  6. data/bin/commonmarker +41 -0
  7. data/commonmarker.gemspec +30 -0
  8. data/ext/commonmarker/cmark/CMakeLists.txt +25 -0
  9. data/ext/commonmarker/cmark/COPYING +192 -0
  10. data/ext/commonmarker/cmark/FindAsan.cmake +74 -0
  11. data/ext/commonmarker/cmark/Makefile +170 -0
  12. data/ext/commonmarker/cmark/Makefile.nmake +36 -0
  13. data/ext/commonmarker/cmark/README.md +169 -0
  14. data/ext/commonmarker/cmark/api_test/CMakeLists.txt +25 -0
  15. data/ext/commonmarker/cmark/api_test/cplusplus.cpp +15 -0
  16. data/ext/commonmarker/cmark/api_test/cplusplus.h +17 -0
  17. data/ext/commonmarker/cmark/api_test/harness.c +102 -0
  18. data/ext/commonmarker/cmark/api_test/harness.h +42 -0
  19. data/ext/commonmarker/cmark/api_test/main.c +700 -0
  20. data/ext/commonmarker/cmark/appveyor.yml +15 -0
  21. data/ext/commonmarker/cmark/bench/statistics.py +595 -0
  22. data/ext/commonmarker/cmark/bench/stats.py +19 -0
  23. data/ext/commonmarker/cmark/benchmarks.md +33 -0
  24. data/ext/commonmarker/cmark/build/CMakeCache.txt +362 -0
  25. data/ext/commonmarker/cmark/build/CMakeFiles/3.2.2/CMakeCCompiler.cmake +63 -0
  26. data/ext/commonmarker/cmark/build/CMakeFiles/3.2.2/CMakeCXXCompiler.cmake +64 -0
  27. data/ext/commonmarker/cmark/build/CMakeFiles/3.2.2/CMakeDetermineCompilerABI_C.bin +0 -0
  28. data/ext/commonmarker/cmark/build/CMakeFiles/3.2.2/CMakeDetermineCompilerABI_CXX.bin +0 -0
  29. data/ext/commonmarker/cmark/build/CMakeFiles/3.2.2/CMakeSystem.cmake +15 -0
  30. data/ext/commonmarker/cmark/build/CMakeFiles/3.2.2/CompilerIdC/CMakeCCompilerId.c +499 -0
  31. data/ext/commonmarker/cmark/build/CMakeFiles/3.2.2/CompilerIdC/a.out +0 -0
  32. data/ext/commonmarker/cmark/build/CMakeFiles/3.2.2/CompilerIdCXX/CMakeCXXCompilerId.cpp +489 -0
  33. data/ext/commonmarker/cmark/build/CMakeFiles/3.2.2/CompilerIdCXX/a.out +0 -0
  34. data/ext/commonmarker/cmark/build/CMakeFiles/CMakeDirectoryInformation.cmake +16 -0
  35. data/ext/commonmarker/cmark/build/CMakeFiles/CMakeError.log +30 -0
  36. data/ext/commonmarker/cmark/build/CMakeFiles/CMakeOutput.log +598 -0
  37. data/ext/commonmarker/cmark/build/CMakeFiles/Makefile.cmake +77 -0
  38. data/ext/commonmarker/cmark/build/CMakeFiles/Makefile2 +268 -0
  39. data/ext/commonmarker/cmark/build/CMakeFiles/TargetDirectories.txt +4 -0
  40. data/ext/commonmarker/cmark/build/CMakeFiles/cmake.check_cache +1 -0
  41. data/ext/commonmarker/cmark/build/CMakeFiles/feature_tests.bin +0 -0
  42. data/ext/commonmarker/cmark/build/CMakeFiles/feature_tests.c +34 -0
  43. data/ext/commonmarker/cmark/build/CMakeFiles/feature_tests.cxx +405 -0
  44. data/ext/commonmarker/cmark/build/CMakeFiles/progress.marks +1 -0
  45. data/ext/commonmarker/cmark/build/CTestTestfile.cmake +10 -0
  46. data/ext/commonmarker/cmark/build/Makefile +237 -0
  47. data/ext/commonmarker/cmark/build/api_test/CMakeFiles/CMakeDirectoryInformation.cmake +16 -0
  48. data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/C.includecache +92 -0
  49. data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/CXX.includecache +36 -0
  50. data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/DependInfo.cmake +29 -0
  51. data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/build.make +155 -0
  52. data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/cmake_clean.cmake +12 -0
  53. data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/cplusplus.cpp.o +0 -0
  54. data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/depend.internal +25 -0
  55. data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/depend.make +25 -0
  56. data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/flags.make +13 -0
  57. data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/harness.c.o +0 -0
  58. data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/link.txt +1 -0
  59. data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/main.c.o +0 -0
  60. data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/progress.make +4 -0
  61. data/ext/commonmarker/cmark/build/api_test/CMakeFiles/progress.marks +1 -0
  62. data/ext/commonmarker/cmark/build/api_test/Makefile +277 -0
  63. data/ext/commonmarker/cmark/build/api_test/api_test +0 -0
  64. data/ext/commonmarker/cmark/build/api_test/cmake_install.cmake +29 -0
  65. data/ext/commonmarker/cmark/build/cmake_install.cmake +48 -0
  66. data/ext/commonmarker/cmark/build/man/CMakeFiles/CMakeDirectoryInformation.cmake +16 -0
  67. data/ext/commonmarker/cmark/build/man/CMakeFiles/progress.marks +1 -0
  68. data/ext/commonmarker/cmark/build/man/Makefile +181 -0
  69. data/ext/commonmarker/cmark/build/man/cmake_install.cmake +37 -0
  70. data/ext/commonmarker/cmark/build/src/CMakeFiles/CMakeDirectoryInformation.cmake +16 -0
  71. data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/C.includecache +422 -0
  72. data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/DependInfo.cmake +39 -0
  73. data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/blocks.c.o +0 -0
  74. data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/buffer.c.o +0 -0
  75. data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/build.make +544 -0
  76. data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/cmake_clean.cmake +27 -0
  77. data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/cmark.c.o +0 -0
  78. data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/cmark_ctype.c.o +0 -0
  79. data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/commonmark.c.o +0 -0
  80. data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/depend.internal +177 -0
  81. data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/depend.make +177 -0
  82. data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/flags.make +8 -0
  83. data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/houdini_href_e.c.o +0 -0
  84. data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/houdini_html_e.c.o +0 -0
  85. data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/houdini_html_u.c.o +0 -0
  86. data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/html.c.o +0 -0
  87. data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/inlines.c.o +0 -0
  88. data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/iterator.c.o +0 -0
  89. data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/link.txt +1 -0
  90. data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/main.c.o +0 -0
  91. data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/man.c.o +0 -0
  92. data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/node.c.o +0 -0
  93. data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/progress.make +19 -0
  94. data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/references.c.o +0 -0
  95. data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/scanners.c.o +0 -0
  96. data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/utf8.c.o +0 -0
  97. data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/xml.c.o +0 -0
  98. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/C.includecache +394 -0
  99. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/DependInfo.cmake +44 -0
  100. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/blocks.c.o +0 -0
  101. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/buffer.c.o +0 -0
  102. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/build.make +522 -0
  103. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/cmake_clean.cmake +27 -0
  104. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/cmark.c.o +0 -0
  105. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/cmark_ctype.c.o +0 -0
  106. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/commonmark.c.o +0 -0
  107. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/depend.internal +169 -0
  108. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/depend.make +169 -0
  109. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/flags.make +8 -0
  110. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/houdini_href_e.c.o +0 -0
  111. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/houdini_html_e.c.o +0 -0
  112. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/houdini_html_u.c.o +0 -0
  113. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/html.c.o +0 -0
  114. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/inlines.c.o +0 -0
  115. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/iterator.c.o +0 -0
  116. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/link.txt +1 -0
  117. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/man.c.o +0 -0
  118. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/node.c.o +0 -0
  119. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/progress.make +18 -0
  120. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/references.c.o +0 -0
  121. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/scanners.c.o +0 -0
  122. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/utf8.c.o +0 -0
  123. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/xml.c.o +0 -0
  124. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/C.includecache +394 -0
  125. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/DependInfo.cmake +38 -0
  126. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/blocks.c.o +0 -0
  127. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/buffer.c.o +0 -0
  128. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/build.make +519 -0
  129. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/cmake_clean.cmake +26 -0
  130. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/cmake_clean_target.cmake +3 -0
  131. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/cmark.c.o +0 -0
  132. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/cmark_ctype.c.o +0 -0
  133. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/commonmark.c.o +0 -0
  134. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/depend.internal +169 -0
  135. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/depend.make +169 -0
  136. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/flags.make +8 -0
  137. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/houdini_href_e.c.o +0 -0
  138. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/houdini_html_e.c.o +0 -0
  139. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/houdini_html_u.c.o +0 -0
  140. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/html.c.o +0 -0
  141. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/inlines.c.o +0 -0
  142. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/iterator.c.o +0 -0
  143. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/link.txt +2 -0
  144. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/man.c.o +0 -0
  145. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/node.c.o +0 -0
  146. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/progress.make +18 -0
  147. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/references.c.o +0 -0
  148. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/scanners.c.o +0 -0
  149. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/utf8.c.o +0 -0
  150. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/xml.c.o +0 -0
  151. data/ext/commonmarker/cmark/build/src/CMakeFiles/progress.marks +1 -0
  152. data/ext/commonmarker/cmark/build/src/Makefile +814 -0
  153. data/ext/commonmarker/cmark/build/src/cmake_install.cmake +69 -0
  154. data/ext/commonmarker/cmark/build/src/cmark +0 -0
  155. data/ext/commonmarker/cmark/build/src/cmark_export.h +41 -0
  156. data/ext/commonmarker/cmark/build/src/cmark_version.h +7 -0
  157. data/ext/commonmarker/cmark/build/src/config.h +23 -0
  158. data/ext/commonmarker/cmark/build/src/libcmark.0.19.0.dylib +0 -0
  159. data/ext/commonmarker/cmark/build/src/libcmark.a +0 -0
  160. data/ext/commonmarker/cmark/build/src/libcmark.dylib +0 -0
  161. data/ext/commonmarker/cmark/build/src/libcmark.pc +10 -0
  162. data/ext/commonmarker/cmark/build/testdir/CMakeFiles/CMakeDirectoryInformation.cmake +16 -0
  163. data/ext/commonmarker/cmark/build/testdir/CMakeFiles/progress.marks +1 -0
  164. data/ext/commonmarker/cmark/build/testdir/CTestTestfile.cmake +12 -0
  165. data/ext/commonmarker/cmark/build/testdir/Makefile +181 -0
  166. data/ext/commonmarker/cmark/build/testdir/cmake_install.cmake +29 -0
  167. data/ext/commonmarker/cmark/changelog.txt +153 -0
  168. data/ext/commonmarker/cmark/data/CaseFolding-3.2.0.txt +912 -0
  169. data/ext/commonmarker/cmark/man/CMakeLists.txt +8 -0
  170. data/ext/commonmarker/cmark/man/make_man_page.py +131 -0
  171. data/ext/commonmarker/cmark/man/man1/cmark.1 +54 -0
  172. data/ext/commonmarker/cmark/man/man3/cmark.3 +583 -0
  173. data/ext/commonmarker/cmark/nmake.bat +1 -0
  174. data/ext/commonmarker/cmark/src/CMakeLists.txt +166 -0
  175. data/ext/commonmarker/cmark/src/bench.h +27 -0
  176. data/ext/commonmarker/cmark/src/blocks.c +887 -0
  177. data/ext/commonmarker/cmark/src/buffer.c +381 -0
  178. data/ext/commonmarker/cmark/src/buffer.h +113 -0
  179. data/ext/commonmarker/cmark/src/case_fold_switch.inc +2637 -0
  180. data/ext/commonmarker/cmark/src/chunk.h +110 -0
  181. data/ext/commonmarker/cmark/src/cmark.c +24 -0
  182. data/ext/commonmarker/cmark/src/cmark.h +565 -0
  183. data/ext/commonmarker/cmark/src/cmark_ctype.c +53 -0
  184. data/ext/commonmarker/cmark/src/cmark_ctype.h +24 -0
  185. data/ext/commonmarker/cmark/src/cmark_version.h.in +7 -0
  186. data/ext/commonmarker/cmark/src/commonmark.c +607 -0
  187. data/ext/commonmarker/cmark/src/config.h.in +23 -0
  188. data/ext/commonmarker/cmark/src/debug.h +36 -0
  189. data/ext/commonmarker/cmark/src/houdini.h +52 -0
  190. data/ext/commonmarker/cmark/src/houdini_href_e.c +107 -0
  191. data/ext/commonmarker/cmark/src/houdini_html_e.c +81 -0
  192. data/ext/commonmarker/cmark/src/houdini_html_u.c +116 -0
  193. data/ext/commonmarker/cmark/src/html.c +322 -0
  194. data/ext/commonmarker/cmark/src/html_unescape.gperf +2130 -0
  195. data/ext/commonmarker/cmark/src/html_unescape.h +13375 -0
  196. data/ext/commonmarker/cmark/src/inlines.c +1147 -0
  197. data/ext/commonmarker/cmark/src/inlines.h +19 -0
  198. data/ext/commonmarker/cmark/src/iterator.c +148 -0
  199. data/ext/commonmarker/cmark/src/iterator.h +25 -0
  200. data/ext/commonmarker/cmark/src/libcmark.pc.in +10 -0
  201. data/ext/commonmarker/cmark/src/main.c +191 -0
  202. data/ext/commonmarker/cmark/src/man.c +287 -0
  203. data/ext/commonmarker/cmark/src/node.c +873 -0
  204. data/ext/commonmarker/cmark/src/node.h +82 -0
  205. data/ext/commonmarker/cmark/src/parser.h +29 -0
  206. data/ext/commonmarker/cmark/src/references.c +154 -0
  207. data/ext/commonmarker/cmark/src/references.h +37 -0
  208. data/ext/commonmarker/cmark/src/scanners.c +15291 -0
  209. data/ext/commonmarker/cmark/src/scanners.h +41 -0
  210. data/ext/commonmarker/cmark/src/scanners.re +247 -0
  211. data/ext/commonmarker/cmark/src/utf8.c +452 -0
  212. data/ext/commonmarker/cmark/src/utf8.h +22 -0
  213. data/ext/commonmarker/cmark/src/xml.c +170 -0
  214. data/ext/commonmarker/cmark/test/CMakeLists.txt +53 -0
  215. data/ext/commonmarker/cmark/test/afl_dictionary/asterisk +1 -0
  216. data/ext/commonmarker/cmark/test/afl_dictionary/attr_generic +1 -0
  217. data/ext/commonmarker/cmark/test/afl_dictionary/attr_href +1 -0
  218. data/ext/commonmarker/cmark/test/afl_dictionary/attr_xml_lang +1 -0
  219. data/ext/commonmarker/cmark/test/afl_dictionary/attr_xmlns +1 -0
  220. data/ext/commonmarker/cmark/test/afl_dictionary/backslash +1 -0
  221. data/ext/commonmarker/cmark/test/afl_dictionary/backtick +1 -0
  222. data/ext/commonmarker/cmark/test/afl_dictionary/colon +1 -0
  223. data/ext/commonmarker/cmark/test/afl_dictionary/dashes +1 -0
  224. data/ext/commonmarker/cmark/test/afl_dictionary/double_quote +1 -0
  225. data/ext/commonmarker/cmark/test/afl_dictionary/entity_builtin +1 -0
  226. data/ext/commonmarker/cmark/test/afl_dictionary/entity_decimal +1 -0
  227. data/ext/commonmarker/cmark/test/afl_dictionary/entity_external +1 -0
  228. data/ext/commonmarker/cmark/test/afl_dictionary/entity_hex +1 -0
  229. data/ext/commonmarker/cmark/test/afl_dictionary/equals +1 -0
  230. data/ext/commonmarker/cmark/test/afl_dictionary/exclamation +1 -0
  231. data/ext/commonmarker/cmark/test/afl_dictionary/greater_than +1 -0
  232. data/ext/commonmarker/cmark/test/afl_dictionary/hash +1 -0
  233. data/ext/commonmarker/cmark/test/afl_dictionary/hyphen +0 -0
  234. data/ext/commonmarker/cmark/test/afl_dictionary/indent +1 -0
  235. data/ext/commonmarker/cmark/test/afl_dictionary/left_bracket +1 -0
  236. data/ext/commonmarker/cmark/test/afl_dictionary/left_paren +1 -0
  237. data/ext/commonmarker/cmark/test/afl_dictionary/less_than +1 -0
  238. data/ext/commonmarker/cmark/test/afl_dictionary/plus +1 -0
  239. data/ext/commonmarker/cmark/test/afl_dictionary/right_bracket +1 -0
  240. data/ext/commonmarker/cmark/test/afl_dictionary/right_paren +1 -0
  241. data/ext/commonmarker/cmark/test/afl_dictionary/single_quote +1 -0
  242. data/ext/commonmarker/cmark/test/afl_dictionary/string_any +1 -0
  243. data/ext/commonmarker/cmark/test/afl_dictionary/string_brackets +1 -0
  244. data/ext/commonmarker/cmark/test/afl_dictionary/string_cdata +1 -0
  245. data/ext/commonmarker/cmark/test/afl_dictionary/string_dashes +1 -0
  246. data/ext/commonmarker/cmark/test/afl_dictionary/string_empty_dblquotes +1 -0
  247. data/ext/commonmarker/cmark/test/afl_dictionary/string_empty_quotes +1 -0
  248. data/ext/commonmarker/cmark/test/afl_dictionary/string_idrefs +1 -0
  249. data/ext/commonmarker/cmark/test/afl_dictionary/string_parentheses +1 -0
  250. data/ext/commonmarker/cmark/test/afl_dictionary/string_pcdata +1 -0
  251. data/ext/commonmarker/cmark/test/afl_dictionary/tag_cdata +1 -0
  252. data/ext/commonmarker/cmark/test/afl_dictionary/tag_close +1 -0
  253. data/ext/commonmarker/cmark/test/afl_dictionary/tag_doctype +1 -0
  254. data/ext/commonmarker/cmark/test/afl_dictionary/tag_element +1 -0
  255. data/ext/commonmarker/cmark/test/afl_dictionary/tag_entity +1 -0
  256. data/ext/commonmarker/cmark/test/afl_dictionary/tag_notation +1 -0
  257. data/ext/commonmarker/cmark/test/afl_dictionary/tag_open +1 -0
  258. data/ext/commonmarker/cmark/test/afl_dictionary/tag_open_close +1 -0
  259. data/ext/commonmarker/cmark/test/afl_dictionary/tag_open_exclamation +1 -0
  260. data/ext/commonmarker/cmark/test/afl_dictionary/tag_open_q +1 -0
  261. data/ext/commonmarker/cmark/test/afl_dictionary/tag_sq2_close +1 -0
  262. data/ext/commonmarker/cmark/test/afl_dictionary/tag_xml_q +1 -0
  263. data/ext/commonmarker/cmark/test/afl_dictionary/underscore +1 -0
  264. data/ext/commonmarker/cmark/test/afl_test_cases/test.md +36 -0
  265. data/ext/commonmarker/cmark/test/cmark.py +40 -0
  266. data/ext/commonmarker/cmark/test/normalize.py +179 -0
  267. data/ext/commonmarker/cmark/test/pathological_tests.py +63 -0
  268. data/ext/commonmarker/cmark/test/roundtrip.sh +2 -0
  269. data/ext/commonmarker/cmark/test/smart_punct.txt +96 -0
  270. data/ext/commonmarker/cmark/test/spec.txt +7505 -0
  271. data/ext/commonmarker/cmark/test/spec_tests.py +139 -0
  272. data/ext/commonmarker/cmark/toolchain-mingw32.cmake +17 -0
  273. data/ext/commonmarker/cmark/tools/mkcasefold.pl +22 -0
  274. data/ext/commonmarker/cmark/wrappers/wrapper.lua +239 -0
  275. data/ext/commonmarker/cmark/wrappers/wrapper.py +37 -0
  276. data/ext/commonmarker/cmark/wrappers/wrapper.rb +15 -0
  277. data/ext/commonmarker/cmark/wrappers/wrapper.rkt +190 -0
  278. data/ext/commonmarker/commonmarker.c +165 -0
  279. data/ext/commonmarker/commonmarker.h +11 -0
  280. data/ext/commonmarker/extconf.rb +18 -0
  281. data/lib/commonmarker/config.rb +20 -0
  282. data/lib/commonmarker/version.rb +3 -0
  283. data/lib/commonmarker.rb +588 -0
  284. data/test/benchmark.rb +30 -0
  285. data/test/spec_tests.json +4074 -0
  286. data/test/test_basics.rb +44 -0
  287. data/test/test_helper.rb +5 -0
  288. data/test/test_maliciousness.rb +9 -0
  289. data/test/test_pathological_inputs.rb +52 -0
  290. data/test/test_spec.rb +20 -0
  291. metadata +399 -0
@@ -0,0 +1,53 @@
1
+ #include <stdint.h>
2
+
3
+ #include "cmark_ctype.h"
4
+
5
+ /** 1 = space, 2 = punct, 3 = digit, 4 = alpha, 0 = other
6
+ */
7
+ static const int8_t cmark_ctype_class[256] = {
8
+ /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
9
+ /* 0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0,
10
+ /* 1 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
11
+ /* 2 */ 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
12
+ /* 3 */ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2,
13
+ /* 4 */ 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
14
+ /* 5 */ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 2,
15
+ /* 6 */ 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
16
+ /* 7 */ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 0,
17
+ /* 8 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
18
+ /* 9 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
19
+ /* a */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
20
+ /* b */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
21
+ /* c */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
22
+ /* d */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
23
+ /* e */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
24
+ /* f */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
25
+ };
26
+
27
+ /**
28
+ * Returns 1 if c is a "whitespace" character as defined by the spec.
29
+ */
30
+ int cmark_isspace(char c)
31
+ {
32
+ return cmark_ctype_class[(int8_t)c] == 1;
33
+ }
34
+
35
+ /**
36
+ * Returns 1 if c is an ascii punctuation character.
37
+ */
38
+ int cmark_ispunct(char c)
39
+ {
40
+ return cmark_ctype_class[(int8_t)c] == 2;
41
+ }
42
+
43
+ int cmark_isalnum(char c)
44
+ {
45
+ int8_t result;
46
+ result = cmark_ctype_class[(int8_t)c];
47
+ return (result == 3 || result == 4);
48
+ }
49
+
50
+ int cmark_isdigit(char c)
51
+ {
52
+ return cmark_ctype_class[(int8_t)c] == 3;
53
+ }
@@ -0,0 +1,24 @@
1
+ #ifndef CMARK_CMARK_CTYPE_H
2
+ #define CMARK_CMARK_CTYPE_H
3
+
4
+ #ifdef __cplusplus
5
+ extern "C" {
6
+ #endif
7
+
8
+ /** Locale-independent versions of functions from ctype.h.
9
+ * We want cmark to behave the same no matter what the system locale.
10
+ */
11
+
12
+ int cmark_isspace(char c);
13
+
14
+ int cmark_ispunct(char c);
15
+
16
+ int cmark_isalnum(char c);
17
+
18
+ int cmark_isdigit(char c);
19
+
20
+ #ifdef __cplusplus
21
+ }
22
+ #endif
23
+
24
+ #endif
@@ -0,0 +1,7 @@
1
+ #ifndef CMARK_VERSION_H
2
+ #define CMARK_VERSION_H
3
+
4
+ #define CMARK_VERSION ((@PROJECT_VERSION_MAJOR@ << 16) | (@PROJECT_VERSION_MINOR@ << 8) | @PROJECT_VERSION_PATCH@)
5
+ #define CMARK_VERSION_STRING "@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@"
6
+
7
+ #endif
@@ -0,0 +1,607 @@
1
+ #include <stdlib.h>
2
+ #include <stdio.h>
3
+ #include <string.h>
4
+ #include <assert.h>
5
+ #include <ctype.h>
6
+
7
+ #include "config.h"
8
+ #include "cmark.h"
9
+ #include "node.h"
10
+ #include "buffer.h"
11
+ #include "utf8.h"
12
+ #include "scanners.h"
13
+
14
+ // Functions to convert cmark_nodes to commonmark strings.
15
+
16
+ struct render_state {
17
+ int options;
18
+ cmark_strbuf* buffer;
19
+ cmark_strbuf* prefix;
20
+ int column;
21
+ int width;
22
+ int need_cr;
23
+ int last_breakable;
24
+ bool begin_line;
25
+ bool no_wrap;
26
+ bool in_tight_list_item;
27
+ };
28
+
29
+ static inline void cr(struct render_state *state)
30
+ {
31
+ if (state->need_cr < 1) {
32
+ state->need_cr = 1;
33
+ }
34
+ }
35
+
36
+ static inline void blankline(struct render_state *state)
37
+ {
38
+ if (state->need_cr < 2) {
39
+ state->need_cr = 2;
40
+ }
41
+ }
42
+
43
+ typedef enum {
44
+ LITERAL,
45
+ NORMAL,
46
+ TITLE,
47
+ URL
48
+ } escaping;
49
+
50
+ static inline bool
51
+ needs_escaping(escaping escape,
52
+ int32_t c,
53
+ unsigned char next_c,
54
+ struct render_state *state)
55
+ {
56
+ if (escape == NORMAL) {
57
+ return (c == '*' || c == '_' || c == '[' || c == ']' ||
58
+ c == '<' || c == '>' || c == '\\' || c == '`' ||
59
+ (c == '&' && isalpha(next_c)) ||
60
+ (c == '!' && next_c == '[') ||
61
+ (state->begin_line &&
62
+ (c == '-' || c == '+' || c == '#' || c == '=')) ||
63
+ (c == '#' && (isspace(next_c) || next_c == '\0')) ||
64
+ ((c == '.' || c == ')') &&
65
+ isdigit(state->buffer->ptr[state->buffer->size - 1])));
66
+ } else if (escape == TITLE) {
67
+ return (c == '`' || c == '<' || c == '>' || c == '"' ||
68
+ c == '\\');
69
+ } else if (escape == URL) {
70
+ return (c == '`' || c == '<' || c == '>' || isspace(c) ||
71
+ c == '\\' || c == ')' || c == '(');
72
+ } else {
73
+ return false;
74
+ }
75
+ }
76
+
77
+ static inline void out(struct render_state *state,
78
+ cmark_chunk str,
79
+ bool wrap,
80
+ escaping escape)
81
+ {
82
+ unsigned char* source = str.data;
83
+ int length = str.len;
84
+ unsigned char nextc;
85
+ int32_t c;
86
+ int i = 0;
87
+ int len;
88
+ cmark_chunk remainder = cmark_chunk_literal("");
89
+ int k = state->buffer->size - 1;
90
+
91
+ wrap = wrap && !state->no_wrap;
92
+
93
+ if (state->in_tight_list_item && state->need_cr > 1) {
94
+ state->need_cr = 1;
95
+ }
96
+ while (state->need_cr) {
97
+ if (k < 0 || state->buffer->ptr[k] == '\n') {
98
+ k -= 1;
99
+ } else {
100
+ cmark_strbuf_putc(state->buffer, '\n');
101
+ if (state->need_cr > 1) {
102
+ cmark_strbuf_put(state->buffer, state->prefix->ptr,
103
+ state->prefix->size);
104
+ }
105
+ }
106
+ state->column = 0;
107
+ state->begin_line = true;
108
+ state->need_cr -= 1;
109
+ }
110
+
111
+ while (i < length) {
112
+ if (state->begin_line) {
113
+ cmark_strbuf_put(state->buffer, state->prefix->ptr,
114
+ state->prefix->size);
115
+ // note: this assumes prefix is ascii:
116
+ state->column = state->prefix->size;
117
+ }
118
+
119
+ len = utf8proc_iterate(source + i, length - i, &c);
120
+ if (len == -1) { // error condition
121
+ return; // return without rendering rest of string
122
+ }
123
+ nextc = source[i + len];
124
+ if (c == 32 && wrap) {
125
+ if (!state->begin_line) {
126
+ cmark_strbuf_putc(state->buffer, ' ');
127
+ state->column += 1;
128
+ state->begin_line = false;
129
+ state->last_breakable = state->buffer->size -
130
+ 1;
131
+ // skip following spaces
132
+ while (source[i + 1] == ' ') {
133
+ i++;
134
+ }
135
+ }
136
+
137
+ } else if (c == 10) {
138
+ cmark_strbuf_putc(state->buffer, '\n');
139
+ state->column = 0;
140
+ state->begin_line = true;
141
+ state->last_breakable = 0;
142
+ } else if (needs_escaping(escape, c, nextc, state)) {
143
+ if (isspace(c)) {
144
+ // use percent encoding for spaces
145
+ cmark_strbuf_printf(state->buffer, "%%%2x", c);
146
+ state->column += 3;
147
+ } else {
148
+ cmark_strbuf_putc(state->buffer, '\\');
149
+ utf8proc_encode_char(c, state->buffer);
150
+ state->column += 2;
151
+ }
152
+ state->begin_line = false;
153
+ } else {
154
+ utf8proc_encode_char(c, state->buffer);
155
+ state->column += 1;
156
+ state->begin_line = false;
157
+ }
158
+
159
+ // If adding the character went beyond width, look for an
160
+ // earlier place where the line could be broken:
161
+ if (state->width > 0 &&
162
+ state->column > state->width &&
163
+ !state->begin_line &&
164
+ state->last_breakable > 0) {
165
+
166
+ // copy from last_breakable to remainder
167
+ cmark_chunk_set_cstr(&remainder, (char *) state->buffer->ptr + state->last_breakable + 1);
168
+ // truncate at last_breakable
169
+ cmark_strbuf_truncate(state->buffer, state->last_breakable);
170
+ // add newline, prefix, and remainder
171
+ cmark_strbuf_putc(state->buffer, '\n');
172
+ cmark_strbuf_put(state->buffer, state->prefix->ptr,
173
+ state->prefix->size);
174
+ cmark_strbuf_put(state->buffer, remainder.data, remainder.len);
175
+ state->column = state->prefix->size + remainder.len;
176
+ cmark_chunk_free(&remainder);
177
+ state->last_breakable = 0;
178
+ state->begin_line = false;
179
+ }
180
+
181
+ i += len;
182
+ }
183
+ }
184
+
185
+ static void lit(struct render_state *state, char *s, bool wrap)
186
+ {
187
+ cmark_chunk str = cmark_chunk_literal(s);
188
+ out(state, str, wrap, LITERAL);
189
+ }
190
+
191
+ static int
192
+ longest_backtick_sequence(cmark_chunk *code)
193
+ {
194
+ int longest = 0;
195
+ int current = 0;
196
+ int i = 0;
197
+ while (i <= code->len) {
198
+ if (code->data[i] == '`') {
199
+ current++;
200
+ } else {
201
+ if (current > longest) {
202
+ longest = current;
203
+ }
204
+ current = 0;
205
+ }
206
+ i++;
207
+ }
208
+ return longest;
209
+ }
210
+
211
+ static int
212
+ shortest_unused_backtick_sequence(cmark_chunk *code)
213
+ {
214
+ int32_t used = 1;
215
+ int current = 0;
216
+ int i = 0;
217
+ while (i <= code->len) {
218
+ if (code->data[i] == '`') {
219
+ current++;
220
+ } else {
221
+ if (current) {
222
+ used |= (1 << current);
223
+ }
224
+ current = 0;
225
+ }
226
+ i++;
227
+ }
228
+ // return number of first bit that is 0:
229
+ i = 0;
230
+ while (used & 1) {
231
+ used = used >> 1;
232
+ i++;
233
+ }
234
+ return i;
235
+ }
236
+
237
+ static bool
238
+ is_autolink(cmark_node *node)
239
+ {
240
+ const char *title;
241
+ const char *url;
242
+
243
+ if (node->type != CMARK_NODE_LINK) {
244
+ return false;
245
+ }
246
+
247
+ url = cmark_node_get_url(node);
248
+ if (url == NULL ||
249
+ _scan_scheme((unsigned char *)url) == 0) {
250
+ return false;
251
+ }
252
+
253
+ title = cmark_node_get_title(node);
254
+ // if it has a title, we can't treat it as an autolink:
255
+ if (title != NULL && strlen(title) > 0) {
256
+ return false;
257
+ }
258
+ cmark_consolidate_text_nodes(node);
259
+ return (strncmp(url,
260
+ (char*)node->as.literal.data,
261
+ node->as.literal.len) == 0);
262
+ }
263
+
264
+ // if node is a block node, returns node.
265
+ // otherwise returns first block-level node that is an ancestor of node.
266
+ static cmark_node*
267
+ get_containing_block(cmark_node *node)
268
+ {
269
+ while (node &&
270
+ (node->type < CMARK_NODE_FIRST_BLOCK ||
271
+ node->type > CMARK_NODE_LAST_BLOCK)) {
272
+ node = node->parent;
273
+ }
274
+ return node;
275
+ }
276
+
277
+ static int
278
+ S_render_node(cmark_node *node, cmark_event_type ev_type,
279
+ struct render_state *state)
280
+ {
281
+ cmark_node *tmp;
282
+ cmark_chunk *code;
283
+ int list_number;
284
+ cmark_delim_type list_delim;
285
+ int numticks;
286
+ int i;
287
+ bool entering = (ev_type == CMARK_EVENT_ENTER);
288
+ const char *info;
289
+ const char *title;
290
+ cmark_strbuf listmarker = GH_BUF_INIT;
291
+ char *emph_delim;
292
+ int marker_width;
293
+
294
+ // Don't adjust tight list status til we've started the list.
295
+ // Otherwise we loose the blank line between a paragraph and
296
+ // a following list.
297
+ if (!(node->type == CMARK_NODE_ITEM && node->prev == NULL &&
298
+ entering)) {
299
+ tmp = get_containing_block(node);
300
+ state->in_tight_list_item =
301
+ (tmp->type == CMARK_NODE_ITEM &&
302
+ cmark_node_get_list_tight(tmp->parent)) ||
303
+ (tmp &&
304
+ tmp->parent &&
305
+ tmp->parent->type == CMARK_NODE_ITEM &&
306
+ cmark_node_get_list_tight(tmp->parent->parent));
307
+ }
308
+
309
+ switch (node->type) {
310
+ case CMARK_NODE_DOCUMENT:
311
+ if (!entering) {
312
+ cmark_strbuf_putc(state->buffer, '\n');
313
+ }
314
+ break;
315
+
316
+ case CMARK_NODE_BLOCK_QUOTE:
317
+ if (entering) {
318
+ lit(state, "> ", false);
319
+ cmark_strbuf_puts(state->prefix, "> ");
320
+ } else {
321
+ cmark_strbuf_truncate(state->prefix,
322
+ state->prefix->size - 2);
323
+ blankline(state);
324
+ }
325
+ break;
326
+
327
+ case CMARK_NODE_LIST:
328
+ if (!entering && node->next &&
329
+ (node->next->type == CMARK_NODE_CODE_BLOCK ||
330
+ node->next->type == CMARK_NODE_LIST)) {
331
+ // this ensures 2 blank lines after list,
332
+ // if before code block or list:
333
+ lit(state, "\n", false);
334
+ state->need_cr = 0;
335
+ }
336
+ break;
337
+
338
+ case CMARK_NODE_ITEM:
339
+ if (cmark_node_get_list_type(node->parent) ==
340
+ CMARK_BULLET_LIST) {
341
+ marker_width = 2;
342
+ } else {
343
+ list_number = cmark_node_get_list_start(node->parent);
344
+ list_delim = cmark_node_get_list_delim(node->parent);
345
+ tmp = node;
346
+ while (tmp->prev) {
347
+ tmp = tmp->prev;
348
+ list_number += 1;
349
+ }
350
+ // we ensure a width of at least 4 so
351
+ // we get nice transition from single digits
352
+ // to double
353
+ cmark_strbuf_printf(&listmarker,
354
+ "%d%s%s", list_number,
355
+ list_delim == CMARK_PAREN_DELIM ?
356
+ ")" : ".",
357
+ list_number < 10 ? " " : " ");
358
+ marker_width = listmarker.size;
359
+ }
360
+ if (entering) {
361
+ if (cmark_node_get_list_type(node->parent) ==
362
+ CMARK_BULLET_LIST) {
363
+ lit(state, "* ", false);
364
+ cmark_strbuf_puts(state->prefix, " ");
365
+ } else {
366
+ lit(state, (char *)listmarker.ptr, false);
367
+ for (i = marker_width; i--;) {
368
+ cmark_strbuf_putc(state->prefix, ' ');
369
+ }
370
+ }
371
+ } else {
372
+ cmark_strbuf_truncate(state->prefix,
373
+ state->prefix->size -
374
+ marker_width);
375
+ cr(state);
376
+ }
377
+ cmark_strbuf_free(&listmarker);
378
+ break;
379
+
380
+ case CMARK_NODE_HEADER:
381
+ if (entering) {
382
+ for (int i = cmark_node_get_header_level(node); i > 0; i--) {
383
+ lit(state, "#", false);
384
+ }
385
+ lit(state, " ", false);
386
+ state->no_wrap = true;
387
+ } else {
388
+ state->no_wrap = false;
389
+ blankline(state);
390
+ }
391
+ break;
392
+
393
+ case CMARK_NODE_CODE_BLOCK:
394
+ blankline(state);
395
+ info = cmark_node_get_fence_info(node);
396
+ code = &node->as.code.literal;
397
+ // use indented form if no info, and code doesn't
398
+ // begin or end with a blank line, and code isn't
399
+ // first thing in a list item
400
+ if ((info == NULL || strlen(info) == 0) &&
401
+ (code->len > 2 &&
402
+ !isspace(code->data[0]) &&
403
+ !(isspace(code->data[code->len - 1]) &&
404
+ isspace(code->data[code->len - 2]))) &&
405
+ !(node->prev == NULL && node->parent &&
406
+ node->parent->type == CMARK_NODE_ITEM)) {
407
+ lit(state, " ", false);
408
+ cmark_strbuf_puts(state->prefix, " ");
409
+ out(state, node->as.code.literal, false, LITERAL);
410
+ cmark_strbuf_truncate(state->prefix,
411
+ state->prefix->size - 4);
412
+ } else {
413
+ numticks = longest_backtick_sequence(code) + 1;
414
+ if (numticks < 3) {
415
+ numticks = 3;
416
+ }
417
+ for (i = 0; i < numticks; i++) {
418
+ lit(state, "`", false);
419
+ }
420
+ lit(state, " ", false);
421
+ out(state, cmark_chunk_literal(info), false, LITERAL);
422
+ cr(state);
423
+ out(state, node->as.code.literal, false, LITERAL);
424
+ cr(state);
425
+ for (i = 0; i < numticks; i++) {
426
+ lit(state, "`", false);
427
+ }
428
+ }
429
+ blankline(state);
430
+ break;
431
+
432
+ case CMARK_NODE_HTML:
433
+ blankline(state);
434
+ out(state, node->as.literal, false, LITERAL);
435
+ blankline(state);
436
+ break;
437
+
438
+ case CMARK_NODE_HRULE:
439
+ blankline(state);
440
+ lit(state, "-----", false);
441
+ blankline(state);
442
+ break;
443
+
444
+ case CMARK_NODE_PARAGRAPH:
445
+ if (!entering) {
446
+ blankline(state);
447
+ }
448
+ break;
449
+
450
+ case CMARK_NODE_TEXT:
451
+ out(state, node->as.literal, true, NORMAL);
452
+ break;
453
+
454
+ case CMARK_NODE_LINEBREAK:
455
+ if (!(CMARK_OPT_HARDBREAKS & state->options)) {
456
+ lit(state, "\\", false);
457
+ }
458
+ cr(state);
459
+ break;
460
+
461
+ case CMARK_NODE_SOFTBREAK:
462
+ if (state->width == 0) {
463
+ cr(state);
464
+ } else {
465
+ lit(state, " ", true);
466
+ }
467
+ break;
468
+
469
+ case CMARK_NODE_CODE:
470
+ code = &node->as.literal;
471
+ numticks = shortest_unused_backtick_sequence(code);
472
+ for (i = 0; i < numticks; i++) {
473
+ lit(state, "`", false);
474
+ }
475
+ if (code->len == 0 || code->data[0] == '`') {
476
+ lit(state, " ", false);
477
+ }
478
+ out(state, node->as.literal, true, LITERAL);
479
+ if (code->len == 0 || code->data[code->len - 1] == '`') {
480
+ lit(state, " ", false);
481
+ }
482
+ for (i = 0; i < numticks; i++) {
483
+ lit(state, "`", false);
484
+ }
485
+ break;
486
+
487
+ case CMARK_NODE_INLINE_HTML:
488
+ out(state, node->as.literal, false, LITERAL);
489
+ break;
490
+
491
+ case CMARK_NODE_STRONG:
492
+ if (entering) {
493
+ lit(state, "**", false);
494
+ } else {
495
+ lit(state, "**", false);
496
+ }
497
+ break;
498
+
499
+ case CMARK_NODE_EMPH:
500
+ // If we have EMPH(EMPH(x)), we need to use *_x_*
501
+ // because **x** is STRONG(x):
502
+ if (node->parent && node->parent->type == CMARK_NODE_EMPH &&
503
+ node->next == NULL && node->prev == NULL) {
504
+ emph_delim = "_";
505
+ } else {
506
+ emph_delim = "*";
507
+ }
508
+ if (entering) {
509
+ lit(state, emph_delim, false);
510
+ } else {
511
+ lit(state, emph_delim, false);
512
+ }
513
+ break;
514
+
515
+ case CMARK_NODE_LINK:
516
+ if (is_autolink(node)) {
517
+ if (entering) {
518
+ lit(state, "<", false);
519
+ if (strncmp(cmark_node_get_url(node),
520
+ "mailto:", 7) == 0) {
521
+ lit(state,
522
+ (char *)cmark_node_get_url(node) + 7,
523
+ false);
524
+ } else {
525
+ lit(state,
526
+ (char *)cmark_node_get_url(node),
527
+ false);
528
+ }
529
+ lit(state, ">", false);
530
+ // return signal to skip contents of node...
531
+ return 0;
532
+ }
533
+ } else {
534
+ if (entering) {
535
+ lit(state, "[", false);
536
+ } else {
537
+ lit(state, "](", false);
538
+ out(state,
539
+ cmark_chunk_literal(cmark_node_get_url(node)),
540
+ false, URL);
541
+ title = cmark_node_get_title(node);
542
+ if (title && strlen(title) > 0) {
543
+ lit(state, " \"", true);
544
+ out(state, cmark_chunk_literal(title),
545
+ false, TITLE);
546
+ lit(state, "\"", false);
547
+ }
548
+ lit(state, ")", false);
549
+ }
550
+ }
551
+ break;
552
+
553
+ case CMARK_NODE_IMAGE:
554
+ if (entering) {
555
+ lit(state, "![", false);
556
+ } else {
557
+ lit(state, "](", false);
558
+ out(state, cmark_chunk_literal(cmark_node_get_url(node)), false, URL);
559
+ title = cmark_node_get_title(node);
560
+ if (title && strlen(title) > 0) {
561
+ lit(state, " \"", true);
562
+ out(state, cmark_chunk_literal(title), false, TITLE);
563
+ lit(state, "\"", false);
564
+ }
565
+ lit(state, ")", false);
566
+ }
567
+ break;
568
+
569
+ default:
570
+ assert(false);
571
+ break;
572
+ }
573
+
574
+ return 1;
575
+ }
576
+
577
+ char *cmark_render_commonmark(cmark_node *root, int options, int width)
578
+ {
579
+ char *result;
580
+ cmark_strbuf commonmark = GH_BUF_INIT;
581
+ cmark_strbuf prefix = GH_BUF_INIT;
582
+ if (CMARK_OPT_HARDBREAKS & options) {
583
+ width = 0;
584
+ }
585
+ struct render_state state = {
586
+ options, &commonmark, &prefix, 0, width,
587
+ 0, 0, true, false, false
588
+ };
589
+ cmark_node *cur;
590
+ cmark_event_type ev_type;
591
+ cmark_iter *iter = cmark_iter_new(root);
592
+
593
+ while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) {
594
+ cur = cmark_iter_get_node(iter);
595
+ if (!S_render_node(cur, ev_type, &state)) {
596
+ // a false value causes us to skip processing
597
+ // the node's contents. this is used for
598
+ // autolinks.
599
+ cmark_iter_reset(iter, cur, CMARK_EVENT_EXIT);
600
+ }
601
+ }
602
+ result = (char *)cmark_strbuf_detach(&commonmark);
603
+
604
+ cmark_strbuf_free(&prefix);
605
+ cmark_iter_free(iter);
606
+ return result;
607
+ }
@@ -0,0 +1,23 @@
1
+ #cmakedefine HAVE_STDBOOL_H
2
+
3
+ #ifdef HAVE_STDBOOL_H
4
+ #include <stdbool.h>
5
+ #elif !defined(__cplusplus)
6
+ typedef char bool;
7
+ #endif
8
+
9
+ #cmakedefine HAVE___BUILTIN_EXPECT
10
+
11
+ #cmakedefine HAVE___ATTRIBUTE__
12
+
13
+ #ifdef HAVE___ATTRIBUTE__
14
+ #define CMARK_ATTRIBUTE(list) __attribute__ (list)
15
+ #else
16
+ #define CMARK_ATTRIBUTE(list)
17
+ #endif
18
+
19
+ #cmakedefine HAVE_VA_COPY
20
+
21
+ #ifndef HAVE_VA_COPY
22
+ #define va_copy(dest, src) ((dest) = (src))
23
+ #endif