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,139 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+ import sys
5
+ from difflib import unified_diff
6
+ import argparse
7
+ import re
8
+ import json
9
+ from cmark import CMark
10
+ from normalize import normalize_html
11
+
12
+ if __name__ == "__main__":
13
+ parser = argparse.ArgumentParser(description='Run cmark tests.')
14
+ parser.add_argument('-p', '--program', dest='program', nargs='?', default=None,
15
+ help='program to test')
16
+ parser.add_argument('-s', '--spec', dest='spec', nargs='?', default='test/spec.txt',
17
+ help='path to spec')
18
+ parser.add_argument('-P', '--pattern', dest='pattern', nargs='?',
19
+ default=None, help='limit to sections matching regex pattern')
20
+ parser.add_argument('--library-dir', dest='library_dir', nargs='?',
21
+ default=None, help='directory containing dynamic library')
22
+ parser.add_argument('--no-normalize', dest='normalize',
23
+ action='store_const', const=False, default=True,
24
+ help='do not normalize HTML')
25
+ parser.add_argument('-d', '--dump-tests', dest='dump_tests',
26
+ action='store_const', const=True, default=False,
27
+ help='dump tests in JSON format')
28
+ parser.add_argument('--debug-normalization', dest='debug_normalization',
29
+ action='store_const', const=True,
30
+ default=False, help='filter stdin through normalizer for testing')
31
+ parser.add_argument('-n', '--number', type=int, default=None,
32
+ help='only consider the test with the given number')
33
+ args = parser.parse_args(sys.argv[1:])
34
+
35
+ def print_test_header(headertext, example_number, start_line, end_line):
36
+ print("Example %d (lines %d-%d) %s" % (example_number,start_line,end_line,headertext))
37
+
38
+ def do_test(test, normalize, result_counts):
39
+ [retcode, actual_html, err] = cmark.to_html(test['markdown'])
40
+ if retcode == 0:
41
+ expected_html = test['html']
42
+ unicode_error = None
43
+ if normalize:
44
+ try:
45
+ passed = normalize_html(actual_html) == normalize_html(expected_html)
46
+ except UnicodeDecodeError as e:
47
+ unicode_error = e
48
+ passed = False
49
+ else:
50
+ passed = actual_html == expected_html
51
+ if passed:
52
+ result_counts['pass'] += 1
53
+ else:
54
+ print_test_header(test['section'], test['example'], test['start_line'], test['end_line'])
55
+ sys.stdout.write(test['markdown'])
56
+ if unicode_error:
57
+ print("Unicode error: " + str(unicode_error))
58
+ print("Expected: " + repr(expected_html))
59
+ print("Got: " + repr(actual_html))
60
+ else:
61
+ expected_html_lines = expected_html.splitlines(True)
62
+ actual_html_lines = actual_html.splitlines(True)
63
+ for diffline in unified_diff(expected_html_lines, actual_html_lines,
64
+ "expected HTML", "actual HTML"):
65
+ sys.stdout.write(diffline)
66
+ sys.stdout.write('\n')
67
+ result_counts['fail'] += 1
68
+ else:
69
+ print_test_header(test['section'], test['example'], test['start_line'], test['end_line'])
70
+ print("program returned error code %d" % retcode)
71
+ print(err)
72
+ result_counts['error'] += 1
73
+
74
+ def get_tests(specfile):
75
+ line_number = 0
76
+ start_line = 0
77
+ end_line = 0
78
+ example_number = 0
79
+ markdown_lines = []
80
+ html_lines = []
81
+ state = 0 # 0 regular text, 1 markdown example, 2 html output
82
+ headertext = ''
83
+ tests = []
84
+
85
+ header_re = re.compile('#+ ')
86
+
87
+ with open(specfile, 'r', encoding='utf-8') as specf:
88
+ for line in specf:
89
+ line_number = line_number + 1
90
+ if state == 0 and re.match(header_re, line):
91
+ headertext = header_re.sub('', line).strip()
92
+ if line.strip() == ".":
93
+ state = (state + 1) % 3
94
+ if state == 0:
95
+ example_number = example_number + 1
96
+ end_line = line_number
97
+ tests.append({
98
+ "markdown":''.join(markdown_lines).replace('→',"\t"),
99
+ "html":''.join(html_lines),
100
+ "example": example_number,
101
+ "start_line": start_line,
102
+ "end_line": end_line,
103
+ "section": headertext})
104
+ start_line = 0
105
+ markdown_lines = []
106
+ html_lines = []
107
+ elif state == 1:
108
+ if start_line == 0:
109
+ start_line = line_number - 1
110
+ markdown_lines.append(line)
111
+ elif state == 2:
112
+ html_lines.append(line)
113
+ return tests
114
+
115
+ if __name__ == "__main__":
116
+ if args.debug_normalization:
117
+ print(normalize_html(sys.stdin.read()))
118
+ exit(0)
119
+
120
+ all_tests = get_tests(args.spec)
121
+ if args.pattern:
122
+ pattern_re = re.compile(args.pattern, re.IGNORECASE)
123
+ else:
124
+ pattern_re = re.compile('.')
125
+ tests = [ test for test in all_tests if re.search(pattern_re, test['section']) and (not args.number or test['example'] == args.number) ]
126
+ if args.dump_tests:
127
+ print(json.dumps(tests, ensure_ascii=False, indent=2))
128
+ exit(0)
129
+ else:
130
+ skipped = len(all_tests) - len(tests)
131
+ cmark = CMark(prog=args.program, library_dir=args.library_dir)
132
+ result_counts = {'pass': 0, 'fail': 0, 'error': 0, 'skip': skipped}
133
+ for test in tests:
134
+ do_test(test, args.normalize, result_counts)
135
+ print("{pass} passed, {fail} failed, {error} errored, {skip} skipped".format(**result_counts))
136
+ if result_counts['fail'] == 0 and result_counts['error'] == 0:
137
+ exit(0)
138
+ else:
139
+ exit(1)
@@ -0,0 +1,17 @@
1
+ # the name of the target operating system
2
+ SET(CMAKE_SYSTEM_NAME Windows)
3
+
4
+ # which compilers to use for C and C++
5
+ SET(CMAKE_C_COMPILER i586-mingw32msvc-gcc)
6
+ SET(CMAKE_CXX_COMPILER i586-mingw32msvc-g++)
7
+ SET(CMAKE_RC_COMPILER i586-mingw32msvc-windres)
8
+
9
+ # here is the target environment located
10
+ SET(CMAKE_FIND_ROOT_PATH /usr/i586-mingw32msvc "${CMAKE_SOURCE_DIR}/windows")
11
+
12
+ # adjust the default behaviour of the FIND_XXX() commands:
13
+ # search headers and libraries in the target environment, search
14
+ # programs in the host environment
15
+ set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
16
+ set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
17
+ set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
@@ -0,0 +1,22 @@
1
+ binmode STDOUT;
2
+ print(" switch (c) {\n");
3
+ my $lastchar = "";
4
+ while (<STDIN>) {
5
+ if (/^[A-F0-9]/ and / [CF]; /) {
6
+ my ($char, $type, $subst) = m/([A-F0-9]+); ([CF]); ([^;]+)/;
7
+ if ($char eq $lastchar) {
8
+ break;
9
+ }
10
+ my @subst = $subst =~ m/(\w+)/g;
11
+ printf(" case 0x%s:\n", $char);
12
+ foreach (@subst) {
13
+ printf(" bufpush(0x%s);\n", $_);
14
+ }
15
+ printf(" break;\n");
16
+ $lastchar = $char;
17
+ }
18
+ }
19
+ printf(" default:\n");
20
+ printf(" bufpush(c);\n");
21
+ print(" }\n");
22
+
@@ -0,0 +1,239 @@
1
+ #!/usr/bin/env luajit
2
+
3
+ local ffi = require("ffi")
4
+
5
+ cmark = ffi.load("libcmark")
6
+
7
+ ffi.cdef[[
8
+ char *cmark_markdown_to_html(const char *text, int len, int options);
9
+
10
+ typedef enum {
11
+ /* Error status */
12
+ CMARK_NODE_NONE,
13
+
14
+ /* Block */
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
+
25
+ CMARK_NODE_FIRST_BLOCK = CMARK_NODE_DOCUMENT,
26
+ CMARK_NODE_LAST_BLOCK = CMARK_NODE_HRULE,
27
+
28
+ /* Inline */
29
+ CMARK_NODE_TEXT,
30
+ CMARK_NODE_SOFTBREAK,
31
+ CMARK_NODE_LINEBREAK,
32
+ CMARK_NODE_CODE,
33
+ CMARK_NODE_INLINE_HTML,
34
+ CMARK_NODE_EMPH,
35
+ CMARK_NODE_STRONG,
36
+ CMARK_NODE_LINK,
37
+ CMARK_NODE_IMAGE,
38
+
39
+ CMARK_NODE_FIRST_INLINE = CMARK_NODE_TEXT,
40
+ CMARK_NODE_LAST_INLINE = CMARK_NODE_IMAGE,
41
+ } cmark_node_type;
42
+
43
+
44
+ typedef enum {
45
+ CMARK_NO_LIST,
46
+ CMARK_BULLET_LIST,
47
+ CMARK_ORDERED_LIST
48
+ } cmark_list_type;
49
+
50
+ typedef enum {
51
+ CMARK_NO_DELIM,
52
+ CMARK_PERIOD_DELIM,
53
+ CMARK_PAREN_DELIM
54
+ } cmark_delim_type;
55
+
56
+ typedef struct cmark_node cmark_node;
57
+ typedef struct cmark_parser cmark_parser;
58
+ typedef struct cmark_iter cmark_iter;
59
+
60
+ typedef enum {
61
+ CMARK_EVENT_NONE,
62
+ CMARK_EVENT_DONE,
63
+ CMARK_EVENT_ENTER,
64
+ CMARK_EVENT_EXIT
65
+ } cmark_event_type;
66
+
67
+ cmark_node*
68
+ cmark_node_new(cmark_node_type type);
69
+
70
+ void
71
+ cmark_node_free(cmark_node *node);
72
+
73
+ cmark_node*
74
+ cmark_node_next(cmark_node *node);
75
+
76
+ cmark_node*
77
+ cmark_node_previous(cmark_node *node);
78
+
79
+ cmark_node*
80
+ cmark_node_parent(cmark_node *node);
81
+
82
+ cmark_node*
83
+ cmark_node_first_child(cmark_node *node);
84
+
85
+ cmark_node*
86
+ cmark_node_last_child(cmark_node *node);
87
+
88
+ cmark_iter*
89
+ cmark_iter_new(cmark_node *root);
90
+
91
+ void
92
+ cmark_iter_free(cmark_iter *iter);
93
+
94
+ cmark_event_type
95
+ cmark_iter_next(cmark_iter *iter);
96
+
97
+ cmark_node*
98
+ cmark_iter_get_node(cmark_iter *iter);
99
+
100
+ cmark_event_type
101
+ cmark_iter_get_event_type(cmark_iter *iter);
102
+
103
+ cmark_node*
104
+ cmark_iter_get_root(cmark_iter *iter);
105
+
106
+ void
107
+ cmark_iter_reset(cmark_iter *iter, cmark_node *current,
108
+ cmark_event_type event_type);
109
+
110
+ void*
111
+ cmark_node_get_user_data(cmark_node *node);
112
+
113
+ int
114
+ cmark_node_set_user_data(cmark_node *node, void *user_data);
115
+
116
+ cmark_node_type
117
+ cmark_node_get_type(cmark_node *node);
118
+
119
+ const char*
120
+ cmark_node_get_type_string(cmark_node *node);
121
+
122
+ const char*
123
+ cmark_node_get_literal(cmark_node *node);
124
+
125
+ int
126
+ cmark_node_set_literal(cmark_node *node, const char *content);
127
+
128
+ int
129
+ cmark_node_get_header_level(cmark_node *node);
130
+
131
+ int
132
+ cmark_node_set_header_level(cmark_node *node, int level);
133
+
134
+ cmark_list_type
135
+ cmark_node_get_list_type(cmark_node *node);
136
+
137
+ int
138
+ cmark_node_set_list_type(cmark_node *node, cmark_list_type type);
139
+
140
+ cmark_delim_type
141
+ cmark_node_get_list_delim(cmark_node *node);
142
+
143
+ int
144
+ cmark_node_set_list_delim(cmark_node *node, cmark_delim_type delim);
145
+
146
+ int
147
+ cmark_node_get_list_start(cmark_node *node);
148
+
149
+ int
150
+ cmark_node_set_list_start(cmark_node *node, int start);
151
+
152
+ int
153
+ cmark_node_get_list_tight(cmark_node *node);
154
+
155
+ int
156
+ cmark_node_set_list_tight(cmark_node *node, int tight);
157
+
158
+ const char*
159
+ cmark_node_get_fence_info(cmark_node *node);
160
+
161
+ int
162
+ cmark_node_set_fence_info(cmark_node *node, const char *info);
163
+
164
+ const char*
165
+ cmark_node_get_url(cmark_node *node);
166
+
167
+ int
168
+ cmark_node_set_url(cmark_node *node, const char *url);
169
+
170
+ const char*
171
+ cmark_node_get_title(cmark_node *node);
172
+
173
+ int
174
+ cmark_node_set_title(cmark_node *node, const char *title);
175
+
176
+ int
177
+ cmark_node_get_start_line(cmark_node *node);
178
+
179
+ int
180
+ cmark_node_get_start_column(cmark_node *node);
181
+
182
+ int
183
+ cmark_node_get_end_line(cmark_node *node);
184
+
185
+ int
186
+ cmark_node_get_end_column(cmark_node *node);
187
+
188
+ void
189
+ cmark_node_unlink(cmark_node *node);
190
+
191
+ int
192
+ cmark_node_insert_before(cmark_node *node, cmark_node *sibling);
193
+
194
+ int
195
+ cmark_node_insert_after(cmark_node *node, cmark_node *sibling);
196
+
197
+ int
198
+ cmark_node_prepend_child(cmark_node *node, cmark_node *child);
199
+
200
+ int
201
+ cmark_node_append_child(cmark_node *node, cmark_node *child);
202
+
203
+ void
204
+ cmark_consolidate_text_nodes(cmark_node *root);
205
+
206
+ cmark_parser *cmark_parser_new(int options);
207
+
208
+ void cmark_parser_free(cmark_parser *parser);
209
+
210
+ void cmark_parser_feed(cmark_parser *parser, const char *buffer, size_t len);
211
+
212
+ cmark_node *cmark_parser_finish(cmark_parser *parser);
213
+
214
+ cmark_node *cmark_parse_document(const char *buffer, size_t len, int options);
215
+
216
+ char *cmark_render_xml(cmark_node *root, int options);
217
+
218
+ char *cmark_render_html(cmark_node *root, int options);
219
+
220
+ char *cmark_render_man(cmark_node *root, int options);
221
+
222
+ char *cmark_render_commonmark(cmark_node *root, int options, int width);
223
+
224
+ extern const int cmark_version;
225
+
226
+ extern const char cmark_version_string[];
227
+
228
+ ]]
229
+
230
+ CMARK_OPT_DEFAULT = 0
231
+ CMARK_OPT_SOURCEPOS = 1
232
+ CMARK_OPT_HARDBREAKS = 2
233
+ CMARK_OPT_NORMALIZE = 4
234
+ CMARK_OPT_SMART = 8
235
+
236
+ local inp = io.read("*all")
237
+ local doc = cmark.cmark_parse_document(inp, string.len(inp), CMARK_OPT_SMART)
238
+ local html = ffi.string(cmark.cmark_render_html(doc, CMARK_OPT_DEFAULT))
239
+ print(html)
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env python
2
+
3
+ # Example for using the shared library from python
4
+ # Will work with either python 2 or python 3
5
+ # Requires cmark library to be installed
6
+
7
+ from ctypes import CDLL, c_char_p, c_long
8
+ import sys
9
+ import platform
10
+
11
+ sysname = platform.system()
12
+
13
+ if sysname == 'Darwin':
14
+ libname = "libcmark.dylib"
15
+ elif sysname == 'Windows':
16
+ libname = "cmark.dll"
17
+ else:
18
+ libname = "libcmark.so"
19
+ cmark = CDLL(libname)
20
+
21
+ markdown = cmark.cmark_markdown_to_html
22
+ markdown.restype = c_char_p
23
+ markdown.argtypes = [c_char_p, c_long, c_long]
24
+
25
+ opts = 8 # CMARK_OPT_PRETTY
26
+
27
+ def md2html(text):
28
+ if sys.version_info >= (3,0):
29
+ textbytes = text.encode('utf-8')
30
+ textlen = len(textbytes)
31
+ return markdown(textbytes, textlen, opts).decode('utf-8')
32
+ else:
33
+ textbytes = text
34
+ textlen = len(text)
35
+ return markdown(textbytes, textlen, opts)
36
+
37
+ sys.stdout.write(md2html(sys.stdin.read()))
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ require 'ffi'
3
+
4
+ module CMark
5
+ extend FFI::Library
6
+ ffi_lib ['libcmark', 'cmark']
7
+ attach_function :cmark_markdown_to_html, [:string, :int, :int], :string
8
+ end
9
+
10
+ def markdown_to_html(s)
11
+ len = s.bytesize
12
+ CMark::cmark_markdown_to_html(s, len, 0)
13
+ end
14
+
15
+ STDOUT.write(markdown_to_html(ARGF.read()))
@@ -0,0 +1,190 @@
1
+ #lang racket/base
2
+
3
+ ;; requires racket >= 5.3 because of submodules
4
+
5
+ ;; Lowlevel interface
6
+
7
+ (module low-level racket/base
8
+
9
+ (require ffi/unsafe ffi/unsafe/define)
10
+
11
+ (provide (all-defined-out))
12
+
13
+ (define-ffi-definer defcmark (ffi-lib "libcmark"))
14
+
15
+ (define _cmark_node_type
16
+ (_enum '(none
17
+ ;; Block
18
+ document block-quote list item code-block
19
+ html paragraph header hrule
20
+ ;; Inline
21
+ text softbreak linebreak code inline-html
22
+ emph strong link image)))
23
+ (define _cmark_list_type
24
+ (_enum '(no_list bullet_list ordered_list)))
25
+ (define _cmark_delim_type
26
+ (_enum '(no_delim period_delim paren_delim)))
27
+ (define _cmark_opts
28
+ (_bitmask '(sourcepos = 1 hardbreaks = 2 normalize = 4 smart = 8)))
29
+
30
+ (define-cpointer-type _node)
31
+
32
+ (defcmark cmark_markdown_to_html
33
+ (_fun [bs : _bytes] [_int = (bytes-length bs)] _cmark_opts
34
+ -> [r : _bytes] -> (begin0 (bytes->string/utf-8 r) (free r))))
35
+
36
+ (defcmark cmark_parse_document
37
+ (_fun [bs : _bytes] [_int = (bytes-length bs)] _cmark_opts
38
+ -> _node))
39
+
40
+ (defcmark cmark_render_html
41
+ (_fun _node _cmark_opts
42
+ -> [r : _bytes] -> (begin0 (bytes->string/utf-8 r) (free r))))
43
+
44
+ (defcmark cmark_node_new (_fun _cmark_node_type -> _node))
45
+ (defcmark cmark_node_free (_fun _node -> _void))
46
+
47
+ (defcmark cmark_node_next (_fun _node -> _node/null))
48
+ (defcmark cmark_node_previous (_fun _node -> _node/null))
49
+ (defcmark cmark_node_parent (_fun _node -> _node/null))
50
+ (defcmark cmark_node_first_child (_fun _node -> _node/null))
51
+ (defcmark cmark_node_last_child (_fun _node -> _node/null))
52
+
53
+ (defcmark cmark_node_get_user_data (_fun _node -> _racket))
54
+ (defcmark cmark_node_set_user_data (_fun _node _racket -> _bool))
55
+ (defcmark cmark_node_get_type (_fun _node -> _cmark_node_type))
56
+ (defcmark cmark_node_get_type_string (_fun _node -> _bytes))
57
+ (defcmark cmark_node_get_literal (_fun _node -> _string))
58
+ (defcmark cmark_node_set_literal (_fun _node _string -> _bool))
59
+ (defcmark cmark_node_get_header_level (_fun _node -> _int))
60
+ (defcmark cmark_node_set_header_level (_fun _node _int -> _bool))
61
+ (defcmark cmark_node_get_list_type (_fun _node -> _cmark_list_type))
62
+ (defcmark cmark_node_set_list_type (_fun _node _cmark_list_type -> _bool))
63
+ (defcmark cmark_node_get_list_delim (_fun _node -> _cmark_delim_type))
64
+ (defcmark cmark_node_set_list_delim (_fun _node _cmark_delim_type -> _bool))
65
+ (defcmark cmark_node_get_list_start (_fun _node -> _int))
66
+ (defcmark cmark_node_set_list_start (_fun _node _int -> _bool))
67
+ (defcmark cmark_node_get_list_tight (_fun _node -> _bool))
68
+ (defcmark cmark_node_set_list_tight (_fun _node _bool -> _bool))
69
+ (defcmark cmark_node_get_fence_info (_fun _node -> _string))
70
+ (defcmark cmark_node_set_fence_info (_fun _node _string -> _bool))
71
+ (defcmark cmark_node_get_url (_fun _node -> _string))
72
+ (defcmark cmark_node_set_url (_fun _node _string -> _bool))
73
+ (defcmark cmark_node_get_title (_fun _node -> _string))
74
+ (defcmark cmark_node_set_title (_fun _node _string -> _bool))
75
+ (defcmark cmark_node_get_start_line (_fun _node -> _int))
76
+ (defcmark cmark_node_get_start_column (_fun _node -> _int))
77
+ (defcmark cmark_node_get_end_line (_fun _node -> _int))
78
+ (defcmark cmark_node_get_end_column (_fun _node -> _int))
79
+
80
+ (defcmark cmark_node_unlink (_fun _node -> _void))
81
+ (defcmark cmark_node_insert_before (_fun _node _node -> _bool))
82
+ (defcmark cmark_node_insert_after (_fun _node _node -> _bool))
83
+ (defcmark cmark_node_prepend_child (_fun _node _node -> _bool))
84
+ (defcmark cmark_node_append_child (_fun _node _node -> _bool))
85
+ (defcmark cmark_consolidate_text_nodes (_fun _node -> _void))
86
+
87
+ )
88
+
89
+ ;; Rackety interface
90
+
91
+ (module high-level racket/base
92
+
93
+ (require (submod ".." low-level) ffi/unsafe)
94
+
95
+ (provide cmark-markdown-to-html)
96
+ (define (cmark-markdown-to-html str [options '(normalize smart)])
97
+ (cmark_markdown_to_html (if (bytes? str) str (string->bytes/utf-8 str))
98
+ options))
99
+
100
+ (require (for-syntax racket/base racket/syntax))
101
+ (define-syntax (make-getter+setter stx)
102
+ (syntax-case stx ()
103
+ [(_ name) (with-syntax ([(getter setter)
104
+ (map (λ(op) (format-id #'name "cmark_node_~a_~a"
105
+ op #'name))
106
+ '(get set))])
107
+ #'(cons getter setter))]))
108
+ (define-syntax-rule (define-getters+setters name [type field ...] ...)
109
+ (define name (list (list 'type (make-getter+setter field) ...) ...)))
110
+ (define-getters+setters getters+setters
111
+ [header header_level] [code-block fence_info]
112
+ [link url title] [image url title]
113
+ [list list_type list_delim list_start list_tight])
114
+
115
+ (provide cmark->sexpr)
116
+ (define (cmark->sexpr node)
117
+ (define text (cmark_node_get_literal node))
118
+ (define type (cmark_node_get_type node))
119
+ (define children
120
+ (let loop ([node (cmark_node_first_child node)])
121
+ (if (not node) '()
122
+ (cons (cmark->sexpr node) (loop (cmark_node_next node))))))
123
+ (define info
124
+ (cond [(assq type getters+setters)
125
+ => (λ(gss) (map (λ(gs) ((car gs) node)) (cdr gss)))]
126
+ [else '()]))
127
+ (define (assert-no what-not b)
128
+ (when b (error 'cmark->sexpr "unexpected ~a in ~s" what-not type)))
129
+ (cond [(memq type '(document paragraph header block-quote list item
130
+ emph strong link image))
131
+ (assert-no 'text text)
132
+ (list type info children)]
133
+ [(memq type '(text code code-block html inline-html
134
+ softbreak linebreak hrule))
135
+ (assert-no 'children (pair? children))
136
+ (list type info text)]
137
+ [else (error 'cmark->sexpr "unknown type: ~s" type)]))
138
+
139
+ (provide sexpr->cmark)
140
+ (define (sexpr->cmark sexpr) ; assumes valid input, as generated by the above
141
+ (define (loop sexpr)
142
+ (define type (car sexpr))
143
+ (define info (cadr sexpr))
144
+ (define data (caddr sexpr))
145
+ (define node (cmark_node_new type))
146
+ (let ([gss (assq type getters+setters)])
147
+ (when gss
148
+ (unless (= (length (cdr gss)) (length info))
149
+ (error 'sexpr->cmark "bad number of info values in ~s" sexpr))
150
+ (for-each (λ(gs x) ((cdr gs) node x)) (cdr gss) info)))
151
+ (cond [(string? data) (cmark_node_set_literal node data)]
152
+ [(not data) (void)]
153
+ [(list? data)
154
+ (for ([child (in-list data)])
155
+ (cmark_node_append_child node (sexpr->cmark child)))]
156
+ [else (error 'sexpr->cmark "bad data in ~s" sexpr)])
157
+ node)
158
+ (define root (loop sexpr))
159
+ (register-finalizer root cmark_node_free)
160
+ root)
161
+
162
+ ;; Registers a `cmark_node_free` finalizer
163
+ (provide cmark-parse-document)
164
+ (define (cmark-parse-document str [options '(normalize smart)])
165
+ (define root (cmark_parse_document
166
+ (if (bytes? str) str (string->bytes/utf-8 str))
167
+ options))
168
+ (register-finalizer root cmark_node_free)
169
+ root)
170
+
171
+ (provide cmark-render-html)
172
+ (define (cmark-render-html root [options '(normalize smart)])
173
+ (cmark_render_html root options)))
174
+
175
+ #; ;; sample use
176
+ (begin
177
+ (require 'high-level racket/string)
178
+ (cmark-render-html
179
+ (cmark-parse-document
180
+ (string-join '("foo"
181
+ "==="
182
+ ""
183
+ "> blah"
184
+ ">"
185
+ "> blah *blah* `bar()` blah:"
186
+ ">"
187
+ "> function foo() {"
188
+ "> bar();"
189
+ "> }")
190
+ "\n"))))