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.
- checksums.yaml +7 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +119 -0
- data/Rakefile +39 -0
- data/bin/commonmarker +41 -0
- data/commonmarker.gemspec +30 -0
- data/ext/commonmarker/cmark/CMakeLists.txt +25 -0
- data/ext/commonmarker/cmark/COPYING +192 -0
- data/ext/commonmarker/cmark/FindAsan.cmake +74 -0
- data/ext/commonmarker/cmark/Makefile +170 -0
- data/ext/commonmarker/cmark/Makefile.nmake +36 -0
- data/ext/commonmarker/cmark/README.md +169 -0
- data/ext/commonmarker/cmark/api_test/CMakeLists.txt +25 -0
- data/ext/commonmarker/cmark/api_test/cplusplus.cpp +15 -0
- data/ext/commonmarker/cmark/api_test/cplusplus.h +17 -0
- data/ext/commonmarker/cmark/api_test/harness.c +102 -0
- data/ext/commonmarker/cmark/api_test/harness.h +42 -0
- data/ext/commonmarker/cmark/api_test/main.c +700 -0
- data/ext/commonmarker/cmark/appveyor.yml +15 -0
- data/ext/commonmarker/cmark/bench/statistics.py +595 -0
- data/ext/commonmarker/cmark/bench/stats.py +19 -0
- data/ext/commonmarker/cmark/benchmarks.md +33 -0
- data/ext/commonmarker/cmark/build/CMakeCache.txt +362 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/3.2.2/CMakeCCompiler.cmake +63 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/3.2.2/CMakeCXXCompiler.cmake +64 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/3.2.2/CMakeDetermineCompilerABI_C.bin +0 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/3.2.2/CMakeDetermineCompilerABI_CXX.bin +0 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/3.2.2/CMakeSystem.cmake +15 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/3.2.2/CompilerIdC/CMakeCCompilerId.c +499 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/3.2.2/CompilerIdC/a.out +0 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/3.2.2/CompilerIdCXX/CMakeCXXCompilerId.cpp +489 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/3.2.2/CompilerIdCXX/a.out +0 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/CMakeDirectoryInformation.cmake +16 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/CMakeError.log +30 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/CMakeOutput.log +598 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/Makefile.cmake +77 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/Makefile2 +268 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/TargetDirectories.txt +4 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/cmake.check_cache +1 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/feature_tests.bin +0 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/feature_tests.c +34 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/feature_tests.cxx +405 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/progress.marks +1 -0
- data/ext/commonmarker/cmark/build/CTestTestfile.cmake +10 -0
- data/ext/commonmarker/cmark/build/Makefile +237 -0
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/CMakeDirectoryInformation.cmake +16 -0
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/C.includecache +92 -0
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/CXX.includecache +36 -0
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/DependInfo.cmake +29 -0
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/build.make +155 -0
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/cmake_clean.cmake +12 -0
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/cplusplus.cpp.o +0 -0
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/depend.internal +25 -0
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/depend.make +25 -0
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/flags.make +13 -0
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/harness.c.o +0 -0
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/link.txt +1 -0
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/main.c.o +0 -0
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/progress.make +4 -0
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/progress.marks +1 -0
- data/ext/commonmarker/cmark/build/api_test/Makefile +277 -0
- data/ext/commonmarker/cmark/build/api_test/api_test +0 -0
- data/ext/commonmarker/cmark/build/api_test/cmake_install.cmake +29 -0
- data/ext/commonmarker/cmark/build/cmake_install.cmake +48 -0
- data/ext/commonmarker/cmark/build/man/CMakeFiles/CMakeDirectoryInformation.cmake +16 -0
- data/ext/commonmarker/cmark/build/man/CMakeFiles/progress.marks +1 -0
- data/ext/commonmarker/cmark/build/man/Makefile +181 -0
- data/ext/commonmarker/cmark/build/man/cmake_install.cmake +37 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/CMakeDirectoryInformation.cmake +16 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/C.includecache +422 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/DependInfo.cmake +39 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/blocks.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/buffer.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/build.make +544 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/cmake_clean.cmake +27 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/cmark.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/cmark_ctype.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/commonmark.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/depend.internal +177 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/depend.make +177 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/flags.make +8 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/houdini_href_e.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/houdini_html_e.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/houdini_html_u.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/html.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/inlines.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/iterator.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/link.txt +1 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/main.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/man.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/node.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/progress.make +19 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/references.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/scanners.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/utf8.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/xml.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/C.includecache +394 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/DependInfo.cmake +44 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/blocks.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/buffer.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/build.make +522 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/cmake_clean.cmake +27 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/cmark.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/cmark_ctype.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/commonmark.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/depend.internal +169 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/depend.make +169 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/flags.make +8 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/houdini_href_e.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/houdini_html_e.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/houdini_html_u.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/html.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/inlines.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/iterator.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/link.txt +1 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/man.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/node.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/progress.make +18 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/references.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/scanners.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/utf8.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/xml.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/C.includecache +394 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/DependInfo.cmake +38 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/blocks.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/buffer.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/build.make +519 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/cmake_clean.cmake +26 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/cmake_clean_target.cmake +3 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/cmark.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/cmark_ctype.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/commonmark.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/depend.internal +169 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/depend.make +169 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/flags.make +8 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/houdini_href_e.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/houdini_html_e.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/houdini_html_u.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/html.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/inlines.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/iterator.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/link.txt +2 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/man.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/node.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/progress.make +18 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/references.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/scanners.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/utf8.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/xml.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/progress.marks +1 -0
- data/ext/commonmarker/cmark/build/src/Makefile +814 -0
- data/ext/commonmarker/cmark/build/src/cmake_install.cmake +69 -0
- data/ext/commonmarker/cmark/build/src/cmark +0 -0
- data/ext/commonmarker/cmark/build/src/cmark_export.h +41 -0
- data/ext/commonmarker/cmark/build/src/cmark_version.h +7 -0
- data/ext/commonmarker/cmark/build/src/config.h +23 -0
- data/ext/commonmarker/cmark/build/src/libcmark.0.19.0.dylib +0 -0
- data/ext/commonmarker/cmark/build/src/libcmark.a +0 -0
- data/ext/commonmarker/cmark/build/src/libcmark.dylib +0 -0
- data/ext/commonmarker/cmark/build/src/libcmark.pc +10 -0
- data/ext/commonmarker/cmark/build/testdir/CMakeFiles/CMakeDirectoryInformation.cmake +16 -0
- data/ext/commonmarker/cmark/build/testdir/CMakeFiles/progress.marks +1 -0
- data/ext/commonmarker/cmark/build/testdir/CTestTestfile.cmake +12 -0
- data/ext/commonmarker/cmark/build/testdir/Makefile +181 -0
- data/ext/commonmarker/cmark/build/testdir/cmake_install.cmake +29 -0
- data/ext/commonmarker/cmark/changelog.txt +153 -0
- data/ext/commonmarker/cmark/data/CaseFolding-3.2.0.txt +912 -0
- data/ext/commonmarker/cmark/man/CMakeLists.txt +8 -0
- data/ext/commonmarker/cmark/man/make_man_page.py +131 -0
- data/ext/commonmarker/cmark/man/man1/cmark.1 +54 -0
- data/ext/commonmarker/cmark/man/man3/cmark.3 +583 -0
- data/ext/commonmarker/cmark/nmake.bat +1 -0
- data/ext/commonmarker/cmark/src/CMakeLists.txt +166 -0
- data/ext/commonmarker/cmark/src/bench.h +27 -0
- data/ext/commonmarker/cmark/src/blocks.c +887 -0
- data/ext/commonmarker/cmark/src/buffer.c +381 -0
- data/ext/commonmarker/cmark/src/buffer.h +113 -0
- data/ext/commonmarker/cmark/src/case_fold_switch.inc +2637 -0
- data/ext/commonmarker/cmark/src/chunk.h +110 -0
- data/ext/commonmarker/cmark/src/cmark.c +24 -0
- data/ext/commonmarker/cmark/src/cmark.h +565 -0
- data/ext/commonmarker/cmark/src/cmark_ctype.c +53 -0
- data/ext/commonmarker/cmark/src/cmark_ctype.h +24 -0
- data/ext/commonmarker/cmark/src/cmark_version.h.in +7 -0
- data/ext/commonmarker/cmark/src/commonmark.c +607 -0
- data/ext/commonmarker/cmark/src/config.h.in +23 -0
- data/ext/commonmarker/cmark/src/debug.h +36 -0
- data/ext/commonmarker/cmark/src/houdini.h +52 -0
- data/ext/commonmarker/cmark/src/houdini_href_e.c +107 -0
- data/ext/commonmarker/cmark/src/houdini_html_e.c +81 -0
- data/ext/commonmarker/cmark/src/houdini_html_u.c +116 -0
- data/ext/commonmarker/cmark/src/html.c +322 -0
- data/ext/commonmarker/cmark/src/html_unescape.gperf +2130 -0
- data/ext/commonmarker/cmark/src/html_unescape.h +13375 -0
- data/ext/commonmarker/cmark/src/inlines.c +1147 -0
- data/ext/commonmarker/cmark/src/inlines.h +19 -0
- data/ext/commonmarker/cmark/src/iterator.c +148 -0
- data/ext/commonmarker/cmark/src/iterator.h +25 -0
- data/ext/commonmarker/cmark/src/libcmark.pc.in +10 -0
- data/ext/commonmarker/cmark/src/main.c +191 -0
- data/ext/commonmarker/cmark/src/man.c +287 -0
- data/ext/commonmarker/cmark/src/node.c +873 -0
- data/ext/commonmarker/cmark/src/node.h +82 -0
- data/ext/commonmarker/cmark/src/parser.h +29 -0
- data/ext/commonmarker/cmark/src/references.c +154 -0
- data/ext/commonmarker/cmark/src/references.h +37 -0
- data/ext/commonmarker/cmark/src/scanners.c +15291 -0
- data/ext/commonmarker/cmark/src/scanners.h +41 -0
- data/ext/commonmarker/cmark/src/scanners.re +247 -0
- data/ext/commonmarker/cmark/src/utf8.c +452 -0
- data/ext/commonmarker/cmark/src/utf8.h +22 -0
- data/ext/commonmarker/cmark/src/xml.c +170 -0
- data/ext/commonmarker/cmark/test/CMakeLists.txt +53 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/asterisk +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/attr_generic +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/attr_href +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/attr_xml_lang +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/attr_xmlns +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/backslash +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/backtick +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/colon +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/dashes +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/double_quote +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/entity_builtin +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/entity_decimal +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/entity_external +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/entity_hex +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/equals +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/exclamation +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/greater_than +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/hash +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/hyphen +0 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/indent +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/left_bracket +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/left_paren +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/less_than +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/plus +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/right_bracket +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/right_paren +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/single_quote +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/string_any +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/string_brackets +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/string_cdata +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/string_dashes +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/string_empty_dblquotes +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/string_empty_quotes +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/string_idrefs +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/string_parentheses +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/string_pcdata +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/tag_cdata +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/tag_close +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/tag_doctype +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/tag_element +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/tag_entity +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/tag_notation +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/tag_open +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/tag_open_close +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/tag_open_exclamation +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/tag_open_q +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/tag_sq2_close +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/tag_xml_q +1 -0
- data/ext/commonmarker/cmark/test/afl_dictionary/underscore +1 -0
- data/ext/commonmarker/cmark/test/afl_test_cases/test.md +36 -0
- data/ext/commonmarker/cmark/test/cmark.py +40 -0
- data/ext/commonmarker/cmark/test/normalize.py +179 -0
- data/ext/commonmarker/cmark/test/pathological_tests.py +63 -0
- data/ext/commonmarker/cmark/test/roundtrip.sh +2 -0
- data/ext/commonmarker/cmark/test/smart_punct.txt +96 -0
- data/ext/commonmarker/cmark/test/spec.txt +7505 -0
- data/ext/commonmarker/cmark/test/spec_tests.py +139 -0
- data/ext/commonmarker/cmark/toolchain-mingw32.cmake +17 -0
- data/ext/commonmarker/cmark/tools/mkcasefold.pl +22 -0
- data/ext/commonmarker/cmark/wrappers/wrapper.lua +239 -0
- data/ext/commonmarker/cmark/wrappers/wrapper.py +37 -0
- data/ext/commonmarker/cmark/wrappers/wrapper.rb +15 -0
- data/ext/commonmarker/cmark/wrappers/wrapper.rkt +190 -0
- data/ext/commonmarker/commonmarker.c +165 -0
- data/ext/commonmarker/commonmarker.h +11 -0
- data/ext/commonmarker/extconf.rb +18 -0
- data/lib/commonmarker/config.rb +20 -0
- data/lib/commonmarker/version.rb +3 -0
- data/lib/commonmarker.rb +588 -0
- data/test/benchmark.rb +30 -0
- data/test/spec_tests.json +4074 -0
- data/test/test_basics.rb +44 -0
- data/test/test_helper.rb +5 -0
- data/test/test_maliciousness.rb +9 -0
- data/test/test_pathological_inputs.rb +52 -0
- data/test/test_spec.rb +20 -0
- metadata +399 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
#ifndef CMARK_DEBUG_H
|
2
|
+
#define CMARK_DEBUG_H
|
3
|
+
#include <stdio.h>
|
4
|
+
#include <errno.h>
|
5
|
+
#include <string.h>
|
6
|
+
|
7
|
+
#ifdef NDEBUG
|
8
|
+
#define debug(M, ...)
|
9
|
+
#else
|
10
|
+
#define debug(M, ...) \
|
11
|
+
fprintf(stderr, "DEBUG %s:%d: " M "\n", __FILE__, __LINE__, ##__VA_ARGS__)
|
12
|
+
#endif
|
13
|
+
|
14
|
+
#define clean_errno() (errno == 0 ? "None" : strerror(errno))
|
15
|
+
|
16
|
+
#define log_err(M, ...) \
|
17
|
+
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " M "\n", __FILE__, __LINE__, \
|
18
|
+
clean_errno(), ##__VA_ARGS__)
|
19
|
+
|
20
|
+
#define log_warn(M, ...) \
|
21
|
+
fprintf(stderr, "[WARN] (%s:%d: errno: %s) " M "\n", __FILE__, __LINE__, \
|
22
|
+
clean_errno(), ##__VA_ARGS__)
|
23
|
+
|
24
|
+
#define log_info(M, ...) fprintf(stderr, "[INFO] (%s:%d) " M "\n", __FILE__, \
|
25
|
+
__LINE__, ##__VA_ARGS__)
|
26
|
+
|
27
|
+
#define check(A, M, ...) \
|
28
|
+
if(!(A)) { log_err(M, ##__VA_ARGS__); errno=0; goto error; }
|
29
|
+
|
30
|
+
#define sentinel(M, ...) \
|
31
|
+
{ log_err(M, ##__VA_ARGS__); errno=0; goto error; }
|
32
|
+
|
33
|
+
#define check_debug(A, M, ...) \
|
34
|
+
if(!(A)) { debug(M, ##__VA_ARGS__); errno=0; goto error; }
|
35
|
+
|
36
|
+
#endif
|
@@ -0,0 +1,52 @@
|
|
1
|
+
#ifndef CMARK_HOUDINI_H
|
2
|
+
#define CMARK_HOUDINI_H
|
3
|
+
|
4
|
+
#ifdef __cplusplus
|
5
|
+
extern "C" {
|
6
|
+
#endif
|
7
|
+
|
8
|
+
#include <stdint.h>
|
9
|
+
#include "config.h"
|
10
|
+
#include "buffer.h"
|
11
|
+
|
12
|
+
#ifdef HAVE___BUILTIN_EXPECT
|
13
|
+
# define likely(x) __builtin_expect((x),1)
|
14
|
+
# define unlikely(x) __builtin_expect((x),0)
|
15
|
+
#else
|
16
|
+
# define likely(x) (x)
|
17
|
+
# define unlikely(x) (x)
|
18
|
+
#endif
|
19
|
+
|
20
|
+
#ifdef HOUDINI_USE_LOCALE
|
21
|
+
# define _isxdigit(c) isxdigit(c)
|
22
|
+
# define _isdigit(c) isdigit(c)
|
23
|
+
#else
|
24
|
+
/*
|
25
|
+
* Helper _isdigit methods -- do not trust the current locale
|
26
|
+
* */
|
27
|
+
# define _isxdigit(c) (strchr("0123456789ABCDEFabcdef", (c)) != NULL)
|
28
|
+
# define _isdigit(c) ((c) >= '0' && (c) <= '9')
|
29
|
+
#endif
|
30
|
+
|
31
|
+
#define HOUDINI_ESCAPED_SIZE(x) (((x) * 12) / 10)
|
32
|
+
#define HOUDINI_UNESCAPED_SIZE(x) (x)
|
33
|
+
|
34
|
+
extern size_t houdini_unescape_ent(cmark_strbuf *ob, const uint8_t *src, size_t size);
|
35
|
+
extern int houdini_escape_html(cmark_strbuf *ob, const uint8_t *src, size_t size);
|
36
|
+
extern int houdini_escape_html0(cmark_strbuf *ob, const uint8_t *src, size_t size, int secure);
|
37
|
+
extern int houdini_unescape_html(cmark_strbuf *ob, const uint8_t *src, size_t size);
|
38
|
+
extern void houdini_unescape_html_f(cmark_strbuf *ob, const uint8_t *src, size_t size);
|
39
|
+
extern int houdini_escape_xml(cmark_strbuf *ob, const uint8_t *src, size_t size);
|
40
|
+
extern int houdini_escape_uri(cmark_strbuf *ob, const uint8_t *src, size_t size);
|
41
|
+
extern int houdini_escape_url(cmark_strbuf *ob, const uint8_t *src, size_t size);
|
42
|
+
extern int houdini_escape_href(cmark_strbuf *ob, const uint8_t *src, size_t size);
|
43
|
+
extern int houdini_unescape_uri(cmark_strbuf *ob, const uint8_t *src, size_t size);
|
44
|
+
extern int houdini_unescape_url(cmark_strbuf *ob, const uint8_t *src, size_t size);
|
45
|
+
extern int houdini_escape_js(cmark_strbuf *ob, const uint8_t *src, size_t size);
|
46
|
+
extern int houdini_unescape_js(cmark_strbuf *ob, const uint8_t *src, size_t size);
|
47
|
+
|
48
|
+
#ifdef __cplusplus
|
49
|
+
}
|
50
|
+
#endif
|
51
|
+
|
52
|
+
#endif
|
@@ -0,0 +1,107 @@
|
|
1
|
+
#include <assert.h>
|
2
|
+
#include <stdio.h>
|
3
|
+
#include <string.h>
|
4
|
+
|
5
|
+
#include "houdini.h"
|
6
|
+
|
7
|
+
/*
|
8
|
+
* The following characters will not be escaped:
|
9
|
+
*
|
10
|
+
* -_.+!*'(),%#@?=;:/,+&$ alphanum
|
11
|
+
*
|
12
|
+
* Note that this character set is the addition of:
|
13
|
+
*
|
14
|
+
* - The characters which are safe to be in an URL
|
15
|
+
* - The characters which are *not* safe to be in
|
16
|
+
* an URL because they are RESERVED characters.
|
17
|
+
*
|
18
|
+
* We asume (lazily) that any RESERVED char that
|
19
|
+
* appears inside an URL is actually meant to
|
20
|
+
* have its native function (i.e. as an URL
|
21
|
+
* component/separator) and hence needs no escaping.
|
22
|
+
*
|
23
|
+
* There are two exceptions: the chacters & (amp)
|
24
|
+
* and ' (single quote) do not appear in the table.
|
25
|
+
* They are meant to appear in the URL as components,
|
26
|
+
* yet they require special HTML-entity escaping
|
27
|
+
* to generate valid HTML markup.
|
28
|
+
*
|
29
|
+
* All other characters will be escaped to %XX.
|
30
|
+
*
|
31
|
+
*/
|
32
|
+
static const char HREF_SAFE[] = {
|
33
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
34
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
35
|
+
0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,
|
36
|
+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1,
|
37
|
+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
38
|
+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,
|
39
|
+
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
40
|
+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
|
41
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
42
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
43
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
44
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
45
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
46
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
47
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
48
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
49
|
+
};
|
50
|
+
|
51
|
+
int
|
52
|
+
houdini_escape_href(cmark_strbuf *ob, const uint8_t *src, size_t size)
|
53
|
+
{
|
54
|
+
static const uint8_t hex_chars[] = "0123456789ABCDEF";
|
55
|
+
size_t i = 0, org;
|
56
|
+
uint8_t hex_str[3];
|
57
|
+
|
58
|
+
hex_str[0] = '%';
|
59
|
+
|
60
|
+
while (i < size) {
|
61
|
+
org = i;
|
62
|
+
while (i < size && HREF_SAFE[src[i]] != 0)
|
63
|
+
i++;
|
64
|
+
|
65
|
+
if (likely(i > org))
|
66
|
+
cmark_strbuf_put(ob, src + org, i - org);
|
67
|
+
|
68
|
+
/* escaping */
|
69
|
+
if (i >= size)
|
70
|
+
break;
|
71
|
+
|
72
|
+
switch (src[i]) {
|
73
|
+
/* amp appears all the time in URLs, but needs
|
74
|
+
* HTML-entity escaping to be inside an href */
|
75
|
+
case '&':
|
76
|
+
cmark_strbuf_puts(ob, "&");
|
77
|
+
break;
|
78
|
+
|
79
|
+
/* the single quote is a valid URL character
|
80
|
+
* according to the standard; it needs HTML
|
81
|
+
* entity escaping too */
|
82
|
+
case '\'':
|
83
|
+
cmark_strbuf_puts(ob, "'");
|
84
|
+
break;
|
85
|
+
|
86
|
+
/* the space can be escaped to %20 or a plus
|
87
|
+
* sign. we're going with the generic escape
|
88
|
+
* for now. the plus thing is more commonly seen
|
89
|
+
* when building GET strings */
|
90
|
+
#if 0
|
91
|
+
case ' ':
|
92
|
+
cmark_strbuf_putc(ob, '+');
|
93
|
+
break;
|
94
|
+
#endif
|
95
|
+
|
96
|
+
/* every other character goes with a %XX escaping */
|
97
|
+
default:
|
98
|
+
hex_str[1] = hex_chars[(src[i] >> 4) & 0xF];
|
99
|
+
hex_str[2] = hex_chars[src[i] & 0xF];
|
100
|
+
cmark_strbuf_put(ob, hex_str, 3);
|
101
|
+
}
|
102
|
+
|
103
|
+
i++;
|
104
|
+
}
|
105
|
+
|
106
|
+
return 1;
|
107
|
+
}
|
@@ -0,0 +1,81 @@
|
|
1
|
+
#include <assert.h>
|
2
|
+
#include <stdio.h>
|
3
|
+
#include <string.h>
|
4
|
+
|
5
|
+
#include "houdini.h"
|
6
|
+
|
7
|
+
/**
|
8
|
+
* According to the OWASP rules:
|
9
|
+
*
|
10
|
+
* & --> &
|
11
|
+
* < --> <
|
12
|
+
* > --> >
|
13
|
+
* " --> "
|
14
|
+
* ' --> ' ' is not recommended
|
15
|
+
* / --> / forward slash is included as it helps end an HTML entity
|
16
|
+
*
|
17
|
+
*/
|
18
|
+
static const char HTML_ESCAPE_TABLE[] = {
|
19
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
20
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
21
|
+
0, 0, 1, 0, 0, 0, 2, 3, 0, 0, 0, 0, 0, 0, 0, 4,
|
22
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 6, 0,
|
23
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
24
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
25
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
26
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
27
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
28
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
29
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
30
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
31
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
32
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
33
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
34
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
35
|
+
};
|
36
|
+
|
37
|
+
static const char *HTML_ESCAPES[] = {
|
38
|
+
"",
|
39
|
+
""",
|
40
|
+
"&",
|
41
|
+
"'",
|
42
|
+
"/",
|
43
|
+
"<",
|
44
|
+
">"
|
45
|
+
};
|
46
|
+
|
47
|
+
int
|
48
|
+
houdini_escape_html0(cmark_strbuf *ob, const uint8_t *src, size_t size, int secure)
|
49
|
+
{
|
50
|
+
size_t i = 0, org, esc = 0;
|
51
|
+
|
52
|
+
while (i < size) {
|
53
|
+
org = i;
|
54
|
+
while (i < size && (esc = HTML_ESCAPE_TABLE[src[i]]) == 0)
|
55
|
+
i++;
|
56
|
+
|
57
|
+
if (i > org)
|
58
|
+
cmark_strbuf_put(ob, src + org, i - org);
|
59
|
+
|
60
|
+
/* escaping */
|
61
|
+
if (unlikely(i >= size))
|
62
|
+
break;
|
63
|
+
|
64
|
+
/* The forward slash is only escaped in secure mode */
|
65
|
+
if ((src[i] == '/' || src[i] == '\'') && !secure) {
|
66
|
+
cmark_strbuf_putc(ob, src[i]);
|
67
|
+
} else {
|
68
|
+
cmark_strbuf_puts(ob, HTML_ESCAPES[esc]);
|
69
|
+
}
|
70
|
+
|
71
|
+
i++;
|
72
|
+
}
|
73
|
+
|
74
|
+
return 1;
|
75
|
+
}
|
76
|
+
|
77
|
+
int
|
78
|
+
houdini_escape_html(cmark_strbuf *ob, const uint8_t *src, size_t size)
|
79
|
+
{
|
80
|
+
return houdini_escape_html0(ob, src, size, 1);
|
81
|
+
}
|
@@ -0,0 +1,116 @@
|
|
1
|
+
#include <assert.h>
|
2
|
+
#include <stdio.h>
|
3
|
+
#include <string.h>
|
4
|
+
|
5
|
+
#include "buffer.h"
|
6
|
+
#include "houdini.h"
|
7
|
+
#include "utf8.h"
|
8
|
+
#include "html_unescape.h"
|
9
|
+
|
10
|
+
size_t
|
11
|
+
houdini_unescape_ent(cmark_strbuf *ob, const uint8_t *src, size_t size)
|
12
|
+
{
|
13
|
+
size_t i = 0;
|
14
|
+
|
15
|
+
if (size > 3 && src[0] == '#') {
|
16
|
+
int codepoint = 0;
|
17
|
+
|
18
|
+
if (_isdigit(src[1])) {
|
19
|
+
for (i = 1; i < size && _isdigit(src[i]); ++i) {
|
20
|
+
int cp = (codepoint * 10) + (src[i] - '0');
|
21
|
+
|
22
|
+
if (cp < codepoint)
|
23
|
+
return 0;
|
24
|
+
|
25
|
+
codepoint = cp;
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
else if (src[1] == 'x' || src[1] == 'X') {
|
30
|
+
for (i = 2; i < size && _isxdigit(src[i]); ++i) {
|
31
|
+
int cp = (codepoint * 16) + ((src[i] | 32) % 39 - 9);
|
32
|
+
|
33
|
+
if (cp < codepoint)
|
34
|
+
return 0;
|
35
|
+
|
36
|
+
codepoint = cp;
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
if (i < size && src[i] == ';' && codepoint) {
|
41
|
+
utf8proc_encode_char(codepoint, ob);
|
42
|
+
return i + 1;
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
else {
|
47
|
+
if (size > MAX_WORD_LENGTH)
|
48
|
+
size = MAX_WORD_LENGTH;
|
49
|
+
|
50
|
+
for (i = MIN_WORD_LENGTH; i < size; ++i) {
|
51
|
+
if (src[i] == ' ')
|
52
|
+
break;
|
53
|
+
|
54
|
+
if (src[i] == ';') {
|
55
|
+
const struct html_ent *entity = find_entity((char *)src, i);
|
56
|
+
|
57
|
+
if (entity != NULL) {
|
58
|
+
int len = 0;
|
59
|
+
while (len < 4 && entity->utf8[len] != '\0') {
|
60
|
+
++len;
|
61
|
+
}
|
62
|
+
cmark_strbuf_put(ob, entity->utf8, len);
|
63
|
+
return i + 1;
|
64
|
+
}
|
65
|
+
|
66
|
+
break;
|
67
|
+
}
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
return 0;
|
72
|
+
}
|
73
|
+
|
74
|
+
int
|
75
|
+
houdini_unescape_html(cmark_strbuf *ob, const uint8_t *src, size_t size)
|
76
|
+
{
|
77
|
+
size_t i = 0, org, ent;
|
78
|
+
|
79
|
+
while (i < size) {
|
80
|
+
org = i;
|
81
|
+
while (i < size && src[i] != '&')
|
82
|
+
i++;
|
83
|
+
|
84
|
+
if (likely(i > org)) {
|
85
|
+
if (unlikely(org == 0)) {
|
86
|
+
if (i >= size)
|
87
|
+
return 0;
|
88
|
+
|
89
|
+
cmark_strbuf_grow(ob, HOUDINI_UNESCAPED_SIZE(size));
|
90
|
+
}
|
91
|
+
|
92
|
+
cmark_strbuf_put(ob, src + org, i - org);
|
93
|
+
}
|
94
|
+
|
95
|
+
/* escaping */
|
96
|
+
if (i >= size)
|
97
|
+
break;
|
98
|
+
|
99
|
+
i++;
|
100
|
+
|
101
|
+
ent = houdini_unescape_ent(ob, src + i, size - i);
|
102
|
+
i += ent;
|
103
|
+
|
104
|
+
/* not really an entity */
|
105
|
+
if (ent == 0)
|
106
|
+
cmark_strbuf_putc(ob, '&');
|
107
|
+
}
|
108
|
+
|
109
|
+
return 1;
|
110
|
+
}
|
111
|
+
|
112
|
+
void houdini_unescape_html_f(cmark_strbuf *ob, const uint8_t *src, size_t size)
|
113
|
+
{
|
114
|
+
if (!houdini_unescape_html(ob, src, size))
|
115
|
+
cmark_strbuf_put(ob, src, size);
|
116
|
+
}
|
@@ -0,0 +1,322 @@
|
|
1
|
+
#include <stdlib.h>
|
2
|
+
#include <stdio.h>
|
3
|
+
#include <string.h>
|
4
|
+
#include <assert.h>
|
5
|
+
|
6
|
+
#include "config.h"
|
7
|
+
#include "cmark.h"
|
8
|
+
#include "node.h"
|
9
|
+
#include "buffer.h"
|
10
|
+
#include "houdini.h"
|
11
|
+
|
12
|
+
// Functions to convert cmark_nodes to HTML strings.
|
13
|
+
|
14
|
+
static void escape_html(cmark_strbuf *dest, const unsigned char *source, int length)
|
15
|
+
{
|
16
|
+
if (length < 0)
|
17
|
+
length = strlen((char *)source);
|
18
|
+
|
19
|
+
houdini_escape_html0(dest, source, (size_t)length, 0);
|
20
|
+
}
|
21
|
+
|
22
|
+
static void escape_href(cmark_strbuf *dest, const unsigned char *source, int length)
|
23
|
+
{
|
24
|
+
if (length < 0)
|
25
|
+
length = strlen((char *)source);
|
26
|
+
|
27
|
+
houdini_escape_href(dest, source, (size_t)length);
|
28
|
+
}
|
29
|
+
|
30
|
+
static inline void cr(cmark_strbuf *html)
|
31
|
+
{
|
32
|
+
if (html->size && html->ptr[html->size - 1] != '\n')
|
33
|
+
cmark_strbuf_putc(html, '\n');
|
34
|
+
}
|
35
|
+
|
36
|
+
struct render_state {
|
37
|
+
cmark_strbuf* html;
|
38
|
+
cmark_node *plain;
|
39
|
+
};
|
40
|
+
|
41
|
+
static void
|
42
|
+
S_render_sourcepos(cmark_node *node, cmark_strbuf *html, int options)
|
43
|
+
{
|
44
|
+
if (CMARK_OPT_SOURCEPOS & options) {
|
45
|
+
cmark_strbuf_printf(html, " data-sourcepos=\"%d:%d-%d:%d\"",
|
46
|
+
cmark_node_get_start_line(node),
|
47
|
+
cmark_node_get_start_column(node),
|
48
|
+
cmark_node_get_end_line(node),
|
49
|
+
cmark_node_get_end_column(node));
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
static int
|
54
|
+
S_render_node(cmark_node *node, cmark_event_type ev_type,
|
55
|
+
struct render_state *state, int options)
|
56
|
+
{
|
57
|
+
cmark_node *parent;
|
58
|
+
cmark_node *grandparent;
|
59
|
+
cmark_strbuf *html = state->html;
|
60
|
+
char start_header[] = "<h0";
|
61
|
+
char end_header[] = "</h0";
|
62
|
+
bool tight;
|
63
|
+
|
64
|
+
bool entering = (ev_type == CMARK_EVENT_ENTER);
|
65
|
+
|
66
|
+
if (state->plain == node) { // back at original node
|
67
|
+
state->plain = NULL;
|
68
|
+
}
|
69
|
+
|
70
|
+
if (state->plain != NULL) {
|
71
|
+
switch(node->type) {
|
72
|
+
case CMARK_NODE_TEXT:
|
73
|
+
case CMARK_NODE_CODE:
|
74
|
+
case CMARK_NODE_INLINE_HTML:
|
75
|
+
escape_html(html, node->as.literal.data,
|
76
|
+
node->as.literal.len);
|
77
|
+
break;
|
78
|
+
|
79
|
+
case CMARK_NODE_LINEBREAK:
|
80
|
+
case CMARK_NODE_SOFTBREAK:
|
81
|
+
cmark_strbuf_putc(html, ' ');
|
82
|
+
break;
|
83
|
+
|
84
|
+
default:
|
85
|
+
break;
|
86
|
+
}
|
87
|
+
return 1;
|
88
|
+
}
|
89
|
+
|
90
|
+
switch (node->type) {
|
91
|
+
case CMARK_NODE_DOCUMENT:
|
92
|
+
break;
|
93
|
+
|
94
|
+
case CMARK_NODE_BLOCK_QUOTE:
|
95
|
+
if (entering) {
|
96
|
+
cr(html);
|
97
|
+
cmark_strbuf_puts(html, "<blockquote");
|
98
|
+
S_render_sourcepos(node, html, options);
|
99
|
+
cmark_strbuf_puts(html, ">\n");
|
100
|
+
} else {
|
101
|
+
cr(html);
|
102
|
+
cmark_strbuf_puts(html, "</blockquote>\n");
|
103
|
+
}
|
104
|
+
break;
|
105
|
+
|
106
|
+
case CMARK_NODE_LIST: {
|
107
|
+
cmark_list_type list_type = node->as.list.list_type;
|
108
|
+
int start = node->as.list.start;
|
109
|
+
|
110
|
+
if (entering) {
|
111
|
+
cr(html);
|
112
|
+
if (list_type == CMARK_BULLET_LIST) {
|
113
|
+
cmark_strbuf_puts(html, "<ul");
|
114
|
+
S_render_sourcepos(node, html, options);
|
115
|
+
cmark_strbuf_puts(html, ">\n");
|
116
|
+
} else if (start == 1) {
|
117
|
+
cmark_strbuf_puts(html, "<ol");
|
118
|
+
S_render_sourcepos(node, html, options);
|
119
|
+
cmark_strbuf_puts(html, ">\n");
|
120
|
+
} else {
|
121
|
+
cmark_strbuf_printf(html,
|
122
|
+
"<ol start=\"%d\"",
|
123
|
+
start);
|
124
|
+
S_render_sourcepos(node, html, options);
|
125
|
+
cmark_strbuf_puts(html, ">\n");
|
126
|
+
}
|
127
|
+
} else {
|
128
|
+
cmark_strbuf_puts(html,
|
129
|
+
list_type == CMARK_BULLET_LIST ?
|
130
|
+
"</ul>\n" : "</ol>\n");
|
131
|
+
}
|
132
|
+
break;
|
133
|
+
}
|
134
|
+
|
135
|
+
case CMARK_NODE_ITEM:
|
136
|
+
if (entering) {
|
137
|
+
cr(html);
|
138
|
+
cmark_strbuf_puts(html, "<li");
|
139
|
+
S_render_sourcepos(node, html, options);
|
140
|
+
cmark_strbuf_putc(html, '>');
|
141
|
+
} else {
|
142
|
+
cmark_strbuf_puts(html, "</li>\n");
|
143
|
+
}
|
144
|
+
break;
|
145
|
+
|
146
|
+
case CMARK_NODE_HEADER:
|
147
|
+
if (entering) {
|
148
|
+
cr(html);
|
149
|
+
start_header[2] = '0' + node->as.header.level;
|
150
|
+
cmark_strbuf_puts(html, start_header);
|
151
|
+
S_render_sourcepos(node, html, options);
|
152
|
+
cmark_strbuf_putc(html, '>');
|
153
|
+
} else {
|
154
|
+
end_header[3] = '0' + node->as.header.level;
|
155
|
+
cmark_strbuf_puts(html, end_header);
|
156
|
+
cmark_strbuf_puts(html, ">\n");
|
157
|
+
}
|
158
|
+
break;
|
159
|
+
|
160
|
+
case CMARK_NODE_CODE_BLOCK:
|
161
|
+
cr(html);
|
162
|
+
|
163
|
+
if (!node->as.code.fenced || node->as.code.info.len == 0) {
|
164
|
+
cmark_strbuf_puts(html, "<pre");
|
165
|
+
S_render_sourcepos(node, html, options);
|
166
|
+
cmark_strbuf_puts(html, "><code>");
|
167
|
+
} else {
|
168
|
+
int first_tag = 0;
|
169
|
+
while (first_tag < node->as.code.info.len &&
|
170
|
+
node->as.code.info.data[first_tag] != ' ') {
|
171
|
+
first_tag += 1;
|
172
|
+
}
|
173
|
+
|
174
|
+
cmark_strbuf_puts(html, "<pre");
|
175
|
+
S_render_sourcepos(node, html, options);
|
176
|
+
cmark_strbuf_puts(html, "><code class=\"language-");
|
177
|
+
escape_html(html, node->as.code.info.data, first_tag);
|
178
|
+
cmark_strbuf_puts(html, "\">");
|
179
|
+
}
|
180
|
+
|
181
|
+
escape_html(html, node->as.code.literal.data,
|
182
|
+
node->as.code.literal.len);
|
183
|
+
cmark_strbuf_puts(html, "</code></pre>\n");
|
184
|
+
break;
|
185
|
+
|
186
|
+
case CMARK_NODE_HTML:
|
187
|
+
cr(html);
|
188
|
+
cmark_strbuf_put(html, node->as.literal.data, node->as.literal.len);
|
189
|
+
break;
|
190
|
+
|
191
|
+
case CMARK_NODE_HRULE:
|
192
|
+
cr(html);
|
193
|
+
cmark_strbuf_puts(html, "<hr");
|
194
|
+
S_render_sourcepos(node, html, options);
|
195
|
+
cmark_strbuf_puts(html, " />\n");
|
196
|
+
break;
|
197
|
+
|
198
|
+
case CMARK_NODE_PARAGRAPH:
|
199
|
+
parent = cmark_node_parent(node);
|
200
|
+
grandparent = cmark_node_parent(parent);
|
201
|
+
if (grandparent != NULL &&
|
202
|
+
grandparent->type == CMARK_NODE_LIST) {
|
203
|
+
tight = grandparent->as.list.tight;
|
204
|
+
} else {
|
205
|
+
tight = false;
|
206
|
+
}
|
207
|
+
if (!tight) {
|
208
|
+
if (entering) {
|
209
|
+
cr(html);
|
210
|
+
cmark_strbuf_puts(html, "<p");
|
211
|
+
S_render_sourcepos(node, html, options);
|
212
|
+
cmark_strbuf_putc(html, '>');
|
213
|
+
} else {
|
214
|
+
cmark_strbuf_puts(html, "</p>\n");
|
215
|
+
}
|
216
|
+
}
|
217
|
+
break;
|
218
|
+
|
219
|
+
case CMARK_NODE_TEXT:
|
220
|
+
escape_html(html, node->as.literal.data, node->as.literal.len);
|
221
|
+
break;
|
222
|
+
|
223
|
+
case CMARK_NODE_LINEBREAK:
|
224
|
+
cmark_strbuf_puts(html, "<br />\n");
|
225
|
+
break;
|
226
|
+
|
227
|
+
case CMARK_NODE_SOFTBREAK:
|
228
|
+
if (options & CMARK_OPT_HARDBREAKS) {
|
229
|
+
cmark_strbuf_puts(html, "<br />\n");
|
230
|
+
} else {
|
231
|
+
cmark_strbuf_putc(html, '\n');
|
232
|
+
}
|
233
|
+
break;
|
234
|
+
|
235
|
+
case CMARK_NODE_CODE:
|
236
|
+
cmark_strbuf_puts(html, "<code>");
|
237
|
+
escape_html(html, node->as.literal.data, node->as.literal.len);
|
238
|
+
cmark_strbuf_puts(html, "</code>");
|
239
|
+
break;
|
240
|
+
|
241
|
+
case CMARK_NODE_INLINE_HTML:
|
242
|
+
cmark_strbuf_put(html, node->as.literal.data, node->as.literal.len);
|
243
|
+
break;
|
244
|
+
|
245
|
+
case CMARK_NODE_STRONG:
|
246
|
+
if (entering) {
|
247
|
+
cmark_strbuf_puts(html, "<strong>");
|
248
|
+
} else {
|
249
|
+
cmark_strbuf_puts(html, "</strong>");
|
250
|
+
}
|
251
|
+
break;
|
252
|
+
|
253
|
+
case CMARK_NODE_EMPH:
|
254
|
+
if (entering) {
|
255
|
+
cmark_strbuf_puts(html, "<em>");
|
256
|
+
} else {
|
257
|
+
cmark_strbuf_puts(html, "</em>");
|
258
|
+
}
|
259
|
+
break;
|
260
|
+
|
261
|
+
case CMARK_NODE_LINK:
|
262
|
+
if (entering) {
|
263
|
+
cmark_strbuf_puts(html, "<a href=\"");
|
264
|
+
if (node->as.link.url)
|
265
|
+
escape_href(html, node->as.link.url, -1);
|
266
|
+
|
267
|
+
if (node->as.link.title) {
|
268
|
+
cmark_strbuf_puts(html, "\" title=\"");
|
269
|
+
escape_html(html, node->as.link.title, -1);
|
270
|
+
}
|
271
|
+
|
272
|
+
cmark_strbuf_puts(html, "\">");
|
273
|
+
} else {
|
274
|
+
cmark_strbuf_puts(html, "</a>");
|
275
|
+
}
|
276
|
+
break;
|
277
|
+
|
278
|
+
case CMARK_NODE_IMAGE:
|
279
|
+
if (entering) {
|
280
|
+
cmark_strbuf_puts(html, "<img src=\"");
|
281
|
+
if (node->as.link.url)
|
282
|
+
escape_href(html, node->as.link.url, -1);
|
283
|
+
|
284
|
+
cmark_strbuf_puts(html, "\" alt=\"");
|
285
|
+
state->plain = node;
|
286
|
+
} else {
|
287
|
+
if (node->as.link.title) {
|
288
|
+
cmark_strbuf_puts(html, "\" title=\"");
|
289
|
+
escape_html(html, node->as.link.title, -1);
|
290
|
+
}
|
291
|
+
|
292
|
+
cmark_strbuf_puts(html, "\" />");
|
293
|
+
}
|
294
|
+
break;
|
295
|
+
|
296
|
+
default:
|
297
|
+
assert(false);
|
298
|
+
break;
|
299
|
+
}
|
300
|
+
|
301
|
+
// cmark_strbuf_putc(html, 'x');
|
302
|
+
return 1;
|
303
|
+
}
|
304
|
+
|
305
|
+
char *cmark_render_html(cmark_node *root, int options)
|
306
|
+
{
|
307
|
+
char *result;
|
308
|
+
cmark_strbuf html = GH_BUF_INIT;
|
309
|
+
cmark_event_type ev_type;
|
310
|
+
cmark_node *cur;
|
311
|
+
struct render_state state = { &html, NULL };
|
312
|
+
cmark_iter *iter = cmark_iter_new(root);
|
313
|
+
|
314
|
+
while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) {
|
315
|
+
cur = cmark_iter_get_node(iter);
|
316
|
+
S_render_node(cur, ev_type, &state, options);
|
317
|
+
}
|
318
|
+
result = (char *)cmark_strbuf_detach(&html);
|
319
|
+
|
320
|
+
cmark_iter_free(iter);
|
321
|
+
return result;
|
322
|
+
}
|