daqing_kramdown 2.3.1
Sign up to get free protection for your applications and to get access to all the features.
- 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,448 @@
|
|
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 'kramdown/converter'
|
11
|
+
require 'kramdown/utils'
|
12
|
+
|
13
|
+
module Kramdown
|
14
|
+
|
15
|
+
module Converter
|
16
|
+
|
17
|
+
# Converts an element tree to the kramdown format.
|
18
|
+
class Kramdown < Base
|
19
|
+
|
20
|
+
# :stopdoc:
|
21
|
+
|
22
|
+
include ::Kramdown::Utils::Html
|
23
|
+
|
24
|
+
def initialize(root, options)
|
25
|
+
super
|
26
|
+
@linkrefs = []
|
27
|
+
@footnotes = []
|
28
|
+
@abbrevs = []
|
29
|
+
@stack = []
|
30
|
+
end
|
31
|
+
|
32
|
+
def convert(el, opts = {indent: 0})
|
33
|
+
res = send("convert_#{el.type}", el, opts)
|
34
|
+
res = res.dup if res.frozen?
|
35
|
+
if ![:html_element, :li, :dt, :dd, :td].include?(el.type) && (ial = ial_for_element(el))
|
36
|
+
res << ial
|
37
|
+
res << "\n\n" if el.block?
|
38
|
+
elsif [:ul, :dl, :ol, :codeblock].include?(el.type) && opts[:next] &&
|
39
|
+
([el.type, :codeblock].include?(opts[:next].type) ||
|
40
|
+
(opts[:next].type == :blank && opts[:nnext] &&
|
41
|
+
[el.type, :codeblock].include?(opts[:nnext].type)))
|
42
|
+
res << "^\n\n"
|
43
|
+
elsif el.block? &&
|
44
|
+
![:li, :dd, :dt, :td, :th, :tr, :thead, :tbody, :tfoot, :blank].include?(el.type) &&
|
45
|
+
(el.type != :html_element || @stack.last.type != :html_element) &&
|
46
|
+
(el.type != :p || !el.options[:transparent])
|
47
|
+
res << "\n"
|
48
|
+
end
|
49
|
+
res
|
50
|
+
end
|
51
|
+
|
52
|
+
def inner(el, opts = {indent: 0})
|
53
|
+
@stack.push(el)
|
54
|
+
result = +''
|
55
|
+
el.children.each_with_index do |inner_el, index|
|
56
|
+
options = opts.dup
|
57
|
+
options[:index] = index
|
58
|
+
options[:prev] = (index == 0 ? nil : el.children[index - 1])
|
59
|
+
options[:pprev] = (index <= 1 ? nil : el.children[index - 2])
|
60
|
+
options[:next] = (index == el.children.length - 1 ? nil : el.children[index + 1])
|
61
|
+
options[:nnext] = (index >= el.children.length - 2 ? nil : el.children[index + 2])
|
62
|
+
result << convert(inner_el, options)
|
63
|
+
end
|
64
|
+
@stack.pop
|
65
|
+
result
|
66
|
+
end
|
67
|
+
|
68
|
+
def convert_blank(_el, _opts)
|
69
|
+
""
|
70
|
+
end
|
71
|
+
|
72
|
+
ESCAPED_CHAR_RE = /(\$\$|[\\*_`\[\]\{"'|])|^[ ]{0,3}(:)/
|
73
|
+
|
74
|
+
def convert_text(el, opts)
|
75
|
+
if opts[:raw_text]
|
76
|
+
el.value
|
77
|
+
else
|
78
|
+
el.value.gsub(/\A\n/) do
|
79
|
+
opts[:prev] && opts[:prev].type == :br ? '' : "\n"
|
80
|
+
end.gsub(/\s+/, ' ').gsub(ESCAPED_CHAR_RE) { "\\#{$1 || $2}" }
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def convert_p(el, opts)
|
85
|
+
w = @options[:line_width] - opts[:indent].to_s.to_i
|
86
|
+
first, second, *rest = inner(el, opts).strip.gsub(/(.{1,#{w}})( +|$\n?)/, "\\1\n").split(/\n/)
|
87
|
+
first&.gsub!(/^(?:(#|>)|(\d+)\.|([+-]\s))/) { $1 || $3 ? "\\#{$1 || $3}" : "#{$2}\\." }
|
88
|
+
second&.gsub!(/^([=-]+\s*?)$/, "\\\1")
|
89
|
+
res = [first, second, *rest].compact.join("\n") + "\n"
|
90
|
+
if el.children.length == 1 && el.children.first.type == :math
|
91
|
+
res = "\\#{res}"
|
92
|
+
elsif res.start_with?('\$$') && res.end_with?("\\$$\n")
|
93
|
+
res.sub!(/^\\\$\$/, '\$\$')
|
94
|
+
end
|
95
|
+
res
|
96
|
+
end
|
97
|
+
|
98
|
+
def convert_codeblock(el, _opts)
|
99
|
+
el.value.split(/\n/).map {|l| l.empty? ? " " : " #{l}" }.join("\n") + "\n"
|
100
|
+
end
|
101
|
+
|
102
|
+
def convert_blockquote(el, opts)
|
103
|
+
opts[:indent] += 2
|
104
|
+
inner(el, opts).chomp.split(/\n/).map {|l| "> #{l}" }.join("\n") << "\n"
|
105
|
+
end
|
106
|
+
|
107
|
+
def convert_header(el, opts)
|
108
|
+
res = +''
|
109
|
+
res << "#{'#' * output_header_level(el.options[:level])} #{inner(el, opts)}"
|
110
|
+
res[-1, 1] = "\\#" if res[-1] == '#'
|
111
|
+
res << " {##{el.attr['id']}}" if el.attr['id'] && !el.attr['id'].strip.empty?
|
112
|
+
res << "\n"
|
113
|
+
end
|
114
|
+
|
115
|
+
def convert_hr(_el, _opts)
|
116
|
+
"* * *\n"
|
117
|
+
end
|
118
|
+
|
119
|
+
def convert_ul(el, opts)
|
120
|
+
inner(el, opts).sub(/\n+\Z/, "\n")
|
121
|
+
end
|
122
|
+
alias convert_ol convert_ul
|
123
|
+
alias convert_dl convert_ul
|
124
|
+
|
125
|
+
def convert_li(el, opts)
|
126
|
+
sym, width = if @stack.last.type == :ul
|
127
|
+
[+'* ', el.children.first && el.children.first.type == :codeblock ? 4 : 2]
|
128
|
+
else
|
129
|
+
["#{opts[:index] + 1}.".ljust(4), 4]
|
130
|
+
end
|
131
|
+
if (ial = ial_for_element(el))
|
132
|
+
sym << ial << " "
|
133
|
+
end
|
134
|
+
|
135
|
+
opts[:indent] += width
|
136
|
+
text = inner(el, opts)
|
137
|
+
newlines = text.scan(/\n*\Z/).first
|
138
|
+
first, *last = text.split(/\n/)
|
139
|
+
last = last.map {|l| " " * width + l }.join("\n")
|
140
|
+
text = (first.nil? ? "\n" : first + (last.empty? ? "" : "\n") + last + newlines)
|
141
|
+
if el.children.first && el.children.first.type == :p && !el.children.first.options[:transparent]
|
142
|
+
res = +"#{sym}#{text}"
|
143
|
+
res << "^\n" if el.children.size == 1 && @stack.last.children.last == el &&
|
144
|
+
(@stack.last.children.any? {|c| c.children.first.type != :p } || @stack.last.children.size == 1)
|
145
|
+
res
|
146
|
+
elsif el.children.first && el.children.first.type == :codeblock
|
147
|
+
"#{sym}\n #{text}"
|
148
|
+
else
|
149
|
+
"#{sym}#{text}"
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def convert_dd(el, opts)
|
154
|
+
sym, width = +": ", (el.children.first && el.children.first.type == :codeblock ? 4 : 2)
|
155
|
+
if (ial = ial_for_element(el))
|
156
|
+
sym << ial << " "
|
157
|
+
end
|
158
|
+
|
159
|
+
opts[:indent] += width
|
160
|
+
text = inner(el, opts)
|
161
|
+
newlines = text.scan(/\n*\Z/).first
|
162
|
+
first, *last = text.split(/\n/)
|
163
|
+
last = last.map {|l| " " * width + l }.join("\n")
|
164
|
+
text = first.to_s + (last.empty? ? "" : "\n") + last + newlines
|
165
|
+
text.chomp! if text =~ /\n\n\Z/ && opts[:next] && opts[:next].type == :dd
|
166
|
+
text << "\n" if text !~ /\n\n\Z/ && opts[:next] && opts[:next].type == :dt
|
167
|
+
text << "\n" if el.children.empty?
|
168
|
+
if el.children.first && el.children.first.type == :p && !el.children.first.options[:transparent]
|
169
|
+
"\n#{sym}#{text}"
|
170
|
+
elsif el.children.first && el.children.first.type == :codeblock
|
171
|
+
"#{sym}\n #{text}"
|
172
|
+
else
|
173
|
+
"#{sym}#{text}"
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
def convert_dt(el, opts)
|
178
|
+
result = +''
|
179
|
+
if (ial = ial_for_element(el))
|
180
|
+
result << ial << " "
|
181
|
+
end
|
182
|
+
result << inner(el, opts) << "\n"
|
183
|
+
end
|
184
|
+
|
185
|
+
HTML_TAGS_WITH_BODY = ['div', 'script', 'iframe', 'textarea']
|
186
|
+
|
187
|
+
HTML_ELEMENT_TYPES = [:entity, :text, :html_element].freeze
|
188
|
+
private_constant :HTML_ELEMENT_TYPES
|
189
|
+
|
190
|
+
def convert_html_element(el, opts)
|
191
|
+
markdown_attr = el.options[:category] == :block && el.children.any? do |c|
|
192
|
+
c.type != :html_element &&
|
193
|
+
(c.type != :p || !c.options[:transparent] ||
|
194
|
+
c.children.any? {|t| !HTML_ELEMENT_TYPES.member?(t.type) }) &&
|
195
|
+
c.block?
|
196
|
+
end
|
197
|
+
opts[:force_raw_text] = true if %w[script pre code].include?(el.value)
|
198
|
+
opts[:raw_text] = opts[:force_raw_text] || opts[:block_raw_text] || \
|
199
|
+
(el.options[:category] != :span && !markdown_attr)
|
200
|
+
opts[:block_raw_text] = true if el.options[:category] == :block && opts[:raw_text]
|
201
|
+
res = inner(el, opts)
|
202
|
+
if el.options[:category] == :span
|
203
|
+
"<#{el.value}#{html_attributes(el.attr)}" + \
|
204
|
+
(!res.empty? || HTML_TAGS_WITH_BODY.include?(el.value) ? ">#{res}</#{el.value}>" : " />")
|
205
|
+
else
|
206
|
+
output = +''
|
207
|
+
attr = el.attr.dup
|
208
|
+
attr['markdown'] = '1' if markdown_attr
|
209
|
+
output << "<#{el.value}#{html_attributes(attr)}"
|
210
|
+
if !res.empty? && el.options[:content_model] != :block
|
211
|
+
output << ">#{res}</#{el.value}>"
|
212
|
+
elsif !res.empty?
|
213
|
+
output << ">\n#{res}" << "</#{el.value}>"
|
214
|
+
elsif HTML_TAGS_WITH_BODY.include?(el.value)
|
215
|
+
output << "></#{el.value}>"
|
216
|
+
else
|
217
|
+
output << " />"
|
218
|
+
end
|
219
|
+
output << "\n" if @stack.last.type != :html_element || @stack.last.options[:content_model] != :raw
|
220
|
+
output
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
def convert_xml_comment(el, _opts)
|
225
|
+
if el.options[:category] == :block &&
|
226
|
+
(@stack.last.type != :html_element || @stack.last.options[:content_model] != :raw)
|
227
|
+
el.value + "\n"
|
228
|
+
else
|
229
|
+
el.value.dup
|
230
|
+
end
|
231
|
+
end
|
232
|
+
alias convert_xml_pi convert_xml_comment
|
233
|
+
|
234
|
+
def convert_table(el, opts)
|
235
|
+
opts[:alignment] = el.options[:alignment]
|
236
|
+
inner(el, opts)
|
237
|
+
end
|
238
|
+
|
239
|
+
def convert_thead(el, opts)
|
240
|
+
rows = inner(el, opts)
|
241
|
+
if opts[:alignment].all? {|a| a == :default }
|
242
|
+
"#{rows}|#{'-' * 10}\n"
|
243
|
+
else
|
244
|
+
"#{rows}| " + opts[:alignment].map do |a|
|
245
|
+
case a
|
246
|
+
when :left then ":-"
|
247
|
+
when :right then "-:"
|
248
|
+
when :center then ":-:"
|
249
|
+
when :default then "-"
|
250
|
+
end
|
251
|
+
end.join(' ') << "\n"
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
def convert_tbody(el, opts)
|
256
|
+
res = +''
|
257
|
+
res << inner(el, opts)
|
258
|
+
res << '|' << '-' * 10 << "\n" if opts[:next] && opts[:next].type == :tbody
|
259
|
+
res
|
260
|
+
end
|
261
|
+
|
262
|
+
def convert_tfoot(el, opts)
|
263
|
+
"|#{'=' * 10}\n#{inner(el, opts)}"
|
264
|
+
end
|
265
|
+
|
266
|
+
def convert_tr(el, opts)
|
267
|
+
"| #{el.children.map {|c| convert(c, opts) }.join(' | ')} |\n"
|
268
|
+
end
|
269
|
+
|
270
|
+
def convert_td(el, opts)
|
271
|
+
inner(el, opts)
|
272
|
+
end
|
273
|
+
|
274
|
+
def convert_comment(el, _opts)
|
275
|
+
if el.options[:category] == :block
|
276
|
+
"{::comment}\n#{el.value}\n{:/}\n"
|
277
|
+
else
|
278
|
+
"{::comment}#{el.value}{:/}"
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
def convert_br(_el, _opts)
|
283
|
+
" \n"
|
284
|
+
end
|
285
|
+
|
286
|
+
def convert_a(el, opts)
|
287
|
+
if el.attr['href'].empty?
|
288
|
+
"[#{inner(el, opts)}]()"
|
289
|
+
elsif el.attr['href'] =~ /^(?:http|ftp)/ || el.attr['href'].count("()") > 0
|
290
|
+
index = if (link_el = @linkrefs.find {|c| c.attr['href'] == el.attr['href'] })
|
291
|
+
@linkrefs.index(link_el) + 1
|
292
|
+
else
|
293
|
+
@linkrefs << el
|
294
|
+
@linkrefs.size
|
295
|
+
end
|
296
|
+
"[#{inner(el, opts)}][#{index}]"
|
297
|
+
else
|
298
|
+
title = parse_title(el.attr['title'])
|
299
|
+
"[#{inner(el, opts)}](#{el.attr['href']}#{title})"
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
def convert_img(el, _opts)
|
304
|
+
alt_text = el.attr['alt'].to_s.gsub(ESCAPED_CHAR_RE) { $1 ? "\\#{$1}" : $2 }
|
305
|
+
src = el.attr['src'].to_s
|
306
|
+
if src.empty?
|
307
|
+
"![#{alt_text}]()"
|
308
|
+
else
|
309
|
+
title = parse_title(el.attr['title'])
|
310
|
+
link = if src.count("()") > 0
|
311
|
+
"<#{src}>"
|
312
|
+
else
|
313
|
+
src
|
314
|
+
end
|
315
|
+
"![#{alt_text}](#{link}#{title})"
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
def convert_codespan(el, _opts)
|
320
|
+
delim = (el.value.scan(/`+/).max || '') + '`'
|
321
|
+
"#{delim}#{' ' if delim.size > 1}#{el.value}#{' ' if delim.size > 1}#{delim}"
|
322
|
+
end
|
323
|
+
|
324
|
+
def convert_footnote(el, _opts)
|
325
|
+
@footnotes << [el.options[:name], el.value]
|
326
|
+
"[^#{el.options[:name]}]"
|
327
|
+
end
|
328
|
+
|
329
|
+
def convert_raw(el, _opts)
|
330
|
+
attr = (el.options[:type] || []).join(' ')
|
331
|
+
attr = " type=\"#{attr}\"" unless attr.empty?
|
332
|
+
if @stack.last.type == :html_element
|
333
|
+
el.value
|
334
|
+
elsif el.options[:category] == :block
|
335
|
+
"{::nomarkdown#{attr}}\n#{el.value}\n{:/}\n"
|
336
|
+
else
|
337
|
+
"{::nomarkdown#{attr}}#{el.value}{:/}"
|
338
|
+
end
|
339
|
+
end
|
340
|
+
|
341
|
+
def convert_em(el, opts)
|
342
|
+
"*#{inner(el, opts)}*" +
|
343
|
+
(opts[:next] && [:em, :strong].include?(opts[:next].type) && !ial_for_element(el) ? '{::}' : '')
|
344
|
+
end
|
345
|
+
|
346
|
+
def convert_strong(el, opts)
|
347
|
+
"**#{inner(el, opts)}**" +
|
348
|
+
(opts[:next] && [:em, :strong].include?(opts[:next].type) && !ial_for_element(el) ? '{::}' : '')
|
349
|
+
end
|
350
|
+
|
351
|
+
def convert_entity(el, _opts)
|
352
|
+
entity_to_str(el.value, el.options[:original])
|
353
|
+
end
|
354
|
+
|
355
|
+
TYPOGRAPHIC_SYMS = {
|
356
|
+
mdash: '---', ndash: '--', hellip: '...',
|
357
|
+
laquo_space: '<< ', raquo_space: ' >>',
|
358
|
+
laquo: '<<', raquo: '>>'
|
359
|
+
}
|
360
|
+
def convert_typographic_sym(el, _opts)
|
361
|
+
TYPOGRAPHIC_SYMS[el.value]
|
362
|
+
end
|
363
|
+
|
364
|
+
def convert_smart_quote(el, _opts)
|
365
|
+
el.value.to_s =~ /[rl]dquo/ ? "\"" : "'"
|
366
|
+
end
|
367
|
+
|
368
|
+
def convert_math(el, _opts)
|
369
|
+
"$$#{el.value}$$" + (el.options[:category] == :block ? "\n" : '')
|
370
|
+
end
|
371
|
+
|
372
|
+
def convert_abbreviation(el, _opts)
|
373
|
+
el.value
|
374
|
+
end
|
375
|
+
|
376
|
+
def convert_root(el, opts)
|
377
|
+
res = inner(el, opts)
|
378
|
+
res << create_link_defs
|
379
|
+
res << create_footnote_defs
|
380
|
+
res << create_abbrev_defs
|
381
|
+
res
|
382
|
+
end
|
383
|
+
|
384
|
+
def create_link_defs
|
385
|
+
res = +''
|
386
|
+
res << "\n\n" unless @linkrefs.empty?
|
387
|
+
@linkrefs.each_with_index do |el, i|
|
388
|
+
title = parse_title(el.attr['title'])
|
389
|
+
res << "[#{i + 1}]: #{el.attr['href']}#{title}\n"
|
390
|
+
end
|
391
|
+
res
|
392
|
+
end
|
393
|
+
|
394
|
+
def create_footnote_defs
|
395
|
+
res = +''
|
396
|
+
@footnotes.each do |name, data|
|
397
|
+
res << "[^#{name}]:\n"
|
398
|
+
res << inner(data).chomp.split(/\n/).map {|l| " #{l}" }.join("\n") + "\n\n"
|
399
|
+
end
|
400
|
+
res
|
401
|
+
end
|
402
|
+
|
403
|
+
def create_abbrev_defs
|
404
|
+
return '' unless @root.options[:abbrev_defs]
|
405
|
+
res = +''
|
406
|
+
@root.options[:abbrev_defs].each do |name, text|
|
407
|
+
res << "*[#{name}]: #{text}\n"
|
408
|
+
res << ial_for_element(Element.new(:unused, nil, @root.options[:abbrev_attr][name])).to_s << "\n\n"
|
409
|
+
end
|
410
|
+
res
|
411
|
+
end
|
412
|
+
|
413
|
+
# Return the IAL containing the attributes of the element +el+.
|
414
|
+
def ial_for_element(el)
|
415
|
+
res = el.attr.map do |k, v|
|
416
|
+
next if [:img, :a].include?(el.type) && ['href', 'src', 'alt', 'title'].include?(k)
|
417
|
+
next if el.type == :header && k == 'id' && !v.strip.empty?
|
418
|
+
if v.nil?
|
419
|
+
''
|
420
|
+
elsif k == 'class' && !v.empty? && !v.index(/[\.#]/)
|
421
|
+
" " + v.split(/\s+/).map {|w| ".#{w}" }.join(" ")
|
422
|
+
elsif k == 'id' && !v.strip.empty?
|
423
|
+
" ##{v}"
|
424
|
+
else
|
425
|
+
" #{k}=\"#{v}\""
|
426
|
+
end
|
427
|
+
end.compact.join('')
|
428
|
+
res = "toc" + (res.strip.empty? ? '' : " #{res}") if (el.type == :ul || el.type == :ol) &&
|
429
|
+
el.options.dig(:ial, :refs)&.include?('toc')
|
430
|
+
res = "footnotes" + (res.strip.empty? ? '' : " #{res}") if (el.type == :ul || el.type == :ol) &&
|
431
|
+
el.options.dig(:ial, :refs)&.include?('footnotes')
|
432
|
+
if el.type == :dl && el.options[:ial] && el.options[:ial][:refs]
|
433
|
+
auto_ids = el.options[:ial][:refs].select {|ref| ref.start_with?('auto_ids') }.join(" ")
|
434
|
+
res = auto_ids << (res.strip.empty? ? '' : " #{res}") unless auto_ids.empty?
|
435
|
+
end
|
436
|
+
res.strip.empty? ? nil : "{:#{res}}"
|
437
|
+
end
|
438
|
+
|
439
|
+
def parse_title(attr)
|
440
|
+
attr.to_s.empty? ? '' : ' "' + attr.gsub(/"/, '"') + '"'
|
441
|
+
end
|
442
|
+
|
443
|
+
# :startdoc:
|
444
|
+
|
445
|
+
end
|
446
|
+
|
447
|
+
end
|
448
|
+
end
|
@@ -0,0 +1,625 @@
|
|
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 'set'
|
11
|
+
require 'kramdown/converter'
|
12
|
+
|
13
|
+
module Kramdown
|
14
|
+
|
15
|
+
module Converter
|
16
|
+
|
17
|
+
# Converts an element tree to LaTeX.
|
18
|
+
#
|
19
|
+
# This converter uses ideas from other Markdown-to-LaTeX converters like Pandoc and Maruku.
|
20
|
+
#
|
21
|
+
# You can customize this converter by sub-classing it and overriding the +convert_NAME+ methods.
|
22
|
+
# Each such method takes the following parameters:
|
23
|
+
#
|
24
|
+
# [+el+] The element of type +NAME+ to be converted.
|
25
|
+
#
|
26
|
+
# [+opts+] A hash containing processing options that are passed down from parent elements. The
|
27
|
+
# key :parent is always set and contains the parent element as value.
|
28
|
+
#
|
29
|
+
# The return value of such a method has to be a string containing the element +el+ formatted
|
30
|
+
# correctly as LaTeX markup.
|
31
|
+
class Latex < Base
|
32
|
+
|
33
|
+
# Initialize the LaTeX converter with the +root+ element and the conversion +options+.
|
34
|
+
def initialize(root, options)
|
35
|
+
super
|
36
|
+
@data[:packages] = Set.new
|
37
|
+
end
|
38
|
+
|
39
|
+
# Dispatch the conversion of the element +el+ to a +convert_TYPE+ method using the +type+ of
|
40
|
+
# the element.
|
41
|
+
def convert(el, opts = {})
|
42
|
+
send("convert_#{el.type}", el, opts)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Return the converted content of the children of +el+ as a string.
|
46
|
+
def inner(el, opts)
|
47
|
+
result = +''
|
48
|
+
options = opts.dup.merge(parent: el)
|
49
|
+
el.children.each_with_index do |inner_el, index|
|
50
|
+
options[:index] = index
|
51
|
+
options[:result] = result
|
52
|
+
result << send("convert_#{inner_el.type}", inner_el, options)
|
53
|
+
end
|
54
|
+
result
|
55
|
+
end
|
56
|
+
|
57
|
+
def convert_root(el, opts)
|
58
|
+
inner(el, opts)
|
59
|
+
end
|
60
|
+
|
61
|
+
def convert_blank(_el, opts)
|
62
|
+
opts[:result] =~ /\n\n\Z|\A\Z/ ? "" : "\n"
|
63
|
+
end
|
64
|
+
|
65
|
+
def convert_text(el, _opts)
|
66
|
+
escape(el.value)
|
67
|
+
end
|
68
|
+
|
69
|
+
def convert_p(el, opts)
|
70
|
+
if el.children.size == 1 && el.children.first.type == :img &&
|
71
|
+
!(img = convert_img(el.children.first, opts)).empty?
|
72
|
+
convert_standalone_image(el, opts, img)
|
73
|
+
else
|
74
|
+
"#{latex_link_target(el)}#{inner(el, opts)}\n\n"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# Helper method used by +convert_p+ to convert a paragraph that only contains a single :img
|
79
|
+
# element.
|
80
|
+
def convert_standalone_image(el, _opts, img)
|
81
|
+
attrs = attribute_list(el)
|
82
|
+
"\\begin{figure}#{attrs}\n\\begin{center}\n#{img}\n\\end{center}\n" \
|
83
|
+
"\\caption{#{escape(el.children.first.attr['alt'])}}\n" \
|
84
|
+
"#{latex_link_target(el, true)}\n\\end{figure}#{attrs}\n"
|
85
|
+
end
|
86
|
+
|
87
|
+
def convert_codeblock(el, _opts)
|
88
|
+
show_whitespace = el.attr['class'].to_s =~ /\bshow-whitespaces\b/
|
89
|
+
lang = extract_code_language(el.attr)
|
90
|
+
|
91
|
+
if @options[:syntax_highlighter] == :minted &&
|
92
|
+
(highlighted_code = highlight_code(el.value, lang, :block))
|
93
|
+
@data[:packages] << 'minted'
|
94
|
+
"#{latex_link_target(el)}#{highlighted_code}\n"
|
95
|
+
elsif show_whitespace || lang
|
96
|
+
options = []
|
97
|
+
options << (show_whitespace ? "showspaces=true,showtabs=true" : "showspaces=false,showtabs=false")
|
98
|
+
options << "language=#{lang}" if lang
|
99
|
+
options << "basicstyle=\\ttfamily\\footnotesize,columns=fixed,frame=tlbr"
|
100
|
+
id = el.attr['id']
|
101
|
+
options << "label=#{id}" if id
|
102
|
+
attrs = attribute_list(el)
|
103
|
+
"#{latex_link_target(el)}\\begin{lstlisting}[#{options.join(',')}]\n" \
|
104
|
+
"#{el.value}\n\\end{lstlisting}#{attrs}\n"
|
105
|
+
else
|
106
|
+
"#{latex_link_target(el)}\\begin{verbatim}#{el.value}\\end{verbatim}\n"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def convert_blockquote(el, opts)
|
111
|
+
latex_environment(el.children.size > 1 ? 'quotation' : 'quote', el, inner(el, opts))
|
112
|
+
end
|
113
|
+
|
114
|
+
def convert_header(el, opts)
|
115
|
+
type = @options[:latex_headers][output_header_level(el.options[:level]) - 1]
|
116
|
+
if ((id = el.attr['id']) ||
|
117
|
+
(@options[:auto_ids] && (id = generate_id(el.options[:raw_text])))) && in_toc?(el)
|
118
|
+
"\\#{type}{#{inner(el, opts)}}\\hypertarget{#{id}}{}\\label{#{id}}\n\n"
|
119
|
+
else
|
120
|
+
"\\#{type}*{#{inner(el, opts)}}\n\n"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def convert_hr(el, _opts)
|
125
|
+
attrs = attribute_list(el)
|
126
|
+
"#{latex_link_target(el)}\\begin{center}#{attrs}\n\\rule{3in}{0.4pt}\n\\end{center}#{attrs}\n"
|
127
|
+
end
|
128
|
+
|
129
|
+
def convert_ul(el, opts)
|
130
|
+
if !@data[:has_toc] && el.options.dig(:ial, :refs)&.include?('toc')
|
131
|
+
@data[:has_toc] = true
|
132
|
+
'\tableofcontents'
|
133
|
+
else
|
134
|
+
latex_environment(el.type == :ul ? 'itemize' : 'enumerate', el, inner(el, opts))
|
135
|
+
end
|
136
|
+
end
|
137
|
+
alias convert_ol convert_ul
|
138
|
+
|
139
|
+
def convert_dl(el, opts)
|
140
|
+
latex_environment('description', el, inner(el, opts))
|
141
|
+
end
|
142
|
+
|
143
|
+
def convert_li(el, opts)
|
144
|
+
"\\item{} #{latex_link_target(el, true)}#{inner(el, opts).sub(/\n+\Z/, '')}\n"
|
145
|
+
end
|
146
|
+
|
147
|
+
def convert_dt(el, opts)
|
148
|
+
"\\item[#{inner(el, opts)}] "
|
149
|
+
end
|
150
|
+
|
151
|
+
def convert_dd(el, opts)
|
152
|
+
"#{latex_link_target(el)}#{inner(el, opts)}\n\n"
|
153
|
+
end
|
154
|
+
|
155
|
+
def convert_html_element(el, opts)
|
156
|
+
if el.value == 'i' || el.value == 'em'
|
157
|
+
"\\emph{#{inner(el, opts)}}"
|
158
|
+
elsif el.value == 'b' || el.value == 'strong'
|
159
|
+
"\\textbf{#{inner(el, opts)}}"
|
160
|
+
else
|
161
|
+
warning("Can't convert HTML element")
|
162
|
+
''
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def convert_xml_comment(el, _opts)
|
167
|
+
el.value.split(/\n/).map {|l| "% #{l}" }.join("\n") + "\n"
|
168
|
+
end
|
169
|
+
|
170
|
+
def convert_xml_pi(_el, _opts)
|
171
|
+
warning("Can't convert XML PI")
|
172
|
+
''
|
173
|
+
end
|
174
|
+
|
175
|
+
TABLE_ALIGNMENT_CHAR = {default: 'l', left: 'l', center: 'c', right: 'r'} # :nodoc:
|
176
|
+
|
177
|
+
def convert_table(el, opts)
|
178
|
+
@data[:packages] << 'longtable'
|
179
|
+
align = el.options[:alignment].map {|a| TABLE_ALIGNMENT_CHAR[a] }.join('|')
|
180
|
+
attrs = attribute_list(el)
|
181
|
+
"#{latex_link_target(el)}\\begin{longtable}{|#{align}|}#{attrs}\n" \
|
182
|
+
"\\hline\n#{inner(el, opts)}\\hline\n\\end{longtable}#{attrs}\n\n"
|
183
|
+
end
|
184
|
+
|
185
|
+
def convert_thead(el, opts)
|
186
|
+
"#{inner(el, opts)}\\hline\n"
|
187
|
+
end
|
188
|
+
|
189
|
+
def convert_tbody(el, opts)
|
190
|
+
inner(el, opts)
|
191
|
+
end
|
192
|
+
|
193
|
+
def convert_tfoot(el, opts)
|
194
|
+
"\\hline \\hline \n#{inner(el, opts)}"
|
195
|
+
end
|
196
|
+
|
197
|
+
def convert_tr(el, opts)
|
198
|
+
el.children.map {|c| send("convert_#{c.type}", c, opts) }.join(' & ') << "\\\\\n"
|
199
|
+
end
|
200
|
+
|
201
|
+
def convert_td(el, opts)
|
202
|
+
inner(el, opts)
|
203
|
+
end
|
204
|
+
|
205
|
+
def convert_comment(el, _opts)
|
206
|
+
el.value.split(/\n/).map {|l| "% #{l}" }.join("\n") << "\n"
|
207
|
+
end
|
208
|
+
|
209
|
+
def convert_br(_el, opts)
|
210
|
+
res = +"\\newline"
|
211
|
+
res << "\n" if (c = opts[:parent].children[opts[:index] + 1]) &&
|
212
|
+
(c.type != :text || c.value !~ /^\s*\n/)
|
213
|
+
res
|
214
|
+
end
|
215
|
+
|
216
|
+
def convert_a(el, opts)
|
217
|
+
url = el.attr['href']
|
218
|
+
if url.start_with?('#')
|
219
|
+
"\\hyperlink{#{url[1..-1].gsub('%', '\\%')}}{#{inner(el, opts)}}"
|
220
|
+
else
|
221
|
+
"\\href{#{url.gsub('%', '\\%')}}{#{inner(el, opts)}}"
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
def convert_img(el, _opts)
|
226
|
+
line = el.options[:location]
|
227
|
+
if el.attr['src'] =~ /^(https?|ftps?):\/\//
|
228
|
+
warning("Cannot include non-local image#{line ? " (line #{line})" : ''}")
|
229
|
+
''
|
230
|
+
elsif !el.attr['src'].empty?
|
231
|
+
@data[:packages] << 'graphicx'
|
232
|
+
"#{latex_link_target(el)}\\includegraphics{#{el.attr['src']}}"
|
233
|
+
else
|
234
|
+
warning("Cannot include image with empty path#{line ? " (line #{line})" : ''}")
|
235
|
+
''
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
def convert_codespan(el, _opts)
|
240
|
+
lang = extract_code_language(el.attr)
|
241
|
+
if @options[:syntax_highlighter] == :minted &&
|
242
|
+
(highlighted_code = highlight_code(el.value, lang, :span))
|
243
|
+
@data[:packages] << 'minted'
|
244
|
+
"#{latex_link_target(el)}#{highlighted_code}"
|
245
|
+
else
|
246
|
+
"\\texttt{#{latex_link_target(el)}#{escape(el.value)}}"
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
def convert_footnote(el, opts)
|
251
|
+
@data[:packages] << 'fancyvrb'
|
252
|
+
"\\footnote{#{inner(el.value, opts).rstrip}}"
|
253
|
+
end
|
254
|
+
|
255
|
+
def convert_raw(el, _opts)
|
256
|
+
if !el.options[:type] || el.options[:type].empty? || el.options[:type].include?('latex')
|
257
|
+
el.value + (el.options[:category] == :block ? "\n" : '')
|
258
|
+
else
|
259
|
+
''
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
def convert_em(el, opts)
|
264
|
+
"\\emph{#{latex_link_target(el)}#{inner(el, opts)}}"
|
265
|
+
end
|
266
|
+
|
267
|
+
def convert_strong(el, opts)
|
268
|
+
"\\textbf{#{latex_link_target(el)}#{inner(el, opts)}}"
|
269
|
+
end
|
270
|
+
|
271
|
+
# Inspired by Maruku: entity conversion table based on the one from htmltolatex
|
272
|
+
# (http://sourceforge.net/projects/htmltolatex/), with some small adjustments/additions
|
273
|
+
ENTITY_CONV_TABLE = {
|
274
|
+
913 => ['$A$'],
|
275
|
+
914 => ['$B$'],
|
276
|
+
915 => ['$\Gamma$'],
|
277
|
+
916 => ['$\Delta$'],
|
278
|
+
917 => ['$E$'],
|
279
|
+
918 => ['$Z$'],
|
280
|
+
919 => ['$H$'],
|
281
|
+
920 => ['$\Theta$'],
|
282
|
+
921 => ['$I$'],
|
283
|
+
922 => ['$K$'],
|
284
|
+
923 => ['$\Lambda$'],
|
285
|
+
924 => ['$M$'],
|
286
|
+
925 => ['$N$'],
|
287
|
+
926 => ['$\Xi$'],
|
288
|
+
927 => ['$O$'],
|
289
|
+
928 => ['$\Pi$'],
|
290
|
+
929 => ['$P$'],
|
291
|
+
931 => ['$\Sigma$'],
|
292
|
+
932 => ['$T$'],
|
293
|
+
933 => ['$Y$'],
|
294
|
+
934 => ['$\Phi$'],
|
295
|
+
935 => ['$X$'],
|
296
|
+
936 => ['$\Psi$'],
|
297
|
+
937 => ['$\Omega$'],
|
298
|
+
945 => ['$\alpha$'],
|
299
|
+
946 => ['$\beta$'],
|
300
|
+
947 => ['$\gamma$'],
|
301
|
+
948 => ['$\delta$'],
|
302
|
+
949 => ['$\epsilon$'],
|
303
|
+
950 => ['$\zeta$'],
|
304
|
+
951 => ['$\eta$'],
|
305
|
+
952 => ['$\theta$'],
|
306
|
+
953 => ['$\iota$'],
|
307
|
+
954 => ['$\kappa$'],
|
308
|
+
955 => ['$\lambda$'],
|
309
|
+
956 => ['$\mu$'],
|
310
|
+
957 => ['$\nu$'],
|
311
|
+
958 => ['$\xi$'],
|
312
|
+
959 => ['$o$'],
|
313
|
+
960 => ['$\pi$'],
|
314
|
+
961 => ['$\rho$'],
|
315
|
+
963 => ['$\sigma$'],
|
316
|
+
964 => ['$\tau$'],
|
317
|
+
965 => ['$\upsilon$'],
|
318
|
+
966 => ['$\phi$'],
|
319
|
+
967 => ['$\chi$'],
|
320
|
+
968 => ['$\psi$'],
|
321
|
+
969 => ['$\omega$'],
|
322
|
+
962 => ['$\varsigma$'],
|
323
|
+
977 => ['$\vartheta$'],
|
324
|
+
982 => ['$\varpi$'],
|
325
|
+
8230 => ['\ldots'],
|
326
|
+
8242 => ['$\prime$'],
|
327
|
+
8254 => ['-'],
|
328
|
+
8260 => ['/'],
|
329
|
+
8472 => ['$\wp$'],
|
330
|
+
8465 => ['$\Im$'],
|
331
|
+
8476 => ['$\Re$'],
|
332
|
+
8501 => ['$\aleph$'],
|
333
|
+
8226 => ['$\bullet$'],
|
334
|
+
8482 => ['$^{\rm TM}$'],
|
335
|
+
8592 => ['$\leftarrow$'],
|
336
|
+
8594 => ['$\rightarrow$'],
|
337
|
+
8593 => ['$\uparrow$'],
|
338
|
+
8595 => ['$\downarrow$'],
|
339
|
+
8596 => ['$\leftrightarrow$'],
|
340
|
+
8629 => ['$\hookleftarrow$'],
|
341
|
+
8657 => ['$\Uparrow$'],
|
342
|
+
8659 => ['$\Downarrow$'],
|
343
|
+
8656 => ['$\Leftarrow$'],
|
344
|
+
8658 => ['$\Rightarrow$'],
|
345
|
+
8660 => ['$\Leftrightarrow$'],
|
346
|
+
8704 => ['$\forall$'],
|
347
|
+
8706 => ['$\partial$'],
|
348
|
+
8707 => ['$\exists$'],
|
349
|
+
8709 => ['$\emptyset$'],
|
350
|
+
8711 => ['$\nabla$'],
|
351
|
+
8712 => ['$\in$'],
|
352
|
+
8715 => ['$\ni$'],
|
353
|
+
8713 => ['$\notin$'],
|
354
|
+
8721 => ['$\sum$'],
|
355
|
+
8719 => ['$\prod$'],
|
356
|
+
8722 => ['$-$'],
|
357
|
+
8727 => ['$\ast$'],
|
358
|
+
8730 => ['$\surd$'],
|
359
|
+
8733 => ['$\propto$'],
|
360
|
+
8734 => ['$\infty$'],
|
361
|
+
8736 => ['$\angle$'],
|
362
|
+
8743 => ['$\wedge$'],
|
363
|
+
8744 => ['$\vee$'],
|
364
|
+
8745 => ['$\cap$'],
|
365
|
+
8746 => ['$\cup$'],
|
366
|
+
8747 => ['$\int$'],
|
367
|
+
8756 => ['$\therefore$', 'amssymb'],
|
368
|
+
8764 => ['$\sim$'],
|
369
|
+
8776 => ['$\approx$'],
|
370
|
+
8773 => ['$\cong$'],
|
371
|
+
8800 => ['$\neq$'],
|
372
|
+
8801 => ['$\equiv$'],
|
373
|
+
8804 => ['$\leq$'],
|
374
|
+
8805 => ['$\geq$'],
|
375
|
+
8834 => ['$\subset$'],
|
376
|
+
8835 => ['$\supset$'],
|
377
|
+
8838 => ['$\subseteq$'],
|
378
|
+
8839 => ['$\supseteq$'],
|
379
|
+
8836 => ['$\nsubset$', 'amssymb'],
|
380
|
+
8853 => ['$\oplus$'],
|
381
|
+
8855 => ['$\otimes$'],
|
382
|
+
8869 => ['$\perp$'],
|
383
|
+
8901 => ['$\cdot$'],
|
384
|
+
8968 => ['$\rceil$'],
|
385
|
+
8969 => ['$\lceil$'],
|
386
|
+
8970 => ['$\lfloor$'],
|
387
|
+
8971 => ['$\rfloor$'],
|
388
|
+
9001 => ['$\rangle$'],
|
389
|
+
9002 => ['$\langle$'],
|
390
|
+
9674 => ['$\lozenge$', 'amssymb'],
|
391
|
+
9824 => ['$\spadesuit$'],
|
392
|
+
9827 => ['$\clubsuit$'],
|
393
|
+
9829 => ['$\heartsuit$'],
|
394
|
+
9830 => ['$\diamondsuit$'],
|
395
|
+
38 => ['\&'],
|
396
|
+
34 => ['"'],
|
397
|
+
39 => ['\''],
|
398
|
+
169 => ['\copyright'],
|
399
|
+
60 => ['\textless'],
|
400
|
+
62 => ['\textgreater'],
|
401
|
+
338 => ['\OE'],
|
402
|
+
339 => ['\oe'],
|
403
|
+
352 => ['\v{S}'],
|
404
|
+
353 => ['\v{s}'],
|
405
|
+
376 => ['\"Y'],
|
406
|
+
710 => ['\textasciicircum'],
|
407
|
+
732 => ['\textasciitilde'],
|
408
|
+
8211 => ['--'],
|
409
|
+
8212 => ['---'],
|
410
|
+
8216 => ['`'],
|
411
|
+
8217 => ['\''],
|
412
|
+
8220 => ['``'],
|
413
|
+
8221 => ['\'\''],
|
414
|
+
8224 => ['\dag'],
|
415
|
+
8225 => ['\ddag'],
|
416
|
+
8240 => ['\permil', 'wasysym'],
|
417
|
+
8364 => ['\euro', 'eurosym'],
|
418
|
+
8249 => ['\guilsinglleft'],
|
419
|
+
8250 => ['\guilsinglright'],
|
420
|
+
8218 => ['\quotesinglbase', 'mathcomp'],
|
421
|
+
8222 => ['\quotedblbase', 'mathcomp'],
|
422
|
+
402 => ['\textflorin', 'mathcomp'],
|
423
|
+
381 => ['\v{Z}'],
|
424
|
+
382 => ['\v{z}'],
|
425
|
+
160 => ['~'],
|
426
|
+
161 => ['\textexclamdown'],
|
427
|
+
163 => ['\pounds'],
|
428
|
+
164 => ['\currency', 'wasysym'],
|
429
|
+
165 => ['\textyen', 'textcomp'],
|
430
|
+
166 => ['\brokenvert', 'wasysym'],
|
431
|
+
167 => ['\S'],
|
432
|
+
171 => ['\guillemotleft'],
|
433
|
+
187 => ['\guillemotright'],
|
434
|
+
174 => ['\textregistered'],
|
435
|
+
170 => ['\textordfeminine'],
|
436
|
+
172 => ['$\neg$'],
|
437
|
+
173 => ['\-'],
|
438
|
+
176 => ['$\degree$', 'mathabx'],
|
439
|
+
177 => ['$\pm$'],
|
440
|
+
180 => ['\''],
|
441
|
+
181 => ['$\mu$'],
|
442
|
+
182 => ['\P'],
|
443
|
+
183 => ['$\cdot$'],
|
444
|
+
186 => ['\textordmasculine'],
|
445
|
+
162 => ['\cent', 'wasysym'],
|
446
|
+
185 => ['$^1$'],
|
447
|
+
178 => ['$^2$'],
|
448
|
+
179 => ['$^3$'],
|
449
|
+
189 => ['$\frac{1}{2}$'],
|
450
|
+
188 => ['$\frac{1}{4}$'],
|
451
|
+
190 => ['$\frac{3}{4}'],
|
452
|
+
192 => ['\`A'],
|
453
|
+
193 => ['\\\'A'],
|
454
|
+
194 => ['\^A'],
|
455
|
+
195 => ['\~A'],
|
456
|
+
196 => ['\"A'],
|
457
|
+
197 => ['\AA'],
|
458
|
+
198 => ['\AE'],
|
459
|
+
199 => ['\cC'],
|
460
|
+
200 => ['\`E'],
|
461
|
+
201 => ['\\\'E'],
|
462
|
+
202 => ['\^E'],
|
463
|
+
203 => ['\"E'],
|
464
|
+
204 => ['\`I'],
|
465
|
+
205 => ['\\\'I'],
|
466
|
+
206 => ['\^I'],
|
467
|
+
207 => ['\"I'],
|
468
|
+
208 => ['$\eth$', 'amssymb'],
|
469
|
+
209 => ['\~N'],
|
470
|
+
210 => ['\`O'],
|
471
|
+
211 => ['\\\'O'],
|
472
|
+
212 => ['\^O'],
|
473
|
+
213 => ['\~O'],
|
474
|
+
214 => ['\"O'],
|
475
|
+
215 => ['$\times$'],
|
476
|
+
216 => ['\O'],
|
477
|
+
217 => ['\`U'],
|
478
|
+
218 => ['\\\'U'],
|
479
|
+
219 => ['\^U'],
|
480
|
+
220 => ['\"U'],
|
481
|
+
221 => ['\\\'Y'],
|
482
|
+
222 => ['\Thorn', 'wasysym'],
|
483
|
+
223 => ['\ss'],
|
484
|
+
224 => ['\`a'],
|
485
|
+
225 => ['\\\'a'],
|
486
|
+
226 => ['\^a'],
|
487
|
+
227 => ['\~a'],
|
488
|
+
228 => ['\"a'],
|
489
|
+
229 => ['\aa'],
|
490
|
+
230 => ['\ae'],
|
491
|
+
231 => ['\cc'],
|
492
|
+
232 => ['\`e'],
|
493
|
+
233 => ['\\\'e'],
|
494
|
+
234 => ['\^e'],
|
495
|
+
235 => ['\"e'],
|
496
|
+
236 => ['\`i'],
|
497
|
+
237 => ['\\\'i'],
|
498
|
+
238 => ['\^i'],
|
499
|
+
239 => ['\"i'],
|
500
|
+
240 => ['$\eth$'],
|
501
|
+
241 => ['\~n'],
|
502
|
+
242 => ['\`o'],
|
503
|
+
243 => ['\\\'o'],
|
504
|
+
244 => ['\^o'],
|
505
|
+
245 => ['\~o'],
|
506
|
+
246 => ['\"o'],
|
507
|
+
247 => ['$\divide$'],
|
508
|
+
248 => ['\o'],
|
509
|
+
249 => ['\`u'],
|
510
|
+
250 => ['\\\'u'],
|
511
|
+
251 => ['\^u'],
|
512
|
+
252 => ['\"u'],
|
513
|
+
253 => ['\\\'y'],
|
514
|
+
254 => ['\thorn', 'wasysym'],
|
515
|
+
255 => ['\"y'],
|
516
|
+
8201 => ['\thinspace'],
|
517
|
+
8194 => ['\hskip .5em\relax'],
|
518
|
+
8195 => ['\quad'],
|
519
|
+
} # :nodoc:
|
520
|
+
ENTITY_CONV_TABLE.each_value {|v| v[0] = "{}#{v[0]}" }
|
521
|
+
|
522
|
+
def entity_to_latex(entity)
|
523
|
+
text, package = ENTITY_CONV_TABLE[entity.code_point]
|
524
|
+
if text
|
525
|
+
@data[:packages] << package if package
|
526
|
+
text
|
527
|
+
else
|
528
|
+
warning("Couldn't find entity with code #{entity.code_point} in substitution table!")
|
529
|
+
''
|
530
|
+
end
|
531
|
+
end
|
532
|
+
|
533
|
+
def convert_entity(el, _opts)
|
534
|
+
entity_to_latex(el.value)
|
535
|
+
end
|
536
|
+
|
537
|
+
TYPOGRAPHIC_SYMS = {
|
538
|
+
mdash: '---', ndash: '--', hellip: '\ldots{}',
|
539
|
+
laquo_space: '\guillemotleft{}~', raquo_space: '~\guillemotright{}',
|
540
|
+
laquo: '\guillemotleft{}', raquo: '\guillemotright{}'
|
541
|
+
} # :nodoc:
|
542
|
+
def convert_typographic_sym(el, _opts)
|
543
|
+
if (result = @options[:typographic_symbols][el.value])
|
544
|
+
escape(result)
|
545
|
+
else
|
546
|
+
TYPOGRAPHIC_SYMS[el.value]
|
547
|
+
end
|
548
|
+
end
|
549
|
+
|
550
|
+
def convert_smart_quote(el, opts)
|
551
|
+
res = entity_to_latex(smart_quote_entity(el)).chomp('{}')
|
552
|
+
res << "{}" if ((nel = opts[:parent].children[opts[:index] + 1]) && nel.type == :smart_quote) || res =~ /\w$/
|
553
|
+
res
|
554
|
+
end
|
555
|
+
|
556
|
+
def convert_math(el, _opts)
|
557
|
+
@data[:packages] += %w[amssymb amsmath amsthm amsfonts]
|
558
|
+
if el.options[:category] == :block
|
559
|
+
if el.value =~ /\A\s*\\begin\{/
|
560
|
+
el.value
|
561
|
+
else
|
562
|
+
latex_environment('displaymath', el, el.value)
|
563
|
+
end
|
564
|
+
else
|
565
|
+
"$#{el.value}$"
|
566
|
+
end
|
567
|
+
end
|
568
|
+
|
569
|
+
def convert_abbreviation(el, _opts)
|
570
|
+
@data[:packages] += %w[acronym]
|
571
|
+
"\\ac{#{normalize_abbreviation_key(el.value)}}"
|
572
|
+
end
|
573
|
+
|
574
|
+
# Normalize the abbreviation key so that it only contains allowed ASCII character
|
575
|
+
def normalize_abbreviation_key(key)
|
576
|
+
key.gsub(/\W/) {|m| m.unpack('H*').first }
|
577
|
+
end
|
578
|
+
|
579
|
+
# Wrap the +text+ inside a LaTeX environment of type +type+. The element +el+ is passed on to
|
580
|
+
# the method #attribute_list -- the resulting string is appended to both the \\begin and the
|
581
|
+
# \\end lines of the LaTeX environment for easier post-processing of LaTeX environments.
|
582
|
+
def latex_environment(type, el, text)
|
583
|
+
attrs = attribute_list(el)
|
584
|
+
"\\begin{#{type}}#{latex_link_target(el)}#{attrs}\n#{text.rstrip}\n\\end{#{type}}#{attrs}\n"
|
585
|
+
end
|
586
|
+
|
587
|
+
# Return a string containing a valid \hypertarget command if the element has an ID defined, or
|
588
|
+
# +nil+ otherwise. If the parameter +add_label+ is +true+, a \label command will also be used
|
589
|
+
# additionally to the \hypertarget command.
|
590
|
+
def latex_link_target(el, add_label = false)
|
591
|
+
if (id = el.attr['id'])
|
592
|
+
"\\hypertarget{#{id}}{}#{add_label ? "\\label{#{id}}" : ''}"
|
593
|
+
else
|
594
|
+
nil
|
595
|
+
end
|
596
|
+
end
|
597
|
+
|
598
|
+
# Return a LaTeX comment containing all attributes as 'key="value"' pairs.
|
599
|
+
def attribute_list(el)
|
600
|
+
attrs = el.attr.map {|k, v| v.nil? ? '' : " #{k}=\"#{v}\"" }.compact.sort.join('')
|
601
|
+
attrs = " % #{attrs}" unless attrs.empty?
|
602
|
+
attrs
|
603
|
+
end
|
604
|
+
|
605
|
+
ESCAPE_MAP = {
|
606
|
+
"^" => "\\^{}",
|
607
|
+
"\\" => "\\textbackslash{}",
|
608
|
+
"~" => "\\ensuremath{\\sim}",
|
609
|
+
"|" => "\\textbar{}",
|
610
|
+
"<" => "\\textless{}",
|
611
|
+
">" => "\\textgreater{}",
|
612
|
+
"[" => "{[}",
|
613
|
+
"]" => "{]}",
|
614
|
+
}.merge(Hash[*("{}$%&_#".each_char.map {|c| [c, "\\#{c}"] }.flatten)]) # :nodoc:
|
615
|
+
ESCAPE_RE = Regexp.union(*ESCAPE_MAP.collect {|k, _v| k }) # :nodoc:
|
616
|
+
|
617
|
+
# Escape the special LaTeX characters in the string +str+.
|
618
|
+
def escape(str)
|
619
|
+
str.gsub(ESCAPE_RE) {|m| ESCAPE_MAP[m] }
|
620
|
+
end
|
621
|
+
|
622
|
+
end
|
623
|
+
|
624
|
+
end
|
625
|
+
end
|