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,887 @@
1
+ #include <stdlib.h>
2
+ #include <assert.h>
3
+ #include <stdio.h>
4
+
5
+ #include "cmark_ctype.h"
6
+ #include "config.h"
7
+ #include "parser.h"
8
+ #include "cmark.h"
9
+ #include "node.h"
10
+ #include "references.h"
11
+ #include "utf8.h"
12
+ #include "scanners.h"
13
+ #include "inlines.h"
14
+ #include "houdini.h"
15
+ #include "buffer.h"
16
+ #include "debug.h"
17
+
18
+ #define CODE_INDENT 4
19
+ #define peek_at(i, n) (i)->data[n]
20
+
21
+ static void
22
+ S_parser_feed(cmark_parser *parser, const unsigned char *buffer, size_t len,
23
+ bool eof);
24
+
25
+ static void
26
+ S_process_line(cmark_parser *parser, const unsigned char *buffer,
27
+ size_t bytes);
28
+
29
+ static cmark_node* make_block(cmark_node_type tag, int start_line, int start_column)
30
+ {
31
+ cmark_node* e;
32
+
33
+ e = (cmark_node *)calloc(1, sizeof(*e));
34
+ if(e != NULL) {
35
+ e->type = tag;
36
+ e->open = true;
37
+ e->start_line = start_line;
38
+ e->start_column = start_column;
39
+ e->end_line = start_line;
40
+ cmark_strbuf_init(&e->string_content, 32);
41
+ }
42
+
43
+ return e;
44
+ }
45
+
46
+ // Create a root document node.
47
+ static cmark_node* make_document()
48
+ {
49
+ cmark_node *e = make_block(NODE_DOCUMENT, 1, 1);
50
+ return e;
51
+ }
52
+
53
+ cmark_parser *cmark_parser_new(int options)
54
+ {
55
+ cmark_parser *parser = (cmark_parser*)malloc(sizeof(cmark_parser));
56
+ cmark_node *document = make_document();
57
+ cmark_strbuf *line = (cmark_strbuf*)malloc(sizeof(cmark_strbuf));
58
+ cmark_strbuf *buf = (cmark_strbuf*)malloc(sizeof(cmark_strbuf));
59
+ cmark_strbuf_init(line, 256);
60
+ cmark_strbuf_init(buf, 0);
61
+
62
+ parser->refmap = cmark_reference_map_new();
63
+ parser->root = document;
64
+ parser->current = document;
65
+ parser->line_number = 0;
66
+ parser->curline = line;
67
+ parser->last_line_length = 0;
68
+ parser->linebuf = buf;
69
+ parser->options = options;
70
+
71
+ return parser;
72
+ }
73
+
74
+ void cmark_parser_free(cmark_parser *parser)
75
+ {
76
+ cmark_strbuf_free(parser->curline);
77
+ free(parser->curline);
78
+ cmark_strbuf_free(parser->linebuf);
79
+ free(parser->linebuf);
80
+ cmark_reference_map_free(parser->refmap);
81
+ free(parser);
82
+ }
83
+
84
+ static cmark_node*
85
+ finalize(cmark_parser *parser, cmark_node* b);
86
+
87
+ // Returns true if line has only space characters, else false.
88
+ static bool is_blank(cmark_strbuf *s, int offset)
89
+ {
90
+ while (offset < s->size) {
91
+ switch (s->ptr[offset]) {
92
+ case '\n':
93
+ return true;
94
+ case ' ':
95
+ offset++;
96
+ break;
97
+ default:
98
+ return false;
99
+ }
100
+ }
101
+
102
+ return true;
103
+ }
104
+
105
+ static inline bool can_contain(cmark_node_type parent_type, cmark_node_type child_type)
106
+ {
107
+ return ( parent_type == NODE_DOCUMENT ||
108
+ parent_type == NODE_BLOCK_QUOTE ||
109
+ parent_type == NODE_ITEM ||
110
+ (parent_type == NODE_LIST && child_type == NODE_ITEM) );
111
+ }
112
+
113
+ static inline bool accepts_lines(cmark_node_type block_type)
114
+ {
115
+ return (block_type == NODE_PARAGRAPH ||
116
+ block_type == NODE_HEADER ||
117
+ block_type == NODE_CODE_BLOCK);
118
+ }
119
+
120
+ static void add_line(cmark_node* node, cmark_chunk *ch, int offset)
121
+ {
122
+ assert(node->open);
123
+ cmark_strbuf_put(&node->string_content, ch->data + offset, ch->len - offset);
124
+ }
125
+
126
+ static void remove_trailing_blank_lines(cmark_strbuf *ln)
127
+ {
128
+ int i;
129
+
130
+ for (i = ln->size - 1; i >= 0; --i) {
131
+ unsigned char c = ln->ptr[i];
132
+
133
+ if (c != ' ' && c != '\t' && c != '\r' && c != '\n')
134
+ break;
135
+ }
136
+
137
+ if (i < 0) {
138
+ cmark_strbuf_clear(ln);
139
+ return;
140
+ }
141
+
142
+ i = cmark_strbuf_strchr(ln, '\n', i);
143
+ if (i >= 0)
144
+ cmark_strbuf_truncate(ln, i);
145
+ }
146
+
147
+ // Check to see if a node ends with a blank line, descending
148
+ // if needed into lists and sublists.
149
+ static bool ends_with_blank_line(cmark_node* node)
150
+ {
151
+ cmark_node *cur = node;
152
+ while (cur != NULL) {
153
+ if (cur->last_line_blank) {
154
+ return true;
155
+ }
156
+ if (cur->type == NODE_LIST || cur->type == NODE_ITEM) {
157
+ cur = cur->last_child;
158
+ } else {
159
+ cur = NULL;
160
+ }
161
+ }
162
+ return false;
163
+ }
164
+
165
+ // Break out of all containing lists
166
+ static int break_out_of_lists(cmark_parser *parser, cmark_node ** bptr)
167
+ {
168
+ cmark_node *container = *bptr;
169
+ cmark_node *b = parser->root;
170
+ // find first containing NODE_LIST:
171
+ while (b && b->type != NODE_LIST) {
172
+ b = b->last_child;
173
+ }
174
+ if (b) {
175
+ while (container && container != b) {
176
+ container = finalize(parser, container);
177
+ }
178
+ finalize(parser, b);
179
+ *bptr = b->parent;
180
+ }
181
+ return 0;
182
+ }
183
+
184
+
185
+ static cmark_node*
186
+ finalize(cmark_parser *parser, cmark_node* b)
187
+ {
188
+ int firstlinelen;
189
+ int pos;
190
+ cmark_node* item;
191
+ cmark_node* subitem;
192
+ cmark_node* parent;
193
+
194
+ parent = b->parent;
195
+
196
+ assert(b->open); // shouldn't call finalize on closed blocks
197
+ b->open = false;
198
+
199
+ if (parser->curline->size == 0) {
200
+ // end of input - line number has not been incremented
201
+ b->end_line = parser->line_number;
202
+ b->end_column = parser->last_line_length;
203
+ } else if (b->type == NODE_DOCUMENT ||
204
+ (b->type == NODE_CODE_BLOCK && b->as.code.fenced) ||
205
+ (b->type == NODE_HEADER && b->as.header.setext)) {
206
+ b->end_line = parser->line_number;
207
+ b->end_column = parser->curline->size -
208
+ (parser->curline->ptr[parser->curline->size - 1] == '\n' ?
209
+ 1 : 0);
210
+ } else {
211
+ b->end_line = parser->line_number - 1;
212
+ b->end_column = parser->last_line_length;
213
+ }
214
+
215
+ switch (b->type) {
216
+ case NODE_PARAGRAPH:
217
+ while (cmark_strbuf_at(&b->string_content, 0) == '[' &&
218
+ (pos = cmark_parse_reference_inline(&b->string_content, parser->refmap))) {
219
+
220
+ cmark_strbuf_drop(&b->string_content, pos);
221
+ }
222
+ if (is_blank(&b->string_content, 0)) {
223
+ // remove blank node (former reference def)
224
+ cmark_node_free(b);
225
+ }
226
+ break;
227
+
228
+ case NODE_CODE_BLOCK:
229
+ if (!b->as.code.fenced) { // indented code
230
+ remove_trailing_blank_lines(&b->string_content);
231
+ cmark_strbuf_putc(&b->string_content, '\n');
232
+ } else {
233
+
234
+ // first line of contents becomes info
235
+ firstlinelen = cmark_strbuf_strchr(&b->string_content, '\n', 0);
236
+
237
+ cmark_strbuf tmp = GH_BUF_INIT;
238
+ houdini_unescape_html_f(
239
+ &tmp,
240
+ b->string_content.ptr,
241
+ firstlinelen
242
+ );
243
+ cmark_strbuf_trim(&tmp);
244
+ cmark_strbuf_unescape(&tmp);
245
+ b->as.code.info = cmark_chunk_buf_detach(&tmp);
246
+
247
+ cmark_strbuf_drop(&b->string_content, firstlinelen + 1);
248
+ }
249
+ b->as.code.literal = cmark_chunk_buf_detach(&b->string_content);
250
+ break;
251
+
252
+ case NODE_HTML:
253
+ b->as.literal = cmark_chunk_buf_detach(&b->string_content);
254
+ break;
255
+
256
+ case NODE_LIST: // determine tight/loose status
257
+ b->as.list.tight = true; // tight by default
258
+ item = b->first_child;
259
+
260
+ while (item) {
261
+ // check for non-final non-empty list item ending with blank line:
262
+ if (item->last_line_blank && item->next) {
263
+ b->as.list.tight = false;
264
+ break;
265
+ }
266
+ // recurse into children of list item, to see if there are
267
+ // spaces between them:
268
+ subitem = item->first_child;
269
+ while (subitem) {
270
+ if (ends_with_blank_line(subitem) &&
271
+ (item->next || subitem->next)) {
272
+ b->as.list.tight = false;
273
+ break;
274
+ }
275
+ subitem = subitem->next;
276
+ }
277
+ if (!(b->as.list.tight)) {
278
+ break;
279
+ }
280
+ item = item->next;
281
+ }
282
+
283
+ break;
284
+
285
+ default:
286
+ break;
287
+ }
288
+ return parent;
289
+ }
290
+
291
+ // Add a node as child of another. Return pointer to child.
292
+ static cmark_node* add_child(cmark_parser *parser, cmark_node* parent,
293
+ cmark_node_type block_type, int start_column)
294
+ {
295
+ assert(parent);
296
+
297
+ // if 'parent' isn't the kind of node that can accept this child,
298
+ // then back up til we hit a node that can.
299
+ while (!can_contain(parent->type, block_type)) {
300
+ parent = finalize(parser, parent);
301
+ }
302
+
303
+ cmark_node* child = make_block(block_type, parser->line_number, start_column);
304
+ child->parent = parent;
305
+
306
+ if (parent->last_child) {
307
+ parent->last_child->next = child;
308
+ child->prev = parent->last_child;
309
+ } else {
310
+ parent->first_child = child;
311
+ child->prev = NULL;
312
+ }
313
+ parent->last_child = child;
314
+ return child;
315
+ }
316
+
317
+
318
+ // Walk through node and all children, recursively, parsing
319
+ // string content into inline content where appropriate.
320
+ static void process_inlines(cmark_node* root, cmark_reference_map *refmap, int options)
321
+ {
322
+ cmark_iter *iter = cmark_iter_new(root);
323
+ cmark_node *cur;
324
+ cmark_event_type ev_type;
325
+
326
+ while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) {
327
+ cur = cmark_iter_get_node(iter);
328
+ if (ev_type == CMARK_EVENT_ENTER) {
329
+ if (cur->type == NODE_PARAGRAPH ||
330
+ cur->type == NODE_HEADER) {
331
+ cmark_parse_inlines(cur, refmap, options);
332
+ }
333
+ }
334
+ }
335
+
336
+ cmark_iter_free(iter);
337
+ }
338
+
339
+ // Attempts to parse a list item marker (bullet or enumerated).
340
+ // On success, returns length of the marker, and populates
341
+ // data with the details. On failure, returns 0.
342
+ static int parse_list_marker(cmark_chunk *input, int pos, cmark_list **dataptr)
343
+ {
344
+ unsigned char c;
345
+ int startpos;
346
+ cmark_list *data;
347
+
348
+ startpos = pos;
349
+ c = peek_at(input, pos);
350
+
351
+ if (c == '*' || c == '-' || c == '+') {
352
+ pos++;
353
+ if (!cmark_isspace(peek_at(input, pos))) {
354
+ return 0;
355
+ }
356
+ data = (cmark_list *)calloc(1, sizeof(*data));
357
+ if(data == NULL) {
358
+ return 0;
359
+ } else {
360
+ data->marker_offset = 0; // will be adjusted later
361
+ data->list_type = CMARK_BULLET_LIST;
362
+ data->bullet_char = c;
363
+ data->start = 1;
364
+ data->delimiter = CMARK_PERIOD_DELIM;
365
+ data->tight = false;
366
+ }
367
+ } else if (cmark_isdigit(c)) {
368
+ int start = 0;
369
+
370
+ do {
371
+ start = (10 * start) + (peek_at(input, pos) - '0');
372
+ pos++;
373
+ } while (cmark_isdigit(peek_at(input, pos)));
374
+
375
+ c = peek_at(input, pos);
376
+ if (c == '.' || c == ')') {
377
+ pos++;
378
+ if (!cmark_isspace(peek_at(input, pos))) {
379
+ return 0;
380
+ }
381
+ data = (cmark_list *)calloc(1, sizeof(*data));
382
+ if(data == NULL) {
383
+ return 0;
384
+ } else {
385
+ data->marker_offset = 0; // will be adjusted later
386
+ data->list_type = CMARK_ORDERED_LIST;
387
+ data->bullet_char = 0;
388
+ data->start = start;
389
+ data->delimiter = (c == '.' ? CMARK_PERIOD_DELIM : CMARK_PAREN_DELIM);
390
+ data->tight = false;
391
+ }
392
+ } else {
393
+ return 0;
394
+ }
395
+
396
+ } else {
397
+ return 0;
398
+ }
399
+
400
+ *dataptr = data;
401
+ return (pos - startpos);
402
+ }
403
+
404
+ // Return 1 if list item belongs in list, else 0.
405
+ static int lists_match(cmark_list *list_data, cmark_list *item_data)
406
+ {
407
+ return (list_data->list_type == item_data->list_type &&
408
+ list_data->delimiter == item_data->delimiter &&
409
+ // list_data->marker_offset == item_data.marker_offset &&
410
+ list_data->bullet_char == item_data->bullet_char);
411
+ }
412
+
413
+ static cmark_node *finalize_document(cmark_parser *parser)
414
+ {
415
+ while (parser->current != parser->root) {
416
+ parser->current = finalize(parser, parser->current);
417
+ }
418
+
419
+ finalize(parser, parser->root);
420
+ process_inlines(parser->root, parser->refmap, parser->options);
421
+
422
+ return parser->root;
423
+ }
424
+
425
+ cmark_node *cmark_parse_file(FILE *f, int options)
426
+ {
427
+ unsigned char buffer[4096];
428
+ cmark_parser *parser = cmark_parser_new(options);
429
+ size_t bytes;
430
+ cmark_node *document;
431
+
432
+ while ((bytes = fread(buffer, 1, sizeof(buffer), f)) > 0) {
433
+ bool eof = bytes < sizeof(buffer);
434
+ S_parser_feed(parser, buffer, bytes, eof);
435
+ if (eof) {
436
+ break;
437
+ }
438
+ }
439
+
440
+ document = cmark_parser_finish(parser);
441
+ cmark_parser_free(parser);
442
+ return document;
443
+ }
444
+
445
+ cmark_node *cmark_parse_document(const char *buffer, size_t len, int options)
446
+ {
447
+ cmark_parser *parser = cmark_parser_new(options);
448
+ cmark_node *document;
449
+
450
+ S_parser_feed(parser, (const unsigned char *)buffer, len, true);
451
+
452
+ document = cmark_parser_finish(parser);
453
+ cmark_parser_free(parser);
454
+ return document;
455
+ }
456
+
457
+ void
458
+ cmark_parser_feed(cmark_parser *parser, const char *buffer, size_t len)
459
+ {
460
+ S_parser_feed(parser, (const unsigned char *)buffer, len, false);
461
+ }
462
+
463
+ static void
464
+ S_parser_feed(cmark_parser *parser, const unsigned char *buffer, size_t len,
465
+ bool eof)
466
+ {
467
+ const unsigned char *end = buffer + len;
468
+
469
+ while (buffer < end) {
470
+ const unsigned char *eol
471
+ = (const unsigned char *)memchr(buffer, '\n',
472
+ end - buffer);
473
+ size_t line_len;
474
+
475
+ if (eol) {
476
+ line_len = eol + 1 - buffer;
477
+ } else if (eof) {
478
+ line_len = end - buffer;
479
+ } else {
480
+ cmark_strbuf_put(parser->linebuf, buffer, end - buffer);
481
+ break;
482
+ }
483
+
484
+ if (parser->linebuf->size > 0) {
485
+ cmark_strbuf_put(parser->linebuf, buffer, line_len);
486
+ S_process_line(parser, parser->linebuf->ptr,
487
+ parser->linebuf->size);
488
+ cmark_strbuf_clear(parser->linebuf);
489
+ } else {
490
+ S_process_line(parser, buffer, line_len);
491
+ }
492
+
493
+ buffer += line_len;
494
+ }
495
+ }
496
+
497
+ static void chop_trailing_hashtags(cmark_chunk *ch)
498
+ {
499
+ int n, orig_n;
500
+
501
+ cmark_chunk_rtrim(ch);
502
+ orig_n = n = ch->len - 1;
503
+
504
+ // if string ends in space followed by #s, remove these:
505
+ while (n >= 0 && peek_at(ch, n) == '#')
506
+ n--;
507
+
508
+ // Check for a be a space before the final #s:
509
+ if (n != orig_n && n >= 0 && peek_at(ch, n) == ' ') {
510
+ ch->len = n;
511
+ cmark_chunk_rtrim(ch);
512
+ }
513
+ }
514
+
515
+ static void
516
+ S_process_line(cmark_parser *parser, const unsigned char *buffer, size_t bytes)
517
+ {
518
+ cmark_node* last_matched_container;
519
+ int offset = 0;
520
+ int matched = 0;
521
+ int lev = 0;
522
+ int i;
523
+ cmark_list *data = NULL;
524
+ bool all_matched = true;
525
+ cmark_node* container;
526
+ bool blank = false;
527
+ int first_nonspace;
528
+ int indent;
529
+ cmark_chunk input;
530
+ bool maybe_lazy;
531
+
532
+ utf8proc_detab(parser->curline, buffer, bytes);
533
+
534
+ // Add a newline to the end if not present:
535
+ // TODO this breaks abstraction:
536
+ if (parser->curline->ptr[parser->curline->size - 1] != '\n') {
537
+ cmark_strbuf_putc(parser->curline, '\n');
538
+ }
539
+ input.data = parser->curline->ptr;
540
+ input.len = parser->curline->size;
541
+
542
+ // container starts at the document root.
543
+ container = parser->root;
544
+
545
+ parser->line_number++;
546
+
547
+ // for each containing node, try to parse the associated line start.
548
+ // bail out on failure: container will point to the last matching node.
549
+
550
+ while (container->last_child && container->last_child->open) {
551
+ container = container->last_child;
552
+
553
+ first_nonspace = offset;
554
+ while (peek_at(&input, first_nonspace) == ' ') {
555
+ first_nonspace++;
556
+ }
557
+
558
+ indent = first_nonspace - offset;
559
+ blank = peek_at(&input, first_nonspace) == '\n';
560
+
561
+ if (container->type == NODE_BLOCK_QUOTE) {
562
+ matched = indent <= 3 && peek_at(&input, first_nonspace) == '>';
563
+ if (matched) {
564
+ offset = first_nonspace + 1;
565
+ if (peek_at(&input, offset) == ' ')
566
+ offset++;
567
+ } else {
568
+ all_matched = false;
569
+ }
570
+
571
+ } else if (container->type == NODE_ITEM) {
572
+
573
+ if (indent >= container->as.list.marker_offset +
574
+ container->as.list.padding) {
575
+ offset += container->as.list.marker_offset +
576
+ container->as.list.padding;
577
+ } else if (blank) {
578
+ offset = first_nonspace;
579
+ } else {
580
+ all_matched = false;
581
+ }
582
+
583
+ } else if (container->type == NODE_CODE_BLOCK) {
584
+
585
+ if (!container->as.code.fenced) { // indented
586
+ if (indent >= CODE_INDENT) {
587
+ offset += CODE_INDENT;
588
+ } else if (blank) {
589
+ offset = first_nonspace;
590
+ } else {
591
+ all_matched = false;
592
+ }
593
+ } else { // fenced
594
+ matched = 0;
595
+ if (indent <= 3 &&
596
+ (peek_at(&input, first_nonspace) ==
597
+ container->as.code.fence_char)) {
598
+ matched = scan_close_code_fence(&input,
599
+ first_nonspace);
600
+ }
601
+ if (matched >= container->as.code.fence_length) {
602
+ // closing fence - and since we're at
603
+ // the end of a line, we can return:
604
+ all_matched = false;
605
+ offset += matched;
606
+ parser->current = finalize(parser, container);
607
+ goto finished;
608
+ } else {
609
+ // skip opt. spaces of fence offset
610
+ i = container->as.code.fence_offset;
611
+ while (i > 0 &&
612
+ peek_at(&input, offset) == ' ') {
613
+ offset++;
614
+ i--;
615
+ }
616
+ }
617
+ }
618
+ } else if (container->type == NODE_HEADER) {
619
+
620
+ // a header can never contain more than one line
621
+ all_matched = false;
622
+
623
+ } else if (container->type == NODE_HTML) {
624
+
625
+ if (blank) {
626
+ all_matched = false;
627
+ }
628
+
629
+ } else if (container->type == NODE_PARAGRAPH) {
630
+
631
+ if (blank) {
632
+ all_matched = false;
633
+ }
634
+
635
+ }
636
+
637
+ if (!all_matched) {
638
+ container = container->parent; // back up to last matching node
639
+ break;
640
+ }
641
+ }
642
+
643
+ last_matched_container = container;
644
+
645
+ // check to see if we've hit 2nd blank line, break out of list:
646
+ if (blank && container->last_line_blank) {
647
+ break_out_of_lists(parser, &container);
648
+ }
649
+
650
+ maybe_lazy = parser->current->type == NODE_PARAGRAPH;
651
+ // try new container starts:
652
+ while (container->type != NODE_CODE_BLOCK &&
653
+ container->type != NODE_HTML) {
654
+
655
+ first_nonspace = offset;
656
+ while (peek_at(&input, first_nonspace) == ' ')
657
+ first_nonspace++;
658
+
659
+ indent = first_nonspace - offset;
660
+ blank = peek_at(&input, first_nonspace) == '\n';
661
+
662
+ if (indent >= CODE_INDENT) {
663
+ if (!maybe_lazy && !blank) {
664
+ offset += CODE_INDENT;
665
+ container = add_child(parser, container, NODE_CODE_BLOCK, offset + 1);
666
+ container->as.code.fenced = false;
667
+ container->as.code.fence_char = 0;
668
+ container->as.code.fence_length = 0;
669
+ container->as.code.fence_offset = 0;
670
+ container->as.code.info = cmark_chunk_literal("");
671
+ } else { // indent > 4 in lazy line
672
+ break;
673
+ }
674
+
675
+ } else if (peek_at(&input, first_nonspace) == '>') {
676
+
677
+ offset = first_nonspace + 1;
678
+ // optional following character
679
+ if (peek_at(&input, offset) == ' ')
680
+ offset++;
681
+ container = add_child(parser, container, NODE_BLOCK_QUOTE, offset + 1);
682
+
683
+ } else if ((matched = scan_atx_header_start(&input, first_nonspace))) {
684
+
685
+ offset = first_nonspace + matched;
686
+ container = add_child(parser, container, NODE_HEADER, offset + 1);
687
+
688
+ int hashpos = cmark_chunk_strchr(&input, '#', first_nonspace);
689
+ int level = 0;
690
+
691
+ while (peek_at(&input, hashpos) == '#') {
692
+ level++;
693
+ hashpos++;
694
+ }
695
+ container->as.header.level = level;
696
+ container->as.header.setext = false;
697
+
698
+ } else if ((matched = scan_open_code_fence(&input, first_nonspace))) {
699
+
700
+ container = add_child(parser, container, NODE_CODE_BLOCK, first_nonspace + 1);
701
+ container->as.code.fenced = true;
702
+ container->as.code.fence_char = peek_at(&input, first_nonspace);
703
+ container->as.code.fence_length = matched;
704
+ container->as.code.fence_offset = first_nonspace - offset;
705
+ container->as.code.info = cmark_chunk_literal("");
706
+ offset = first_nonspace + matched;
707
+
708
+ } else if ((matched = scan_html_block_tag(&input, first_nonspace))) {
709
+
710
+ container = add_child(parser, container, NODE_HTML, first_nonspace + 1);
711
+ // note, we don't adjust offset because the tag is part of the text
712
+
713
+ } else if (container->type == NODE_PARAGRAPH &&
714
+ (lev = scan_setext_header_line(&input, first_nonspace)) &&
715
+ // check that there is only one line in the paragraph:
716
+ cmark_strbuf_strrchr(&container->string_content, '\n',
717
+ cmark_strbuf_len(&container->string_content) - 2) < 0) {
718
+
719
+ container->type = NODE_HEADER;
720
+ container->as.header.level = lev;
721
+ container->as.header.setext = true;
722
+ offset = input.len - 1;
723
+
724
+ } else if (!(container->type == NODE_PARAGRAPH && !all_matched) &&
725
+ (matched = scan_hrule(&input, first_nonspace))) {
726
+
727
+ // it's only now that we know the line is not part of a setext header:
728
+ container = add_child(parser, container, NODE_HRULE, first_nonspace + 1);
729
+ container = finalize(parser, container);
730
+ offset = input.len - 1;
731
+
732
+ } else if ((matched = parse_list_marker(&input, first_nonspace, &data))) {
733
+
734
+ // compute padding:
735
+ offset = first_nonspace + matched;
736
+ i = 0;
737
+ while (i <= 5 && peek_at(&input, offset + i) == ' ') {
738
+ i++;
739
+ }
740
+ // i = number of spaces after marker, up to 5
741
+ if (i >= 5 || i < 1 || peek_at(&input, offset) == '\n') {
742
+ data->padding = matched + 1;
743
+ if (i > 0) {
744
+ offset += 1;
745
+ }
746
+ } else {
747
+ data->padding = matched + i;
748
+ offset += i;
749
+ }
750
+
751
+ // check container; if it's a list, see if this list item
752
+ // can continue the list; otherwise, create a list container.
753
+
754
+ data->marker_offset = indent;
755
+
756
+ if (container->type != NODE_LIST ||
757
+ !lists_match(&container->as.list, data)) {
758
+ container = add_child(parser, container, NODE_LIST,
759
+ first_nonspace + 1);
760
+
761
+ memcpy(&container->as.list, data, sizeof(*data));
762
+ }
763
+
764
+ // add the list item
765
+ container = add_child(parser, container, NODE_ITEM,
766
+ first_nonspace + 1);
767
+ /* TODO: static */
768
+ memcpy(&container->as.list, data, sizeof(*data));
769
+ free(data);
770
+ } else {
771
+ break;
772
+ }
773
+
774
+ if (accepts_lines(container->type)) {
775
+ // if it's a line container, it can't contain other containers
776
+ break;
777
+ }
778
+ maybe_lazy = false;
779
+ }
780
+
781
+ // what remains at offset is a text line. add the text to the
782
+ // appropriate container.
783
+
784
+ first_nonspace = offset;
785
+ while (peek_at(&input, first_nonspace) == ' ')
786
+ first_nonspace++;
787
+
788
+ indent = first_nonspace - offset;
789
+ blank = peek_at(&input, first_nonspace) == '\n';
790
+
791
+ if (blank && container->last_child) {
792
+ container->last_child->last_line_blank = true;
793
+ }
794
+
795
+ // block quote lines are never blank as they start with >
796
+ // and we don't count blanks in fenced code for purposes of tight/loose
797
+ // lists or breaking out of lists. we also don't set last_line_blank
798
+ // on an empty list item.
799
+ container->last_line_blank = (blank &&
800
+ container->type != NODE_BLOCK_QUOTE &&
801
+ container->type != NODE_HEADER &&
802
+ !(container->type == NODE_CODE_BLOCK &&
803
+ container->as.code.fenced) &&
804
+ !(container->type == NODE_ITEM &&
805
+ container->first_child == NULL &&
806
+ container->start_line == parser->line_number));
807
+
808
+ cmark_node *cont = container;
809
+ while (cont->parent) {
810
+ cont->parent->last_line_blank = false;
811
+ cont = cont->parent;
812
+ }
813
+
814
+ if (parser->current != last_matched_container &&
815
+ container == last_matched_container &&
816
+ !blank &&
817
+ parser->current->type == NODE_PARAGRAPH &&
818
+ cmark_strbuf_len(&parser->current->string_content) > 0) {
819
+
820
+ add_line(parser->current, &input, offset);
821
+
822
+ } else { // not a lazy continuation
823
+
824
+ // finalize any blocks that were not matched and set cur to container:
825
+ while (parser->current != last_matched_container) {
826
+ parser->current = finalize(parser, parser->current);
827
+ assert(parser->current != NULL);
828
+ }
829
+
830
+ if (container->type == NODE_CODE_BLOCK ||
831
+ container->type == NODE_HTML) {
832
+
833
+ add_line(container, &input, offset);
834
+
835
+ } else if (blank) {
836
+
837
+ // ??? do nothing
838
+
839
+ } else if (accepts_lines(container->type)) {
840
+
841
+ if (container->type == NODE_HEADER &&
842
+ container->as.header.setext == false) {
843
+ chop_trailing_hashtags(&input);
844
+ }
845
+ add_line(container, &input, first_nonspace);
846
+
847
+ } else {
848
+ // create paragraph container for line
849
+ container = add_child(parser, container, NODE_PARAGRAPH, first_nonspace + 1);
850
+ add_line(container, &input, first_nonspace);
851
+
852
+ }
853
+
854
+ parser->current = container;
855
+ }
856
+ finished:
857
+ parser->last_line_length = parser->curline->size -
858
+ (parser->curline->ptr[parser->curline->size - 1] == '\n' ?
859
+ 1 : 0);
860
+ ;
861
+ cmark_strbuf_clear(parser->curline);
862
+
863
+ }
864
+
865
+ cmark_node *cmark_parser_finish(cmark_parser *parser)
866
+ {
867
+ if (parser->linebuf->size) {
868
+ S_process_line(parser, parser->linebuf->ptr,
869
+ parser->linebuf->size);
870
+ cmark_strbuf_clear(parser->linebuf);
871
+ }
872
+
873
+ finalize_document(parser);
874
+
875
+ if (parser->options & CMARK_OPT_NORMALIZE) {
876
+ cmark_consolidate_text_nodes(parser->root);
877
+ }
878
+
879
+ cmark_strbuf_free(parser->curline);
880
+
881
+ #if CMARK_DEBUG_NODES
882
+ if (cmark_node_check(parser->root, stderr)) {
883
+ abort();
884
+ }
885
+ #endif
886
+ return parser->root;
887
+ }