daqing_kramdown 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/AUTHORS +1 -0
- data/CONTRIBUTERS +78 -0
- data/COPYING +30 -0
- data/README.md +71 -0
- data/VERSION +1 -0
- data/bin/daqing_kramdown +132 -0
- data/data/kramdown/document.html +22 -0
- data/data/kramdown/document.latex +50 -0
- data/lib/kramdown.rb +10 -0
- data/lib/kramdown/converter.rb +68 -0
- data/lib/kramdown/converter/base.rb +261 -0
- data/lib/kramdown/converter/hash_ast.rb +38 -0
- data/lib/kramdown/converter/html.rb +535 -0
- data/lib/kramdown/converter/kramdown.rb +448 -0
- data/lib/kramdown/converter/latex.rb +625 -0
- data/lib/kramdown/converter/man.rb +300 -0
- data/lib/kramdown/converter/math_engine/mathjax.rb +32 -0
- data/lib/kramdown/converter/remove_html_tags.rb +57 -0
- data/lib/kramdown/converter/syntax_highlighter.rb +56 -0
- data/lib/kramdown/converter/syntax_highlighter/minted.rb +35 -0
- data/lib/kramdown/converter/syntax_highlighter/rouge.rb +85 -0
- data/lib/kramdown/converter/toc.rb +69 -0
- data/lib/kramdown/document.rb +139 -0
- data/lib/kramdown/element.rb +551 -0
- data/lib/kramdown/error.rb +17 -0
- data/lib/kramdown/options.rb +604 -0
- data/lib/kramdown/parser.rb +26 -0
- data/lib/kramdown/parser/base.rb +131 -0
- data/lib/kramdown/parser/html.rb +608 -0
- data/lib/kramdown/parser/kramdown.rb +376 -0
- data/lib/kramdown/parser/kramdown/abbreviation.rb +78 -0
- data/lib/kramdown/parser/kramdown/autolink.rb +31 -0
- data/lib/kramdown/parser/kramdown/blank_line.rb +30 -0
- data/lib/kramdown/parser/kramdown/block_boundary.rb +34 -0
- data/lib/kramdown/parser/kramdown/blockquote.rb +38 -0
- data/lib/kramdown/parser/kramdown/codeblock.rb +57 -0
- data/lib/kramdown/parser/kramdown/codespan.rb +54 -0
- data/lib/kramdown/parser/kramdown/emphasis.rb +61 -0
- data/lib/kramdown/parser/kramdown/eob.rb +26 -0
- data/lib/kramdown/parser/kramdown/escaped_chars.rb +25 -0
- data/lib/kramdown/parser/kramdown/extensions.rb +214 -0
- data/lib/kramdown/parser/kramdown/footnote.rb +64 -0
- data/lib/kramdown/parser/kramdown/header.rb +70 -0
- data/lib/kramdown/parser/kramdown/horizontal_rule.rb +27 -0
- data/lib/kramdown/parser/kramdown/html.rb +162 -0
- data/lib/kramdown/parser/kramdown/html_entity.rb +34 -0
- data/lib/kramdown/parser/kramdown/line_break.rb +25 -0
- data/lib/kramdown/parser/kramdown/link.rb +149 -0
- data/lib/kramdown/parser/kramdown/list.rb +284 -0
- data/lib/kramdown/parser/kramdown/math.rb +53 -0
- data/lib/kramdown/parser/kramdown/paragraph.rb +62 -0
- data/lib/kramdown/parser/kramdown/smart_quotes.rb +174 -0
- data/lib/kramdown/parser/kramdown/table.rb +171 -0
- data/lib/kramdown/parser/kramdown/typographic_symbol.rb +44 -0
- data/lib/kramdown/parser/markdown.rb +57 -0
- data/lib/kramdown/utils.rb +45 -0
- data/lib/kramdown/utils/configurable.rb +45 -0
- data/lib/kramdown/utils/entities.rb +344 -0
- data/lib/kramdown/utils/html.rb +84 -0
- data/lib/kramdown/utils/lru_cache.rb +41 -0
- data/lib/kramdown/utils/string_scanner.rb +81 -0
- data/lib/kramdown/utils/unidecoder.rb +50 -0
- data/lib/kramdown/version.rb +15 -0
- data/man/man1/kramdown.1 +0 -0
- data/test/run_tests.rb +46 -0
- data/test/test_files.rb +298 -0
- data/test/test_location.rb +216 -0
- data/test/test_string_scanner_kramdown.rb +27 -0
- data/test/testcases/block/01_blank_line/spaces.html +1 -0
- data/test/testcases/block/01_blank_line/spaces.text +3 -0
- data/test/testcases/block/01_blank_line/tabs.html +1 -0
- data/test/testcases/block/01_blank_line/tabs.text +6 -0
- data/test/testcases/block/02_eob/beginning.html +1 -0
- data/test/testcases/block/02_eob/beginning.text +3 -0
- data/test/testcases/block/02_eob/end.html +1 -0
- data/test/testcases/block/02_eob/end.text +3 -0
- data/test/testcases/block/02_eob/middle.html +1 -0
- data/test/testcases/block/02_eob/middle.text +5 -0
- data/test/testcases/block/03_paragraph/indented.html +18 -0
- data/test/testcases/block/03_paragraph/indented.html.gfm +18 -0
- data/test/testcases/block/03_paragraph/indented.text +19 -0
- data/test/testcases/block/03_paragraph/line_break_last_line.html +9 -0
- data/test/testcases/block/03_paragraph/line_break_last_line.text +9 -0
- data/test/testcases/block/03_paragraph/no_newline_at_end.html +5 -0
- data/test/testcases/block/03_paragraph/no_newline_at_end.text +5 -0
- data/test/testcases/block/03_paragraph/one_para.html +1 -0
- data/test/testcases/block/03_paragraph/one_para.text +1 -0
- data/test/testcases/block/03_paragraph/standalone_image.html +8 -0
- data/test/testcases/block/03_paragraph/standalone_image.text +6 -0
- data/test/testcases/block/03_paragraph/two_para.html +4 -0
- data/test/testcases/block/03_paragraph/two_para.text +4 -0
- data/test/testcases/block/03_paragraph/with_html_to_native.html +1 -0
- data/test/testcases/block/03_paragraph/with_html_to_native.options +1 -0
- data/test/testcases/block/03_paragraph/with_html_to_native.text +1 -0
- data/test/testcases/block/04_header/atx_header.html +57 -0
- data/test/testcases/block/04_header/atx_header.text +54 -0
- data/test/testcases/block/04_header/atx_header_no_newline_at_end.html +1 -0
- data/test/testcases/block/04_header/atx_header_no_newline_at_end.text +1 -0
- data/test/testcases/block/04_header/header_type_offset.html +11 -0
- data/test/testcases/block/04_header/header_type_offset.kramdown +12 -0
- data/test/testcases/block/04_header/header_type_offset.latex +12 -0
- data/test/testcases/block/04_header/header_type_offset.options +2 -0
- data/test/testcases/block/04_header/header_type_offset.text +13 -0
- data/test/testcases/block/04_header/setext_header.html +32 -0
- data/test/testcases/block/04_header/setext_header.text +39 -0
- data/test/testcases/block/04_header/setext_header_no_newline_at_end.html +1 -0
- data/test/testcases/block/04_header/setext_header_no_newline_at_end.text +2 -0
- data/test/testcases/block/04_header/with_auto_id_prefix.html +3 -0
- data/test/testcases/block/04_header/with_auto_id_prefix.options +2 -0
- data/test/testcases/block/04_header/with_auto_id_prefix.text +3 -0
- data/test/testcases/block/04_header/with_auto_id_stripping.html +1 -0
- data/test/testcases/block/04_header/with_auto_id_stripping.options +1 -0
- data/test/testcases/block/04_header/with_auto_id_stripping.text +1 -0
- data/test/testcases/block/04_header/with_auto_ids.html +21 -0
- data/test/testcases/block/04_header/with_auto_ids.options +2 -0
- data/test/testcases/block/04_header/with_auto_ids.text +24 -0
- data/test/testcases/block/05_blockquote/indented.html +25 -0
- data/test/testcases/block/05_blockquote/indented.text +14 -0
- data/test/testcases/block/05_blockquote/lazy.html +34 -0
- data/test/testcases/block/05_blockquote/lazy.text +20 -0
- data/test/testcases/block/05_blockquote/nested.html +10 -0
- data/test/testcases/block/05_blockquote/nested.text +6 -0
- data/test/testcases/block/05_blockquote/no_newline_at_end.html +4 -0
- data/test/testcases/block/05_blockquote/no_newline_at_end.text +2 -0
- data/test/testcases/block/05_blockquote/very_long_line.html +3 -0
- data/test/testcases/block/05_blockquote/very_long_line.text +1 -0
- data/test/testcases/block/05_blockquote/with_code_blocks.html +15 -0
- data/test/testcases/block/05_blockquote/with_code_blocks.text +11 -0
- data/test/testcases/block/06_codeblock/disable-highlighting.html +4 -0
- data/test/testcases/block/06_codeblock/disable-highlighting.options +1 -0
- data/test/testcases/block/06_codeblock/disable-highlighting.text +4 -0
- data/test/testcases/block/06_codeblock/error.html +4 -0
- data/test/testcases/block/06_codeblock/error.text +4 -0
- data/test/testcases/block/06_codeblock/guess_lang_css_class.html +15 -0
- data/test/testcases/block/06_codeblock/guess_lang_css_class.options +2 -0
- data/test/testcases/block/06_codeblock/guess_lang_css_class.text +13 -0
- data/test/testcases/block/06_codeblock/highlighting-minted-with-opts.latex +9 -0
- data/test/testcases/block/06_codeblock/highlighting-minted-with-opts.options +4 -0
- data/test/testcases/block/06_codeblock/highlighting-minted-with-opts.text +5 -0
- data/test/testcases/block/06_codeblock/highlighting-minted.latex +8 -0
- data/test/testcases/block/06_codeblock/highlighting-minted.options +3 -0
- data/test/testcases/block/06_codeblock/highlighting-minted.text +4 -0
- data/test/testcases/block/06_codeblock/highlighting-opts.html +6 -0
- data/test/testcases/block/06_codeblock/highlighting-opts.options +7 -0
- data/test/testcases/block/06_codeblock/highlighting-opts.text +4 -0
- data/test/testcases/block/06_codeblock/highlighting.html +5 -0
- data/test/testcases/block/06_codeblock/highlighting.options +5 -0
- data/test/testcases/block/06_codeblock/highlighting.text +4 -0
- data/test/testcases/block/06_codeblock/issue_gh45.html +164 -0
- data/test/testcases/block/06_codeblock/issue_gh45.test +188 -0
- data/test/testcases/block/06_codeblock/lazy.html +4 -0
- data/test/testcases/block/06_codeblock/lazy.text +5 -0
- data/test/testcases/block/06_codeblock/no_newline_at_end.html +2 -0
- data/test/testcases/block/06_codeblock/no_newline_at_end.text +1 -0
- data/test/testcases/block/06_codeblock/no_newline_at_end_1.html +2 -0
- data/test/testcases/block/06_codeblock/no_newline_at_end_1.text +2 -0
- data/test/testcases/block/06_codeblock/normal.html +13 -0
- data/test/testcases/block/06_codeblock/normal.text +10 -0
- data/test/testcases/block/06_codeblock/rouge/disabled.html +2 -0
- data/test/testcases/block/06_codeblock/rouge/disabled.options +4 -0
- data/test/testcases/block/06_codeblock/rouge/disabled.text +1 -0
- data/test/testcases/block/06_codeblock/rouge/multiple.html +11 -0
- data/test/testcases/block/06_codeblock/rouge/multiple.options +4 -0
- data/test/testcases/block/06_codeblock/rouge/multiple.text +11 -0
- data/test/testcases/block/06_codeblock/rouge/simple.html +10 -0
- data/test/testcases/block/06_codeblock/rouge/simple.options +3 -0
- data/test/testcases/block/06_codeblock/rouge/simple.text +9 -0
- data/test/testcases/block/06_codeblock/tilde_syntax.html +7 -0
- data/test/testcases/block/06_codeblock/tilde_syntax.text +9 -0
- data/test/testcases/block/06_codeblock/whitespace.html +3 -0
- data/test/testcases/block/06_codeblock/whitespace.text +3 -0
- data/test/testcases/block/06_codeblock/with_blank_line.html +13 -0
- data/test/testcases/block/06_codeblock/with_blank_line.text +12 -0
- data/test/testcases/block/06_codeblock/with_eob_marker.html +6 -0
- data/test/testcases/block/06_codeblock/with_eob_marker.text +5 -0
- data/test/testcases/block/06_codeblock/with_ial.html +6 -0
- data/test/testcases/block/06_codeblock/with_ial.text +5 -0
- data/test/testcases/block/06_codeblock/with_lang_in_fenced_block.html +24 -0
- data/test/testcases/block/06_codeblock/with_lang_in_fenced_block.options +2 -0
- data/test/testcases/block/06_codeblock/with_lang_in_fenced_block.text +33 -0
- data/test/testcases/block/06_codeblock/with_lang_in_fenced_block_any_char.html +8 -0
- data/test/testcases/block/06_codeblock/with_lang_in_fenced_block_any_char.options +2 -0
- data/test/testcases/block/06_codeblock/with_lang_in_fenced_block_any_char.text +11 -0
- data/test/testcases/block/06_codeblock/with_lang_in_fenced_block_name_with_dash.html +3 -0
- data/test/testcases/block/06_codeblock/with_lang_in_fenced_block_name_with_dash.options +2 -0
- data/test/testcases/block/06_codeblock/with_lang_in_fenced_block_name_with_dash.text +4 -0
- data/test/testcases/block/07_horizontal_rule/error.html +7 -0
- data/test/testcases/block/07_horizontal_rule/error.text +7 -0
- data/test/testcases/block/07_horizontal_rule/normal.html +19 -0
- data/test/testcases/block/07_horizontal_rule/normal.text +20 -0
- data/test/testcases/block/07_horizontal_rule/sepspaces.html +3 -0
- data/test/testcases/block/07_horizontal_rule/sepspaces.text +3 -0
- data/test/testcases/block/07_horizontal_rule/septabs.html +3 -0
- data/test/testcases/block/07_horizontal_rule/septabs.text +3 -0
- data/test/testcases/block/08_list/brackets_in_item.latex +3 -0
- data/test/testcases/block/08_list/brackets_in_item.text +1 -0
- data/test/testcases/block/08_list/escaping.html +17 -0
- data/test/testcases/block/08_list/escaping.text +17 -0
- data/test/testcases/block/08_list/item_ial.html +10 -0
- data/test/testcases/block/08_list/item_ial.text +8 -0
- data/test/testcases/block/08_list/lazy.html +39 -0
- data/test/testcases/block/08_list/lazy.text +29 -0
- data/test/testcases/block/08_list/lazy_and_nested.html +9 -0
- data/test/testcases/block/08_list/lazy_and_nested.text +4 -0
- data/test/testcases/block/08_list/list_and_hr.html +9 -0
- data/test/testcases/block/08_list/list_and_hr.text +5 -0
- data/test/testcases/block/08_list/list_and_others.html +40 -0
- data/test/testcases/block/08_list/list_and_others.text +26 -0
- data/test/testcases/block/08_list/mixed.html +117 -0
- data/test/testcases/block/08_list/mixed.text +66 -0
- data/test/testcases/block/08_list/nested.html +17 -0
- data/test/testcases/block/08_list/nested.text +7 -0
- data/test/testcases/block/08_list/other_first_element.html +39 -0
- data/test/testcases/block/08_list/other_first_element.text +18 -0
- data/test/testcases/block/08_list/simple_ol.html +19 -0
- data/test/testcases/block/08_list/simple_ol.text +13 -0
- data/test/testcases/block/08_list/simple_ul.html +48 -0
- data/test/testcases/block/08_list/simple_ul.text +36 -0
- data/test/testcases/block/08_list/single_item.html +3 -0
- data/test/testcases/block/08_list/single_item.text +1 -0
- data/test/testcases/block/08_list/special_cases.html +62 -0
- data/test/testcases/block/08_list/special_cases.text +40 -0
- data/test/testcases/block/09_html/comment.html +18 -0
- data/test/testcases/block/09_html/comment.text +15 -0
- data/test/testcases/block/09_html/content_model/deflists.html +6 -0
- data/test/testcases/block/09_html/content_model/deflists.options +1 -0
- data/test/testcases/block/09_html/content_model/deflists.text +6 -0
- data/test/testcases/block/09_html/content_model/tables.html +14 -0
- data/test/testcases/block/09_html/content_model/tables.options +1 -0
- data/test/testcases/block/09_html/content_model/tables.text +14 -0
- data/test/testcases/block/09_html/html5_attributes.html +15 -0
- data/test/testcases/block/09_html/html5_attributes.text +15 -0
- data/test/testcases/block/09_html/html_after_block.html +7 -0
- data/test/testcases/block/09_html/html_after_block.text +5 -0
- data/test/testcases/block/09_html/html_and_codeblocks.html +15 -0
- data/test/testcases/block/09_html/html_and_codeblocks.options +1 -0
- data/test/testcases/block/09_html/html_and_codeblocks.text +13 -0
- data/test/testcases/block/09_html/html_and_headers.html +5 -0
- data/test/testcases/block/09_html/html_and_headers.text +6 -0
- data/test/testcases/block/09_html/html_to_native/code.html +10 -0
- data/test/testcases/block/09_html/html_to_native/code.text +9 -0
- data/test/testcases/block/09_html/html_to_native/comment.html +7 -0
- data/test/testcases/block/09_html/html_to_native/comment.text +8 -0
- data/test/testcases/block/09_html/html_to_native/emphasis.html +6 -0
- data/test/testcases/block/09_html/html_to_native/emphasis.text +6 -0
- data/test/testcases/block/09_html/html_to_native/entity.html +1 -0
- data/test/testcases/block/09_html/html_to_native/entity.text +1 -0
- data/test/testcases/block/09_html/html_to_native/header.html +6 -0
- data/test/testcases/block/09_html/html_to_native/header.options +2 -0
- data/test/testcases/block/09_html/html_to_native/header.text +6 -0
- data/test/testcases/block/09_html/html_to_native/list_dl.html +8 -0
- data/test/testcases/block/09_html/html_to_native/list_dl.text +8 -0
- data/test/testcases/block/09_html/html_to_native/list_ol.html +15 -0
- data/test/testcases/block/09_html/html_to_native/list_ol.text +17 -0
- data/test/testcases/block/09_html/html_to_native/list_ul.html +19 -0
- data/test/testcases/block/09_html/html_to_native/list_ul.text +22 -0
- data/test/testcases/block/09_html/html_to_native/options +1 -0
- data/test/testcases/block/09_html/html_to_native/paragraph.html +3 -0
- data/test/testcases/block/09_html/html_to_native/paragraph.text +4 -0
- data/test/testcases/block/09_html/html_to_native/table_normal.html +12 -0
- data/test/testcases/block/09_html/html_to_native/table_normal.text +12 -0
- data/test/testcases/block/09_html/html_to_native/table_simple.html +61 -0
- data/test/testcases/block/09_html/html_to_native/table_simple.text +71 -0
- data/test/testcases/block/09_html/html_to_native/typography.html +1 -0
- data/test/testcases/block/09_html/html_to_native/typography.text +1 -0
- data/test/testcases/block/09_html/invalid_html_1.html +5 -0
- data/test/testcases/block/09_html/invalid_html_1.text +5 -0
- data/test/testcases/block/09_html/invalid_html_2.html +5 -0
- data/test/testcases/block/09_html/invalid_html_2.text +5 -0
- data/test/testcases/block/09_html/markdown_attr.html +38 -0
- data/test/testcases/block/09_html/markdown_attr.text +38 -0
- data/test/testcases/block/09_html/not_parsed.html +24 -0
- data/test/testcases/block/09_html/not_parsed.text +24 -0
- data/test/testcases/block/09_html/parse_as_raw.html +35 -0
- data/test/testcases/block/09_html/parse_as_raw.htmlinput +34 -0
- data/test/testcases/block/09_html/parse_as_raw.options +1 -0
- data/test/testcases/block/09_html/parse_as_raw.text +33 -0
- data/test/testcases/block/09_html/parse_as_span.html +12 -0
- data/test/testcases/block/09_html/parse_as_span.htmlinput +12 -0
- data/test/testcases/block/09_html/parse_as_span.options +1 -0
- data/test/testcases/block/09_html/parse_as_span.text +9 -0
- data/test/testcases/block/09_html/parse_block_html.html +21 -0
- data/test/testcases/block/09_html/parse_block_html.options +1 -0
- data/test/testcases/block/09_html/parse_block_html.text +17 -0
- data/test/testcases/block/09_html/processing_instruction.html +12 -0
- data/test/testcases/block/09_html/processing_instruction.text +12 -0
- data/test/testcases/block/09_html/simple.html +60 -0
- data/test/testcases/block/09_html/simple.options +1 -0
- data/test/testcases/block/09_html/simple.text +55 -0
- data/test/testcases/block/09_html/standalone_image_in_div.htmlinput +7 -0
- data/test/testcases/block/09_html/standalone_image_in_div.text +8 -0
- data/test/testcases/block/09_html/textarea.html +8 -0
- data/test/testcases/block/09_html/textarea.text +8 -0
- data/test/testcases/block/09_html/xml.html +8 -0
- data/test/testcases/block/09_html/xml.text +7 -0
- data/test/testcases/block/10_ald/simple.html +2 -0
- data/test/testcases/block/10_ald/simple.text +8 -0
- data/test/testcases/block/11_ial/auto_id_and_ial.html +1 -0
- data/test/testcases/block/11_ial/auto_id_and_ial.options +1 -0
- data/test/testcases/block/11_ial/auto_id_and_ial.text +2 -0
- data/test/testcases/block/11_ial/nested.html +11 -0
- data/test/testcases/block/11_ial/nested.text +15 -0
- data/test/testcases/block/11_ial/simple.html +29 -0
- data/test/testcases/block/11_ial/simple.text +41 -0
- data/test/testcases/block/12_extension/comment.html +8 -0
- data/test/testcases/block/12_extension/comment.text +12 -0
- data/test/testcases/block/12_extension/ignored.html +8 -0
- data/test/testcases/block/12_extension/ignored.text +8 -0
- data/test/testcases/block/12_extension/nomarkdown.html +10 -0
- data/test/testcases/block/12_extension/nomarkdown.kramdown +20 -0
- data/test/testcases/block/12_extension/nomarkdown.latex +13 -0
- data/test/testcases/block/12_extension/nomarkdown.text +21 -0
- data/test/testcases/block/12_extension/options.html +21 -0
- data/test/testcases/block/12_extension/options.text +23 -0
- data/test/testcases/block/12_extension/options2.html +10 -0
- data/test/testcases/block/12_extension/options2.text +5 -0
- data/test/testcases/block/12_extension/options3.html +8 -0
- data/test/testcases/block/12_extension/options3.text +7 -0
- data/test/testcases/block/13_definition_list/auto_ids.html +15 -0
- data/test/testcases/block/13_definition_list/auto_ids.text +18 -0
- data/test/testcases/block/13_definition_list/definition_at_beginning.html +1 -0
- data/test/testcases/block/13_definition_list/definition_at_beginning.text +1 -0
- data/test/testcases/block/13_definition_list/deflist_ial.html +4 -0
- data/test/testcases/block/13_definition_list/deflist_ial.text +4 -0
- data/test/testcases/block/13_definition_list/item_ial.html +17 -0
- data/test/testcases/block/13_definition_list/item_ial.text +16 -0
- data/test/testcases/block/13_definition_list/multiple_terms.html +13 -0
- data/test/testcases/block/13_definition_list/multiple_terms.text +10 -0
- data/test/testcases/block/13_definition_list/no_def_list.html +2 -0
- data/test/testcases/block/13_definition_list/no_def_list.text +2 -0
- data/test/testcases/block/13_definition_list/para_wrapping.html +10 -0
- data/test/testcases/block/13_definition_list/para_wrapping.text +6 -0
- data/test/testcases/block/13_definition_list/separated_by_eob.html +8 -0
- data/test/testcases/block/13_definition_list/separated_by_eob.text +5 -0
- data/test/testcases/block/13_definition_list/simple.html +10 -0
- data/test/testcases/block/13_definition_list/simple.text +10 -0
- data/test/testcases/block/13_definition_list/styled_terms.html +4 -0
- data/test/testcases/block/13_definition_list/styled_terms.text +2 -0
- data/test/testcases/block/13_definition_list/too_much_space.html +3 -0
- data/test/testcases/block/13_definition_list/too_much_space.text +4 -0
- data/test/testcases/block/13_definition_list/with_blocks.html +38 -0
- data/test/testcases/block/13_definition_list/with_blocks.text +24 -0
- data/test/testcases/block/14_table/empty_tag_in_cell.html +8 -0
- data/test/testcases/block/14_table/empty_tag_in_cell.options +1 -0
- data/test/testcases/block/14_table/empty_tag_in_cell.text +1 -0
- data/test/testcases/block/14_table/errors.html +12 -0
- data/test/testcases/block/14_table/errors.text +13 -0
- data/test/testcases/block/14_table/escaping.html +52 -0
- data/test/testcases/block/14_table/escaping.text +19 -0
- data/test/testcases/block/14_table/footer.html +65 -0
- data/test/testcases/block/14_table/footer.text +25 -0
- data/test/testcases/block/14_table/header.html +117 -0
- data/test/testcases/block/14_table/header.text +39 -0
- data/test/testcases/block/14_table/no_table.html +3 -0
- data/test/testcases/block/14_table/no_table.text +3 -0
- data/test/testcases/block/14_table/simple.html +192 -0
- data/test/testcases/block/14_table/simple.text +53 -0
- data/test/testcases/block/14_table/table_with_footnote.html +25 -0
- data/test/testcases/block/14_table/table_with_footnote.latex +11 -0
- data/test/testcases/block/14_table/table_with_footnote.text +6 -0
- data/test/testcases/block/15_math/gh_128.html +1 -0
- data/test/testcases/block/15_math/gh_128.text +1 -0
- data/test/testcases/block/15_math/no_engine.html +3 -0
- data/test/testcases/block/15_math/no_engine.options +1 -0
- data/test/testcases/block/15_math/no_engine.text +2 -0
- data/test/testcases/block/15_math/normal.html +30 -0
- data/test/testcases/block/15_math/normal.text +30 -0
- data/test/testcases/block/16_toc/no_toc.html +14 -0
- data/test/testcases/block/16_toc/no_toc.text +16 -0
- data/test/testcases/block/16_toc/toc_exclude.html +35 -0
- data/test/testcases/block/16_toc/toc_exclude.options +1 -0
- data/test/testcases/block/16_toc/toc_exclude.text +19 -0
- data/test/testcases/block/16_toc/toc_levels.html +24 -0
- data/test/testcases/block/16_toc/toc_levels.options +2 -0
- data/test/testcases/block/16_toc/toc_levels.text +16 -0
- data/test/testcases/block/16_toc/toc_with_footnotes.html +13 -0
- data/test/testcases/block/16_toc/toc_with_footnotes.options +1 -0
- data/test/testcases/block/16_toc/toc_with_footnotes.text +6 -0
- data/test/testcases/block/16_toc/toc_with_links.html +8 -0
- data/test/testcases/block/16_toc/toc_with_links.options +2 -0
- data/test/testcases/block/16_toc/toc_with_links.text +8 -0
- data/test/testcases/cjk-line-break.html +4 -0
- data/test/testcases/cjk-line-break.options +1 -0
- data/test/testcases/cjk-line-break.text +12 -0
- data/test/testcases/encoding.html +46 -0
- data/test/testcases/encoding.text +28 -0
- data/test/testcases/man/example.man +123 -0
- data/test/testcases/man/example.text +85 -0
- data/test/testcases/man/heading-name-dash-description.man +4 -0
- data/test/testcases/man/heading-name-dash-description.text +1 -0
- data/test/testcases/man/heading-name-description.man +4 -0
- data/test/testcases/man/heading-name-description.text +2 -0
- data/test/testcases/man/heading-name-section-description.man +4 -0
- data/test/testcases/man/heading-name-section-description.text +1 -0
- data/test/testcases/man/heading-name-section.man +2 -0
- data/test/testcases/man/heading-name-section.text +1 -0
- data/test/testcases/man/heading-name.man +2 -0
- data/test/testcases/man/heading-name.text +1 -0
- data/test/testcases/man/sections.man +4 -0
- data/test/testcases/man/sections.text +11 -0
- data/test/testcases/man/text-escaping.man +8 -0
- data/test/testcases/man/text-escaping.text +7 -0
- data/test/testcases/span/01_link/empty.html +5 -0
- data/test/testcases/span/01_link/empty.text +5 -0
- data/test/testcases/span/01_link/empty_title.htmlinput +3 -0
- data/test/testcases/span/01_link/empty_title.text +7 -0
- data/test/testcases/span/01_link/image_in_a.html +5 -0
- data/test/testcases/span/01_link/image_in_a.text +5 -0
- data/test/testcases/span/01_link/imagelinks.html +15 -0
- data/test/testcases/span/01_link/imagelinks.text +18 -0
- data/test/testcases/span/01_link/inline.html +46 -0
- data/test/testcases/span/01_link/inline.text +48 -0
- data/test/testcases/span/01_link/latex_escaping.latex +6 -0
- data/test/testcases/span/01_link/latex_escaping.text +5 -0
- data/test/testcases/span/01_link/link_defs.html +9 -0
- data/test/testcases/span/01_link/link_defs.text +27 -0
- data/test/testcases/span/01_link/link_defs_with_ial.html +4 -0
- data/test/testcases/span/01_link/link_defs_with_ial.text +16 -0
- data/test/testcases/span/01_link/links_with_angle_brackets.html +3 -0
- data/test/testcases/span/01_link/links_with_angle_brackets.text +3 -0
- data/test/testcases/span/01_link/reference.html +37 -0
- data/test/testcases/span/01_link/reference.options +3 -0
- data/test/testcases/span/01_link/reference.text +53 -0
- data/test/testcases/span/02_emphasis/empty.html +3 -0
- data/test/testcases/span/02_emphasis/empty.text +3 -0
- data/test/testcases/span/02_emphasis/errors.html +9 -0
- data/test/testcases/span/02_emphasis/errors.text +9 -0
- data/test/testcases/span/02_emphasis/nesting.html +41 -0
- data/test/testcases/span/02_emphasis/nesting.text +36 -0
- data/test/testcases/span/02_emphasis/normal.html +65 -0
- data/test/testcases/span/02_emphasis/normal.options +1 -0
- data/test/testcases/span/02_emphasis/normal.text +63 -0
- data/test/testcases/span/03_codespan/empty.html +5 -0
- data/test/testcases/span/03_codespan/empty.text +5 -0
- data/test/testcases/span/03_codespan/errors.html +1 -0
- data/test/testcases/span/03_codespan/errors.text +1 -0
- data/test/testcases/span/03_codespan/highlighting-minted.latex +2 -0
- data/test/testcases/span/03_codespan/highlighting-minted.options +1 -0
- data/test/testcases/span/03_codespan/highlighting-minted.text +1 -0
- data/test/testcases/span/03_codespan/highlighting.html +1 -0
- data/test/testcases/span/03_codespan/highlighting.text +1 -0
- data/test/testcases/span/03_codespan/normal-css-class.html +1 -0
- data/test/testcases/span/03_codespan/normal-css-class.options +2 -0
- data/test/testcases/span/03_codespan/normal-css-class.text +1 -0
- data/test/testcases/span/03_codespan/normal.html +16 -0
- data/test/testcases/span/03_codespan/normal.text +16 -0
- data/test/testcases/span/03_codespan/rouge/disabled.html +1 -0
- data/test/testcases/span/03_codespan/rouge/disabled.options +4 -0
- data/test/testcases/span/03_codespan/rouge/disabled.text +1 -0
- data/test/testcases/span/03_codespan/rouge/simple.html +1 -0
- data/test/testcases/span/03_codespan/rouge/simple.options +1 -0
- data/test/testcases/span/03_codespan/rouge/simple.text +1 -0
- data/test/testcases/span/04_footnote/backlink_inline.html +79 -0
- data/test/testcases/span/04_footnote/backlink_inline.options +1 -0
- data/test/testcases/span/04_footnote/backlink_inline.text +38 -0
- data/test/testcases/span/04_footnote/backlink_text.html +9 -0
- data/test/testcases/span/04_footnote/backlink_text.options +1 -0
- data/test/testcases/span/04_footnote/backlink_text.text +3 -0
- data/test/testcases/span/04_footnote/definitions.html +17 -0
- data/test/testcases/span/04_footnote/definitions.latex +17 -0
- data/test/testcases/span/04_footnote/definitions.text +24 -0
- data/test/testcases/span/04_footnote/footnote_nr.html +12 -0
- data/test/testcases/span/04_footnote/footnote_nr.latex +2 -0
- data/test/testcases/span/04_footnote/footnote_nr.options +1 -0
- data/test/testcases/span/04_footnote/footnote_nr.text +4 -0
- data/test/testcases/span/04_footnote/footnote_prefix.html +12 -0
- data/test/testcases/span/04_footnote/footnote_prefix.options +1 -0
- data/test/testcases/span/04_footnote/footnote_prefix.text +4 -0
- data/test/testcases/span/04_footnote/inside_footnote.html +17 -0
- data/test/testcases/span/04_footnote/inside_footnote.text +9 -0
- data/test/testcases/span/04_footnote/markers.html +46 -0
- data/test/testcases/span/04_footnote/markers.latex +23 -0
- data/test/testcases/span/04_footnote/markers.options +2 -0
- data/test/testcases/span/04_footnote/markers.text +27 -0
- data/test/testcases/span/04_footnote/placement.html +11 -0
- data/test/testcases/span/04_footnote/placement.options +1 -0
- data/test/testcases/span/04_footnote/placement.text +8 -0
- data/test/testcases/span/04_footnote/regexp_problem.html +14 -0
- data/test/testcases/span/04_footnote/regexp_problem.options +2 -0
- data/test/testcases/span/04_footnote/regexp_problem.text +52 -0
- data/test/testcases/span/04_footnote/without_backlink.html +9 -0
- data/test/testcases/span/04_footnote/without_backlink.options +1 -0
- data/test/testcases/span/04_footnote/without_backlink.text +3 -0
- data/test/testcases/span/05_html/across_lines.html +1 -0
- data/test/testcases/span/05_html/across_lines.text +2 -0
- data/test/testcases/span/05_html/button.html +7 -0
- data/test/testcases/span/05_html/button.text +7 -0
- data/test/testcases/span/05_html/invalid.html +1 -0
- data/test/testcases/span/05_html/invalid.text +1 -0
- data/test/testcases/span/05_html/link_with_mailto.html +1 -0
- data/test/testcases/span/05_html/link_with_mailto.text +1 -0
- data/test/testcases/span/05_html/mark_element.html +3 -0
- data/test/testcases/span/05_html/mark_element.text +3 -0
- data/test/testcases/span/05_html/markdown_attr.html +6 -0
- data/test/testcases/span/05_html/markdown_attr.text +6 -0
- data/test/testcases/span/05_html/normal.html +43 -0
- data/test/testcases/span/05_html/normal.text +43 -0
- data/test/testcases/span/05_html/raw_span_elements.html +2 -0
- data/test/testcases/span/05_html/raw_span_elements.text +2 -0
- data/test/testcases/span/05_html/xml.html +5 -0
- data/test/testcases/span/05_html/xml.text +5 -0
- data/test/testcases/span/abbreviations/abbrev.html +21 -0
- data/test/testcases/span/abbreviations/abbrev.text +34 -0
- data/test/testcases/span/abbreviations/abbrev_defs.html +2 -0
- data/test/testcases/span/abbreviations/abbrev_defs.text +5 -0
- data/test/testcases/span/abbreviations/in_footnote.html +9 -0
- data/test/testcases/span/abbreviations/in_footnote.text +5 -0
- data/test/testcases/span/autolinks/url_links.html +15 -0
- data/test/testcases/span/autolinks/url_links.text +16 -0
- data/test/testcases/span/escaped_chars/normal.html +47 -0
- data/test/testcases/span/escaped_chars/normal.text +47 -0
- data/test/testcases/span/extension/comment.html +6 -0
- data/test/testcases/span/extension/comment.text +6 -0
- data/test/testcases/span/extension/ignored.html +1 -0
- data/test/testcases/span/extension/ignored.text +1 -0
- data/test/testcases/span/extension/nomarkdown.html +1 -0
- data/test/testcases/span/extension/nomarkdown.text +1 -0
- data/test/testcases/span/extension/options.html +1 -0
- data/test/testcases/span/extension/options.text +1 -0
- data/test/testcases/span/ial/simple.html +6 -0
- data/test/testcases/span/ial/simple.text +6 -0
- data/test/testcases/span/line_breaks/normal.html +11 -0
- data/test/testcases/span/line_breaks/normal.latex +12 -0
- data/test/testcases/span/line_breaks/normal.text +11 -0
- data/test/testcases/span/math/no_engine.html +1 -0
- data/test/testcases/span/math/no_engine.options +1 -0
- data/test/testcases/span/math/no_engine.text +1 -0
- data/test/testcases/span/math/normal.html +10 -0
- data/test/testcases/span/math/normal.text +10 -0
- data/test/testcases/span/text_substitutions/entities.html +6 -0
- data/test/testcases/span/text_substitutions/entities.options +1 -0
- data/test/testcases/span/text_substitutions/entities.text +6 -0
- data/test/testcases/span/text_substitutions/entities_as_char.html +1 -0
- data/test/testcases/span/text_substitutions/entities_as_char.options +2 -0
- data/test/testcases/span/text_substitutions/entities_as_char.text +1 -0
- data/test/testcases/span/text_substitutions/entities_as_input.html +1 -0
- data/test/testcases/span/text_substitutions/entities_as_input.options +1 -0
- data/test/testcases/span/text_substitutions/entities_as_input.text +1 -0
- data/test/testcases/span/text_substitutions/entities_numeric.html +1 -0
- data/test/testcases/span/text_substitutions/entities_numeric.options +1 -0
- data/test/testcases/span/text_substitutions/entities_numeric.text +1 -0
- data/test/testcases/span/text_substitutions/entities_symbolic.html +1 -0
- data/test/testcases/span/text_substitutions/entities_symbolic.options +1 -0
- data/test/testcases/span/text_substitutions/entities_symbolic.text +1 -0
- data/test/testcases/span/text_substitutions/greaterthan.html +1 -0
- data/test/testcases/span/text_substitutions/greaterthan.text +1 -0
- data/test/testcases/span/text_substitutions/lowerthan.html +1 -0
- data/test/testcases/span/text_substitutions/lowerthan.text +1 -0
- data/test/testcases/span/text_substitutions/typography.html +40 -0
- data/test/testcases/span/text_substitutions/typography.options +1 -0
- data/test/testcases/span/text_substitutions/typography.text +40 -0
- data/test/testcases/span/text_substitutions/typography_subst.html +3 -0
- data/test/testcases/span/text_substitutions/typography_subst.latex +4 -0
- data/test/testcases/span/text_substitutions/typography_subst.options +8 -0
- data/test/testcases/span/text_substitutions/typography_subst.text +3 -0
- metadata +659 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# -*- coding: utf-8; frozen_string_literal: true -*-
|
|
2
|
+
#
|
|
3
|
+
#--
|
|
4
|
+
# Copyright (C) 2009-2019 Thomas Leitner <t_leitner@gmx.at>
|
|
5
|
+
#
|
|
6
|
+
# This file is part of kramdown which is licensed under the MIT.
|
|
7
|
+
#++
|
|
8
|
+
#
|
|
9
|
+
|
|
10
|
+
require 'rexml/parsers/baseparser'
|
|
11
|
+
|
|
12
|
+
module Kramdown
|
|
13
|
+
|
|
14
|
+
module Utils
|
|
15
|
+
|
|
16
|
+
# Provides convenience methods for HTML related tasks.
|
|
17
|
+
#
|
|
18
|
+
# *Note* that this module has to be mixed into a class that has a @root (containing an element
|
|
19
|
+
# of type :root) and an @options (containing an options hash) instance variable so that some of
|
|
20
|
+
# the methods can work correctly.
|
|
21
|
+
module Html
|
|
22
|
+
|
|
23
|
+
# Convert the entity +e+ to a string. The optional parameter +original+ may contain the
|
|
24
|
+
# original representation of the entity.
|
|
25
|
+
#
|
|
26
|
+
# This method uses the option +entity_output+ to determine the output form for the entity.
|
|
27
|
+
def entity_to_str(e, original = nil)
|
|
28
|
+
entity_output = @options[:entity_output]
|
|
29
|
+
|
|
30
|
+
if entity_output == :as_char &&
|
|
31
|
+
(c = e.char.encode(@root.options[:encoding]) rescue nil) &&
|
|
32
|
+
((c = e.char) == '"' || !ESCAPE_MAP.key?(c))
|
|
33
|
+
c
|
|
34
|
+
elsif (entity_output == :as_input || entity_output == :as_char) && original
|
|
35
|
+
original
|
|
36
|
+
elsif (entity_output == :symbolic || ESCAPE_MAP.key?(e.char)) && !e.name.nil?
|
|
37
|
+
"&#{e.name};"
|
|
38
|
+
else # default to :numeric
|
|
39
|
+
"&##{e.code_point};"
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Return the HTML representation of the attributes +attr+.
|
|
44
|
+
def html_attributes(attr)
|
|
45
|
+
return '' if attr.empty?
|
|
46
|
+
|
|
47
|
+
attr.map do |k, v|
|
|
48
|
+
v.nil? || (k == 'id' && v.strip.empty?) ? '' : " #{k}=\"#{escape_html(v.to_s, :attribute)}\""
|
|
49
|
+
end.join('')
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# :stopdoc:
|
|
53
|
+
ESCAPE_MAP = {
|
|
54
|
+
'<' => '<',
|
|
55
|
+
'>' => '>',
|
|
56
|
+
'&' => '&',
|
|
57
|
+
'"' => '"',
|
|
58
|
+
}
|
|
59
|
+
ESCAPE_ALL_RE = /<|>|&/
|
|
60
|
+
ESCAPE_TEXT_RE = Regexp.union(REXML::Parsers::BaseParser::REFERENCE_RE, /<|>|&/)
|
|
61
|
+
ESCAPE_ATTRIBUTE_RE = Regexp.union(REXML::Parsers::BaseParser::REFERENCE_RE, /<|>|&|"/)
|
|
62
|
+
ESCAPE_RE_FROM_TYPE = {all: ESCAPE_ALL_RE, text: ESCAPE_TEXT_RE, attribute: ESCAPE_ATTRIBUTE_RE}
|
|
63
|
+
# :startdoc:
|
|
64
|
+
|
|
65
|
+
# Escape the special HTML characters in the string +str+. The parameter +type+ specifies what
|
|
66
|
+
# is escaped: :all - all special HTML characters except the quotation mark as well as
|
|
67
|
+
# entities, :text - all special HTML characters except the quotation mark but no entities and
|
|
68
|
+
# :attribute - all special HTML characters including the quotation mark but no entities.
|
|
69
|
+
def escape_html(str, type = :all)
|
|
70
|
+
str.gsub(ESCAPE_RE_FROM_TYPE[type]) {|m| ESCAPE_MAP[m] || m }
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
REDUNDANT_LINE_BREAK_REGEX = /([\p{Han}\p{Hiragana}\p{Katakana}]+)\n([\p{Han}\p{Hiragana}\p{Katakana}]+)/u
|
|
74
|
+
def fix_cjk_line_break(str)
|
|
75
|
+
while str.gsub!(REDUNDANT_LINE_BREAK_REGEX, '\1\2')
|
|
76
|
+
end
|
|
77
|
+
str
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# -*- coding: utf-8; frozen_string_literal: true -*-
|
|
2
|
+
#
|
|
3
|
+
#--
|
|
4
|
+
# Copyright (C) 2009-2019 Thomas Leitner <t_leitner@gmx.at>
|
|
5
|
+
#
|
|
6
|
+
# This file is part of kramdown which is licensed under the MIT.
|
|
7
|
+
#++
|
|
8
|
+
#
|
|
9
|
+
|
|
10
|
+
module Kramdown
|
|
11
|
+
module Utils
|
|
12
|
+
|
|
13
|
+
# A simple least recently used (LRU) cache.
|
|
14
|
+
#
|
|
15
|
+
# The cache relies on the fact that Ruby's Hash class maintains insertion order. So deleting
|
|
16
|
+
# and re-inserting a key-value pair on access moves the key to the last position. When an
|
|
17
|
+
# entry is added and the cache is full, the first entry is removed.
|
|
18
|
+
class LRUCache
|
|
19
|
+
|
|
20
|
+
# Creates a new LRUCache that can hold +size+ entries.
|
|
21
|
+
def initialize(size)
|
|
22
|
+
@size = size
|
|
23
|
+
@cache = {}
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Returns the stored value for +key+ or +nil+ if no value was stored under the key.
|
|
27
|
+
def [](key)
|
|
28
|
+
(val = @cache.delete(key)).nil? ? nil : @cache[key] = val
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Stores the +value+ under the +key+.
|
|
32
|
+
def []=(key, value)
|
|
33
|
+
@cache.delete(key)
|
|
34
|
+
@cache[key] = value
|
|
35
|
+
@cache.shift if @cache.length > @size
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# -*- coding: utf-8; frozen_string_literal: true -*-
|
|
2
|
+
#
|
|
3
|
+
#--
|
|
4
|
+
# Copyright (C) 2009-2019 Thomas Leitner <t_leitner@gmx.at>
|
|
5
|
+
#
|
|
6
|
+
# This file is part of kramdown which is licensed under the MIT.
|
|
7
|
+
#++
|
|
8
|
+
#
|
|
9
|
+
|
|
10
|
+
require 'strscan'
|
|
11
|
+
|
|
12
|
+
module Kramdown
|
|
13
|
+
module Utils
|
|
14
|
+
|
|
15
|
+
# This patched StringScanner adds line number information for current scan position and a
|
|
16
|
+
# start_line_number override for nested StringScanners.
|
|
17
|
+
class StringScanner < ::StringScanner
|
|
18
|
+
|
|
19
|
+
# The start line number. Used for nested StringScanners that scan a sub-string of the source
|
|
20
|
+
# document. The kramdown parser uses this, e.g., for span level parsers.
|
|
21
|
+
attr_reader :start_line_number
|
|
22
|
+
|
|
23
|
+
# Takes the start line number as optional second argument.
|
|
24
|
+
#
|
|
25
|
+
# Note: The original second argument is no longer used so this should be safe.
|
|
26
|
+
def initialize(string, start_line_number = 1)
|
|
27
|
+
super(string)
|
|
28
|
+
@start_line_number = start_line_number || 1
|
|
29
|
+
@previous_pos = 0
|
|
30
|
+
@previous_line_number = @start_line_number
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Sets the byte position of the scan pointer.
|
|
34
|
+
#
|
|
35
|
+
# Note: This also resets some internal variables, so always use pos= when setting the position
|
|
36
|
+
# and don't use any other method for that!
|
|
37
|
+
def pos=(pos)
|
|
38
|
+
if self.pos > pos
|
|
39
|
+
@previous_line_number = @start_line_number
|
|
40
|
+
@previous_pos = 0
|
|
41
|
+
end
|
|
42
|
+
super
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Return information needed to revert the byte position of the string scanner in a performant
|
|
46
|
+
# way.
|
|
47
|
+
#
|
|
48
|
+
# The returned data can be fed to #revert_pos to revert the position to the saved one.
|
|
49
|
+
#
|
|
50
|
+
# Note: Just saving #pos won't be enough.
|
|
51
|
+
def save_pos
|
|
52
|
+
[pos, @previous_pos, @previous_line_number]
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Revert the position to one saved by #save_pos.
|
|
56
|
+
def revert_pos(data)
|
|
57
|
+
self.pos = data[0]
|
|
58
|
+
@previous_pos, @previous_line_number = data[1], data[2]
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Returns the line number for current charpos.
|
|
62
|
+
#
|
|
63
|
+
# NOTE: Requires that all line endings are normalized to '\n'
|
|
64
|
+
#
|
|
65
|
+
# NOTE: Normally we'd have to add one to the count of newlines to get the correct line number.
|
|
66
|
+
# However we add the one indirectly by using a one-based start_line_number.
|
|
67
|
+
def current_line_number
|
|
68
|
+
# Not using string[@previous_pos..best_pos].count('\n') because it is slower
|
|
69
|
+
strscan = ::StringScanner.new(string)
|
|
70
|
+
strscan.pos = @previous_pos
|
|
71
|
+
old_pos = pos + 1
|
|
72
|
+
@previous_line_number += 1 while strscan.skip_until(/\n/) && strscan.pos <= old_pos
|
|
73
|
+
|
|
74
|
+
@previous_pos = (eos? ? pos : pos + 1)
|
|
75
|
+
@previous_line_number
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
end
|
|
81
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# -*- coding: utf-8; frozen_string_literal: true -*-
|
|
2
|
+
#
|
|
3
|
+
#--
|
|
4
|
+
# Copyright (C) 2009-2019 Thomas Leitner <t_leitner@gmx.at>
|
|
5
|
+
#
|
|
6
|
+
# This file is part of kramdown which is licensed under the MIT.
|
|
7
|
+
#++
|
|
8
|
+
#
|
|
9
|
+
# This file is based on code originally from the Stringex library and needs the data files from
|
|
10
|
+
# Stringex to work correctly.
|
|
11
|
+
|
|
12
|
+
module Kramdown
|
|
13
|
+
module Utils
|
|
14
|
+
|
|
15
|
+
# Provides the ability to tranliterate Unicode strings into plain ASCII ones.
|
|
16
|
+
module Unidecoder
|
|
17
|
+
|
|
18
|
+
gem 'stringex'
|
|
19
|
+
path = $:.find do |dir|
|
|
20
|
+
File.directory?(File.join(File.expand_path(dir), "stringex", "unidecoder_data"))
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
if !path
|
|
24
|
+
def self.decode(string)
|
|
25
|
+
string
|
|
26
|
+
end
|
|
27
|
+
else
|
|
28
|
+
|
|
29
|
+
CODEPOINTS = Hash.new do |h, k|
|
|
30
|
+
h[k] = YAML.load_file(File.join(path, "stringex", "unidecoder_data", "#{k}.yml"))
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Transliterate string from Unicode into ASCII.
|
|
34
|
+
def self.decode(string)
|
|
35
|
+
string.gsub(/[^\x00-\x7f]/u) do |codepoint|
|
|
36
|
+
begin
|
|
37
|
+
unpacked = codepoint.unpack("U")[0]
|
|
38
|
+
CODEPOINTS[sprintf("x%02x", unpacked >> 8)][unpacked & 255]
|
|
39
|
+
rescue StandardError
|
|
40
|
+
"?"
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# -*- coding: utf-8; frozen_string_literal: true -*-
|
|
2
|
+
#
|
|
3
|
+
#--
|
|
4
|
+
# Copyright (C) 2009-2019 Thomas Leitner <t_leitner@gmx.at>
|
|
5
|
+
#
|
|
6
|
+
# This file is part of kramdown which is licensed under the MIT.
|
|
7
|
+
#++
|
|
8
|
+
#
|
|
9
|
+
|
|
10
|
+
module Kramdown
|
|
11
|
+
|
|
12
|
+
# The kramdown version.
|
|
13
|
+
VERSION = '2.3.0'
|
|
14
|
+
|
|
15
|
+
end
|
data/man/man1/kramdown.1
ADDED
|
File without changes
|
data/test/run_tests.rb
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# -*- coding: utf-8; frozen_string_literal: true -*-
|
|
2
|
+
#
|
|
3
|
+
#--
|
|
4
|
+
# Copyright (C) 2009-2019 Thomas Leitner <t_leitner@gmx.at>
|
|
5
|
+
#
|
|
6
|
+
# This file is part of kramdown which is licensed under the MIT.
|
|
7
|
+
#++
|
|
8
|
+
#
|
|
9
|
+
|
|
10
|
+
$:.unshift File.dirname(__FILE__) + '/../lib'
|
|
11
|
+
require 'kramdown'
|
|
12
|
+
require 'test/unit/assertions'
|
|
13
|
+
require 'yaml'
|
|
14
|
+
|
|
15
|
+
include Test::Unit::Assertions
|
|
16
|
+
|
|
17
|
+
arg = ARGV[0] || File.join(File.dirname(__FILE__), 'testcases')
|
|
18
|
+
|
|
19
|
+
arg = if File.directory?(arg)
|
|
20
|
+
File.join(arg, '**/*.text')
|
|
21
|
+
else
|
|
22
|
+
arg + '.text'
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
width = ((size = `stty size 2>/dev/null`).length > 0 ? size.split.last.to_i : 72) rescue 72
|
|
26
|
+
width -= 8
|
|
27
|
+
fwidth = 0
|
|
28
|
+
Dir[arg].each {|f| fwidth = [fwidth, f.length + 10].max }.each do |file|
|
|
29
|
+
print(('Testing ' + file + ' ').ljust([fwidth, width].min))
|
|
30
|
+
$stdout.flush
|
|
31
|
+
|
|
32
|
+
html_file = file.sub('.text', '.html')
|
|
33
|
+
opts_file = file.sub('.text', '.options')
|
|
34
|
+
opts_file = File.join(File.dirname(file), 'options') unless File.exist?(opts_file)
|
|
35
|
+
options = File.exist?(opts_file) ? YAML.safe_load(File.read(opts_file)) : {auto_ids: false, footnote_nr: 1}
|
|
36
|
+
doc = Kramdown::Document.new(File.read(file), options)
|
|
37
|
+
begin
|
|
38
|
+
assert_equal(File.read(html_file), doc.to_html)
|
|
39
|
+
puts 'PASSED'
|
|
40
|
+
rescue StandardError
|
|
41
|
+
puts ' FAILED'
|
|
42
|
+
puts $!.message if $VERBOSE
|
|
43
|
+
puts $!.backtrace if $DEBUG
|
|
44
|
+
end
|
|
45
|
+
puts "Warnings:\n" + doc.warnings.join("\n") if !doc.warnings.empty? && $VERBOSE
|
|
46
|
+
end
|
data/test/test_files.rb
ADDED
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
# -*- coding: utf-8; frozen_string_literal: true -*-
|
|
2
|
+
#
|
|
3
|
+
#--
|
|
4
|
+
# Copyright (C) 2009-2019 Thomas Leitner <t_leitner@gmx.at>
|
|
5
|
+
#
|
|
6
|
+
# This file is part of kramdown which is licensed under the MIT.
|
|
7
|
+
#++
|
|
8
|
+
#
|
|
9
|
+
|
|
10
|
+
require 'minitest/autorun'
|
|
11
|
+
require 'kramdown'
|
|
12
|
+
require 'yaml'
|
|
13
|
+
require 'tmpdir'
|
|
14
|
+
require 'open3'
|
|
15
|
+
|
|
16
|
+
begin
|
|
17
|
+
require 'kramdown/converter/syntax_highlighter/rouge'
|
|
18
|
+
|
|
19
|
+
Kramdown::Converter::SyntaxHighlighter::Rouge.formatter_class.send(:define_method, :format) do |tokens, &b|
|
|
20
|
+
super(tokens, &b).sub(/<\/code><\/pre>\n?/, "</code></pre>\n")
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# custom formatter for tests
|
|
24
|
+
class RougeHTMLFormatters < Kramdown::Converter::SyntaxHighlighter::Rouge.formatter_class
|
|
25
|
+
|
|
26
|
+
tag 'rouge_html_formatters'
|
|
27
|
+
|
|
28
|
+
def stream(tokens, &b)
|
|
29
|
+
yield %(<div class="custom-class">)
|
|
30
|
+
super
|
|
31
|
+
yield %(</div>)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end
|
|
35
|
+
rescue LoadError, SyntaxError, NameError
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
Encoding.default_external = 'utf-8'
|
|
39
|
+
|
|
40
|
+
class TestFiles < Minitest::Test
|
|
41
|
+
|
|
42
|
+
EXCLUDE_KD_FILES = [].compact
|
|
43
|
+
|
|
44
|
+
# Generate test methods for kramdown-to-xxx conversion
|
|
45
|
+
Dir[File.dirname(__FILE__) + '/testcases/**/*.text'].each do |text_file|
|
|
46
|
+
next if EXCLUDE_KD_FILES.any? {|f| text_file =~ /#{f}/ }
|
|
47
|
+
basename = text_file.sub(/\.text$/, '')
|
|
48
|
+
opts_file = text_file.sub(/\.text$/, '.options')
|
|
49
|
+
(Dir[basename + ".*"] - [text_file, opts_file]).each do |output_file|
|
|
50
|
+
output_format = File.extname(output_file)[1..-1]
|
|
51
|
+
next unless Kramdown::Converter.const_defined?(output_format[0..0].upcase + output_format[1..-1])
|
|
52
|
+
define_method('test_' + text_file.tr('.', '_') + "_to_#{output_format}") do
|
|
53
|
+
opts_file = File.join(File.dirname(text_file), 'options') unless File.exist?(opts_file)
|
|
54
|
+
options = File.exist?(opts_file) ? YAML.load(File.read(opts_file)) : {auto_ids: false, footnote_nr: 1}
|
|
55
|
+
doc = Kramdown::Document.new(File.read(text_file), options)
|
|
56
|
+
assert_equal(File.read(output_file), doc.send("to_#{output_format}"))
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Generate test methods for html-to-{html,kramdown} conversion
|
|
62
|
+
`tidy -v 2>&1`
|
|
63
|
+
if $?.exitstatus != 0
|
|
64
|
+
warn("Skipping html-to-{html,kramdown} tests because tidy executable is missing")
|
|
65
|
+
else
|
|
66
|
+
EXCLUDE_HTML_FILES = [
|
|
67
|
+
'test/testcases/block/06_codeblock/whitespace.html', # bc of span inside pre
|
|
68
|
+
'test/testcases/block/09_html/simple.html', # bc of xml elements
|
|
69
|
+
'test/testcases/span/03_codespan/highlighting.html', # bc of span elements inside code element
|
|
70
|
+
'test/testcases/block/04_header/with_auto_ids.html', # bc of auto_ids=true option
|
|
71
|
+
'test/testcases/block/04_header/header_type_offset.html', # bc of header_offset option
|
|
72
|
+
'test/testcases/block/06_codeblock/rouge/simple.html', # bc of double surrounding <div>
|
|
73
|
+
'test/testcases/block/06_codeblock/rouge/multiple.html', # bc of double surrounding <div>
|
|
74
|
+
'test/testcases/block/06_codeblock/highlighting.html', # bc of span elements inside code element
|
|
75
|
+
'test/testcases/block/06_codeblock/highlighting-opts.html', # bc of span elements inside code element
|
|
76
|
+
'test/testcases/block/06_codeblock/guess_lang_css_class.html', # bc of double surrounding <div>
|
|
77
|
+
'test/testcases/block/12_extension/options3.html', # bc of rouge
|
|
78
|
+
'test/testcases/block/14_table/empty_tag_in_cell.html', # bc of tidy
|
|
79
|
+
'test/testcases/block/15_math/mathjax_preview.html', # bc of mathjax preview
|
|
80
|
+
'test/testcases/block/15_math/mathjax_preview_simple.html', # bc of mathjax preview
|
|
81
|
+
'test/testcases/block/15_math/mathjax_preview_as_code.html', # bc of mathjax preview
|
|
82
|
+
'test/testcases/span/05_html/mark_element.html', # bc of tidy
|
|
83
|
+
'test/testcases/block/09_html/xml.html', # bc of tidy
|
|
84
|
+
'test/testcases/span/05_html/xml.html', # bc of tidy
|
|
85
|
+
].compact
|
|
86
|
+
EXCLUDE_HTML_TEXT_FILES = [
|
|
87
|
+
'test/testcases/block/09_html/parse_as_span.htmlinput',
|
|
88
|
+
'test/testcases/block/09_html/parse_as_raw.htmlinput',
|
|
89
|
+
].compact
|
|
90
|
+
Dir[File.dirname(__FILE__) + '/testcases/**/*.{html,htmlinput}'].each do |html_file|
|
|
91
|
+
next if EXCLUDE_HTML_FILES.any? {|f| html_file =~ /#{f}/ }
|
|
92
|
+
|
|
93
|
+
out_files = []
|
|
94
|
+
out_files << [(html_file =~ /\.htmlinput$/ ? html_file.sub(/input$/, '') : html_file), :to_html]
|
|
95
|
+
if html_file =~ /\.htmlinput$/ && EXCLUDE_HTML_TEXT_FILES.none? {|f| html_file =~ /#{f}/ }
|
|
96
|
+
out_files << [html_file.sub(/htmlinput$/, 'text'), :to_kramdown]
|
|
97
|
+
end
|
|
98
|
+
out_files.select {|f, _| File.exist?(f) }.each do |out_file, out_method|
|
|
99
|
+
define_method('test_' + html_file.tr('.', '_') + "_to_#{File.extname(out_file)}") do
|
|
100
|
+
opts_file = html_file.sub(/\.html(input)?$/, '.options')
|
|
101
|
+
opts_file = File.join(File.dirname(html_file), 'options') unless File.exist?(opts_file)
|
|
102
|
+
options = File.exist?(opts_file) ? YAML.load(File.read(opts_file)) : {auto_ids: false, footnote_nr: 1}
|
|
103
|
+
doc = Kramdown::Document.new(File.read(html_file), options.merge(input: 'html'))
|
|
104
|
+
if out_method == :to_html
|
|
105
|
+
assert_equal(tidy_output(File.read(out_file)), tidy_output(doc.send(out_method)))
|
|
106
|
+
else
|
|
107
|
+
assert_equal(File.read(out_file), doc.send(out_method))
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def tidy_output(out)
|
|
115
|
+
return true
|
|
116
|
+
cmd = "tidy -q --doctype omit -utf8"
|
|
117
|
+
result, error, status = Open3.capture3(cmd, stdin_data: out)
|
|
118
|
+
if status.exitstatus == 2
|
|
119
|
+
raise "Problem using tidy: #{error}"
|
|
120
|
+
end
|
|
121
|
+
result
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# Generate test methods for text-to-latex conversion and compilation
|
|
125
|
+
`latex -v 2>&1`
|
|
126
|
+
if $?.exitstatus != 0
|
|
127
|
+
warn("Skipping latex compilation tests because latex executable is missing")
|
|
128
|
+
else
|
|
129
|
+
EXCLUDE_LATEX_FILES = [
|
|
130
|
+
'test/testcases/span/01_link/image_in_a.text', # bc of image link
|
|
131
|
+
'test/testcases/span/01_link/imagelinks.text', # bc of image links
|
|
132
|
+
'test/testcases/span/01_link/empty_title.text',
|
|
133
|
+
'test/testcases/span/04_footnote/markers.text', # bc of footnote in header
|
|
134
|
+
'test/testcases/block/06_codeblock/with_lang_in_fenced_block_name_with_dash.text',
|
|
135
|
+
'test/testcases/block/06_codeblock/with_lang_in_fenced_block_any_char.text',
|
|
136
|
+
'test/testcases/block/03_paragraph/standalone_image.text', # bc of standalone image
|
|
137
|
+
'test/testcases/cjk-line-break.text', # latex unicode support
|
|
138
|
+
].compact
|
|
139
|
+
Dir[File.dirname(__FILE__) + '/testcases/**/*.text'].each do |text_file|
|
|
140
|
+
next if EXCLUDE_LATEX_FILES.any? {|f| text_file =~ /#{f}$/ }
|
|
141
|
+
define_method('test_' + text_file.tr('.', '_') + "_to_latex_compilation") do
|
|
142
|
+
latex = Kramdown::Document.new(File.read(text_file), auto_ids: false, footnote_nr: 1,
|
|
143
|
+
template: 'document').to_latex
|
|
144
|
+
Dir.mktmpdir do |tmpdir|
|
|
145
|
+
result = IO.popen("latex -output-directory='#{tmpdir}' 2>/dev/null", 'r+') do |io|
|
|
146
|
+
io.write(latex)
|
|
147
|
+
io.close_write
|
|
148
|
+
io.read
|
|
149
|
+
end
|
|
150
|
+
assert($?.exitstatus == 0, result.scan(/^!(.*\n.*)/).join("\n"))
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
# Generate test methods for text->kramdown->html conversion
|
|
157
|
+
`tidy -v 2>&1`
|
|
158
|
+
if $?.exitstatus != 0
|
|
159
|
+
warn("Skipping text->kramdown->html tests because tidy executable is missing")
|
|
160
|
+
else
|
|
161
|
+
EXCLUDE_TEXT_FILES = [
|
|
162
|
+
'test/testcases/span/05_html/markdown_attr.text', # bc of markdown attr
|
|
163
|
+
'test/testcases/block/09_html/markdown_attr.text', # bc of markdown attr
|
|
164
|
+
'test/testcases/span/extension/options.text', # bc of parse_span_html option
|
|
165
|
+
'test/testcases/block/12_extension/options.text', # bc of options option
|
|
166
|
+
'test/testcases/block/12_extension/options3.text', # bc of options option
|
|
167
|
+
'test/testcases/block/09_html/content_model/tables.text', # bc of parse_block_html option
|
|
168
|
+
'test/testcases/block/09_html/html_to_native/header.text', # bc of auto_ids option that interferes
|
|
169
|
+
'test/testcases/block/09_html/html_to_native/table_simple.text', # bc of tr style attr getting removed
|
|
170
|
+
'test/testcases/block/09_html/simple.text', # bc of webgen:block elements
|
|
171
|
+
'test/testcases/block/11_ial/simple.text', # bc of change of ordering of attributes in header
|
|
172
|
+
'test/testcases/span/extension/comment.text', # bc of comment text modifications (can this be avoided?)
|
|
173
|
+
'test/testcases/block/04_header/header_type_offset.text', # bc of header_offset being applied twice
|
|
174
|
+
'test/testcases/block/06_codeblock/rouge/simple.text',
|
|
175
|
+
'test/testcases/block/06_codeblock/rouge/multiple.text', # check, what document contain more, than one code block
|
|
176
|
+
'test/testcases/block/14_table/empty_tag_in_cell.text', # bc of tidy
|
|
177
|
+
'test/testcases/span/01_link/link_defs_with_ial.text', # bc of attribute ordering
|
|
178
|
+
'test/testcases/span/05_html/mark_element.text', # bc of tidy
|
|
179
|
+
'test/testcases/block/09_html/xml.text', # bc of tidy
|
|
180
|
+
'test/testcases/span/05_html/xml.text', # bc of tidy
|
|
181
|
+
'test/testcases/block/03_paragraph/standalone_image.text', # bc of standalone image
|
|
182
|
+
'test/testcases/cjk-line-break.text',
|
|
183
|
+
'test/testcases/block/09_html/standalone_image_in_div.html', # bc of standalone image
|
|
184
|
+
].compact
|
|
185
|
+
Dir[File.dirname(__FILE__) + '/testcases/**/*.text'].each do |text_file|
|
|
186
|
+
next if EXCLUDE_TEXT_FILES.any? {|f| text_file =~ /#{f}$/ }
|
|
187
|
+
html_file = text_file.sub(/\.text$/, '.html')
|
|
188
|
+
next unless File.exist?(html_file)
|
|
189
|
+
define_method('test_' + text_file.tr('.', '_') + "_to_kramdown_to_html") do
|
|
190
|
+
opts_file = text_file.sub(/\.text$/, '.options')
|
|
191
|
+
opts_file = File.join(File.dirname(text_file), 'options') unless File.exist?(opts_file)
|
|
192
|
+
options = File.exist?(opts_file) ? YAML.load(File.read(opts_file)) : {auto_ids: false, footnote_nr: 1}
|
|
193
|
+
kdtext = Kramdown::Document.new(File.read(text_file), options).to_kramdown
|
|
194
|
+
html = Kramdown::Document.new(kdtext, options).to_html
|
|
195
|
+
assert_equal(tidy_output(File.read(html_file)), tidy_output(html))
|
|
196
|
+
end
|
|
197
|
+
end
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
# Generate test methods for html-to-kramdown-to-html conversion
|
|
201
|
+
`tidy -v 2>&1`
|
|
202
|
+
if $?.exitstatus != 0
|
|
203
|
+
warn("Skipping html-to-kramdown-to-html tests because tidy executable is missing")
|
|
204
|
+
else
|
|
205
|
+
EXCLUDE_HTML_KD_FILES = [
|
|
206
|
+
'test/testcases/span/extension/options.html', # bc of parse_span_html option
|
|
207
|
+
'test/testcases/span/05_html/normal.html', # bc of br tag before closing p tag
|
|
208
|
+
'test/testcases/block/12_extension/nomarkdown.html', # bc of nomarkdown extension
|
|
209
|
+
'test/testcases/block/12_extension/options3.html', # bc of rouge
|
|
210
|
+
'test/testcases/block/09_html/simple.html', # bc of webgen:block elements
|
|
211
|
+
'test/testcases/block/09_html/markdown_attr.html', # bc of markdown attr
|
|
212
|
+
'test/testcases/block/09_html/html_to_native/table_simple.html', # bc of invalidly converted simple table
|
|
213
|
+
'test/testcases/block/06_codeblock/whitespace.html', # bc of entity to char conversion
|
|
214
|
+
'test/testcases/block/06_codeblock/rouge/simple.html', # bc of double surrounding <div>
|
|
215
|
+
'test/testcases/block/06_codeblock/rouge/multiple.html', # bc of double surrounding <div>
|
|
216
|
+
'test/testcases/block/06_codeblock/guess_lang_css_class.html', # bc of double surrounding <div>
|
|
217
|
+
'test/testcases/block/06_codeblock/highlighting.html', # bc of span elements inside code element
|
|
218
|
+
'test/testcases/block/06_codeblock/highlighting-opts.html', # bc of span elements inside code element
|
|
219
|
+
'test/testcases/block/11_ial/simple.html', # bc of change of ordering of attributes in header
|
|
220
|
+
'test/testcases/span/03_codespan/highlighting.html', # bc of span elements inside code element
|
|
221
|
+
'test/testcases/block/04_header/with_auto_ids.html', # bc of auto_ids=true option
|
|
222
|
+
'test/testcases/block/04_header/header_type_offset.html', # bc of header_offset option
|
|
223
|
+
'test/testcases/block/16_toc/toc_exclude.html', # bc of different attribute ordering
|
|
224
|
+
'test/testcases/span/autolinks/url_links.html', # bc of quot entity being converted to char
|
|
225
|
+
'test/testcases/block/14_table/empty_tag_in_cell.html', # bc of tidy
|
|
226
|
+
'test/testcases/span/01_link/link_defs_with_ial.html', # bc of attribute ordering
|
|
227
|
+
'test/testcases/span/05_html/mark_element.html', # bc of tidy
|
|
228
|
+
'test/testcases/block/09_html/xml.html', # bc of tidy
|
|
229
|
+
'test/testcases/span/05_html/xml.html', # bc of tidy
|
|
230
|
+
'test/testcases/block/03_paragraph/standalone_image.html', # bc of standalone image
|
|
231
|
+
'test/testcases/block/15_math/normal.html', # bc of mathjax and HTML parser
|
|
232
|
+
'test/testcases/block/15_math/gh_128.html', # bc of mathjax and HTML parser
|
|
233
|
+
'test/testcases/span/04_footnote/backlink_inline.html', # bc of mathjax
|
|
234
|
+
'test/testcases/block/09_html/standalone_image_in_div.html', # bc of standalone image
|
|
235
|
+
'test/testcases/block/09_html/processing_instruction.html', # bc of PI
|
|
236
|
+
].compact
|
|
237
|
+
Dir[File.dirname(__FILE__) + '/testcases/**/*.html'].each do |html_file|
|
|
238
|
+
next if EXCLUDE_HTML_KD_FILES.any? {|f| html_file =~ /#{f}$/ }
|
|
239
|
+
define_method('test_' + html_file.tr('.', '_') + "_to_kramdown_to_html") do
|
|
240
|
+
kd = Kramdown::Document.new(File.read(html_file), input: 'html',
|
|
241
|
+
auto_ids: false, footnote_nr: 1).to_kramdown
|
|
242
|
+
opts_file = html_file.sub(/\.html$/, '.options')
|
|
243
|
+
opts_file = File.join(File.dirname(html_file), 'options') unless File.exist?(opts_file)
|
|
244
|
+
options = File.exist?(opts_file) ? YAML.load(File.read(opts_file)) : {auto_ids: false, footnote_nr: 1}
|
|
245
|
+
doc = Kramdown::Document.new(kd, options)
|
|
246
|
+
assert_equal(tidy_output(File.read(html_file)), tidy_output(doc.to_html))
|
|
247
|
+
end
|
|
248
|
+
end
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
# Generate test methods for text-manpage conversion
|
|
252
|
+
Dir[File.dirname(__FILE__) + '/testcases/man/**/*.text'].each do |text_file|
|
|
253
|
+
define_method('test_' + text_file.tr('.', '_') + "_to_man") do
|
|
254
|
+
man_file = text_file.sub(/\.text$/, '.man')
|
|
255
|
+
doc = Kramdown::Document.new(File.read(text_file))
|
|
256
|
+
assert_equal(File.read(man_file), doc.to_man)
|
|
257
|
+
end
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
EXCLUDE_MODIFY = [
|
|
261
|
+
'test/testcases/block/06_codeblock/rouge/multiple.text', # bc of HTMLFormater in options
|
|
262
|
+
].compact
|
|
263
|
+
|
|
264
|
+
# Generate test methods for asserting that converters don't modify the document tree.
|
|
265
|
+
Dir[File.dirname(__FILE__) + '/testcases/**/*.text'].each do |text_file|
|
|
266
|
+
opts_file = text_file.sub(/\.text$/, '.options')
|
|
267
|
+
options = File.exist?(opts_file) ? YAML.load(File.read(opts_file)) : {auto_ids: false, footnote_nr: 1}
|
|
268
|
+
(Kramdown::Converter.constants.map(&:to_sym) -
|
|
269
|
+
[:Base, :RemoveHtmlTags, :MathEngine, :SyntaxHighlighter]).each do |conv_class|
|
|
270
|
+
next if EXCLUDE_MODIFY.any? {|f| text_file =~ /#{f}$/ }
|
|
271
|
+
define_method("test_whether_#{conv_class}_modifies_tree_with_file_#{text_file.tr('.', '_')}") do
|
|
272
|
+
doc = Kramdown::Document.new(File.read(text_file), options)
|
|
273
|
+
options_before = Marshal.load(Marshal.dump(doc.options))
|
|
274
|
+
tree_before = Marshal.load(Marshal.dump(doc.root))
|
|
275
|
+
Kramdown::Converter.const_get(conv_class).convert(doc.root, doc.options)
|
|
276
|
+
assert_equal(options_before, doc.options)
|
|
277
|
+
assert_tree_not_changed(tree_before, doc.root)
|
|
278
|
+
end
|
|
279
|
+
end
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
def assert_tree_not_changed(old, new)
|
|
283
|
+
assert_equal(old.type, new.type, "type mismatch")
|
|
284
|
+
if old.value.kind_of?(Kramdown::Element)
|
|
285
|
+
assert_tree_not_changed(old.value, new.value)
|
|
286
|
+
else
|
|
287
|
+
assert(old.value == new.value, "value mismatch")
|
|
288
|
+
end
|
|
289
|
+
assert_equal(old.attr, new.attr, "attr mismatch")
|
|
290
|
+
assert_equal(old.options, new.options, "options mismatch")
|
|
291
|
+
assert_equal(old.children.length, new.children.length, "children count mismatch")
|
|
292
|
+
|
|
293
|
+
old.children.each_with_index do |child, index|
|
|
294
|
+
assert_tree_not_changed(child, new.children[index])
|
|
295
|
+
end
|
|
296
|
+
end
|
|
297
|
+
|
|
298
|
+
end
|