kramdown 0.14.2 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of kramdown might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/CONTRIBUTERS +63 -1
- data/COPYING +17 -11
- data/README.md +35 -14
- data/VERSION +1 -1
- data/bin/kramdown +92 -40
- data/data/kramdown/document.html +4 -0
- data/data/kramdown/document.latex +7 -0
- data/lib/kramdown.rb +3 -16
- data/lib/kramdown/converter.rb +42 -16
- data/lib/kramdown/converter/base.rb +102 -38
- data/lib/kramdown/converter/hash_ast.rb +38 -0
- data/lib/kramdown/converter/html.rb +232 -141
- data/lib/kramdown/converter/kramdown.rb +122 -104
- data/lib/kramdown/converter/latex.rb +95 -78
- 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 +8 -17
- 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 +7 -20
- data/lib/kramdown/document.rb +30 -37
- data/lib/kramdown/element.rb +54 -27
- data/lib/kramdown/error.rb +3 -16
- data/lib/kramdown/options.rb +392 -247
- data/lib/kramdown/parser.rb +3 -16
- data/lib/kramdown/parser/base.rb +28 -33
- data/lib/kramdown/parser/html.rb +151 -119
- data/lib/kramdown/parser/kramdown.rb +87 -50
- data/lib/kramdown/parser/kramdown/abbreviation.rb +33 -27
- data/lib/kramdown/parser/kramdown/autolink.rb +7 -25
- data/lib/kramdown/parser/kramdown/blank_line.rb +6 -19
- data/lib/kramdown/parser/kramdown/block_boundary.rb +6 -18
- data/lib/kramdown/parser/kramdown/blockquote.rb +6 -19
- data/lib/kramdown/parser/kramdown/codeblock.rb +15 -24
- data/lib/kramdown/parser/kramdown/codespan.rb +20 -22
- data/lib/kramdown/parser/kramdown/emphasis.rb +15 -24
- data/lib/kramdown/parser/kramdown/eob.rb +3 -16
- data/lib/kramdown/parser/kramdown/escaped_chars.rb +3 -16
- data/lib/kramdown/parser/kramdown/extensions.rb +66 -56
- data/lib/kramdown/parser/kramdown/footnote.rb +21 -31
- data/lib/kramdown/parser/kramdown/header.rb +37 -37
- data/lib/kramdown/parser/kramdown/horizontal_rule.rb +5 -17
- data/lib/kramdown/parser/kramdown/html.rb +47 -56
- data/lib/kramdown/parser/kramdown/html_entity.rb +9 -19
- data/lib/kramdown/parser/kramdown/line_break.rb +4 -17
- data/lib/kramdown/parser/kramdown/link.rb +39 -38
- data/lib/kramdown/parser/kramdown/list.rb +124 -82
- data/lib/kramdown/parser/kramdown/math.rb +12 -24
- data/lib/kramdown/parser/kramdown/paragraph.rb +23 -24
- data/lib/kramdown/parser/kramdown/smart_quotes.rb +26 -66
- data/lib/kramdown/parser/kramdown/table.rb +41 -48
- data/lib/kramdown/parser/kramdown/typographic_symbol.rb +14 -22
- data/lib/kramdown/parser/markdown.rb +11 -23
- data/lib/kramdown/utils.rb +21 -18
- data/lib/kramdown/utils/configurable.rb +45 -0
- data/lib/kramdown/utils/entities.rb +287 -292
- data/lib/kramdown/utils/html.rb +27 -30
- 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 +4 -17
- data/man/man1/kramdown.1 +340 -347
- data/test/run_tests.rb +7 -20
- data/test/test_files.rb +188 -100
- data/test/test_location.rb +216 -0
- data/test/test_string_scanner_kramdown.rb +27 -0
- data/test/testcases/block/03_paragraph/indented.html.gfm +18 -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/standalone_image.html +8 -0
- data/test/testcases/block/03_paragraph/standalone_image.text +6 -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 +15 -1
- data/test/testcases/block/04_header/atx_header.text +14 -1
- data/test/testcases/block/04_header/setext_header.html +3 -1
- data/test/testcases/block/04_header/setext_header.text +4 -1
- 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 +2 -0
- data/test/testcases/block/04_header/with_auto_ids.options +1 -0
- data/test/testcases/block/04_header/with_auto_ids.text +2 -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 -6
- 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/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/with_lang_in_fenced_block.options +1 -1
- 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 +2 -2
- data/test/testcases/block/07_horizontal_rule/normal.html +2 -0
- data/test/testcases/block/07_horizontal_rule/normal.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/lazy_and_nested.html +9 -0
- data/test/testcases/block/08_list/lazy_and_nested.text +4 -0
- data/test/testcases/block/09_html/html5_attributes.html +2 -0
- data/test/testcases/block/09_html/html5_attributes.text +2 -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_to_native/table_simple.html +13 -0
- data/test/testcases/block/09_html/html_to_native/table_simple.text +15 -0
- data/test/testcases/block/09_html/html_to_native/typography.html +1 -1
- data/test/testcases/block/09_html/not_parsed.html +1 -1
- data/test/testcases/block/09_html/processing_instruction.html +5 -6
- data/test/testcases/block/09_html/simple.html +1 -5
- data/test/testcases/block/09_html/simple.text +1 -5
- 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/11_ial/simple.html +5 -1
- data/test/testcases/block/11_ial/simple.text +8 -1
- data/test/testcases/block/12_extension/options.html +4 -4
- data/test/testcases/block/12_extension/options.text +2 -0
- data/test/testcases/block/12_extension/options2.html +4 -4
- data/test/testcases/block/12_extension/options3.html +7 -6
- data/test/testcases/block/12_extension/options3.text +2 -2
- 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/item_ial.html +5 -0
- data/test/testcases/block/13_definition_list/item_ial.text +8 -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 +4 -0
- data/test/testcases/block/14_table/errors.text +4 -0
- data/test/testcases/block/14_table/header.html +21 -0
- data/test/testcases/block/14_table/header.text +7 -0
- data/test/testcases/block/14_table/simple.html +22 -7
- data/test/testcases/block/14_table/simple.text +4 -0
- data/test/testcases/block/14_table/table_with_footnote.html +4 -4
- 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 +17 -14
- data/test/testcases/block/15_math/normal.text +2 -0
- data/test/testcases/block/16_toc/toc_exclude.html +7 -7
- data/test/testcases/block/16_toc/toc_levels.html +5 -5
- data/test/testcases/block/16_toc/toc_levels.text +1 -1
- data/test/testcases/block/16_toc/toc_with_footnotes.html +5 -5
- 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/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 +1 -1
- 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/imagelinks.html +1 -0
- data/test/testcases/span/01_link/imagelinks.text +2 -0
- data/test/testcases/span/01_link/inline.html +1 -1
- 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 +1 -1
- data/test/testcases/span/01_link/link_defs.text +2 -1
- 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/reference.html +3 -3
- data/test/testcases/span/02_emphasis/nesting.html +3 -0
- data/test/testcases/span/02_emphasis/nesting.text +4 -1
- data/test/testcases/span/02_emphasis/normal.html +19 -0
- data/test/testcases/span/02_emphasis/normal.options +1 -0
- data/test/testcases/span/02_emphasis/normal.text +17 -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 -1
- 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/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.latex +2 -2
- data/test/testcases/span/04_footnote/footnote_nr.html +6 -6
- 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 +16 -16
- data/test/testcases/span/04_footnote/markers.latex +3 -3
- data/test/testcases/span/04_footnote/markers.options +2 -0
- data/test/testcases/span/04_footnote/markers.text +2 -1
- 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/button.html +7 -0
- data/test/testcases/span/05_html/button.text +7 -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/normal.html +10 -1
- data/test/testcases/span/05_html/normal.text +9 -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 +14 -1
- data/test/testcases/span/abbreviations/abbrev.text +18 -2
- 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 +5 -4
- data/test/testcases/span/autolinks/url_links.text +1 -0
- data/test/testcases/span/line_breaks/normal.html +2 -2
- data/test/testcases/span/line_breaks/normal.latex +2 -2
- 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 +4 -3
- data/test/testcases/span/math/normal.text +2 -1
- data/test/testcases/span/text_substitutions/entities_as_char.html +1 -1
- data/test/testcases/span/text_substitutions/entities_as_char.options +1 -0
- data/test/testcases/span/text_substitutions/entities_as_char.text +1 -1
- data/test/testcases/span/text_substitutions/typography.html +22 -0
- data/test/testcases/span/text_substitutions/typography.text +22 -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 +218 -67
- data/ChangeLog +0 -7436
- data/GPL +0 -674
- data/Rakefile +0 -306
- data/benchmark/benchmark.rb +0 -36
- data/benchmark/benchmark.sh +0 -74
- data/benchmark/generate_data.rb +0 -119
- data/benchmark/mdbasics.text +0 -306
- data/benchmark/mdsyntax.text +0 -888
- data/benchmark/testing.sh +0 -9
- data/benchmark/timing.sh +0 -10
- data/doc/bg.png +0 -0
- data/doc/default.scss.css +0 -181
- data/doc/default.template +0 -68
- data/doc/design.scss.css +0 -441
- data/doc/documentation.page +0 -84
- data/doc/documentation.template +0 -20
- data/doc/index.page +0 -94
- data/doc/installation.page +0 -88
- data/doc/links.markdown +0 -6
- data/doc/metainfo +0 -3
- data/doc/news.feed +0 -10
- data/doc/news.page +0 -29
- data/doc/options.page +0 -10
- data/doc/quickref.page +0 -598
- data/doc/sidebar.template +0 -21
- data/doc/syntax.page +0 -1700
- data/doc/tests.page +0 -91
- data/doc/virtual +0 -2
- data/lib/kramdown/compatibility.rb +0 -49
- data/lib/kramdown/utils/ordered_hash.rb +0 -100
- data/setup.rb +0 -1585
- data/test/testcases/block/07_horizontal_rule/error.html.19 +0 -7
- data/test/testcases/block/09_html/html_to_native/typography.html.19 +0 -1
- data/test/testcases/block/09_html/simple.html.19 +0 -64
- data/test/testcases/block/14_table/simple.html.19 +0 -177
- data/test/testcases/span/01_link/inline.html.19 +0 -46
- data/test/testcases/span/01_link/reference.html.19 +0 -37
- data/test/testcases/span/text_substitutions/entities_as_char.html.19 +0 -1
@@ -1,22 +1,9 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
1
|
+
# -*- coding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
4
|
-
# Copyright (C) 2009-
|
4
|
+
# Copyright (C) 2009-2019 Thomas Leitner <t_leitner@gmx.at>
|
5
5
|
#
|
6
|
-
# This file is part of kramdown.
|
7
|
-
#
|
8
|
-
# kramdown is free software: you can redistribute it and/or modify
|
9
|
-
# it under the terms of the GNU General Public License as published by
|
10
|
-
# the Free Software Foundation, either version 3 of the License, or
|
11
|
-
# (at your option) any later version.
|
12
|
-
#
|
13
|
-
# This program is distributed in the hope that it will be useful,
|
14
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
-
# GNU General Public License for more details.
|
17
|
-
#
|
18
|
-
# You should have received a copy of the GNU General Public License
|
19
|
-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
6
|
+
# This file is part of kramdown which is licensed under the MIT.
|
20
7
|
#++
|
21
8
|
#
|
22
9
|
|
@@ -32,38 +19,41 @@ module Kramdown
|
|
32
19
|
|
33
20
|
# Parse the foot note definition at the current location.
|
34
21
|
def parse_footnote_definition
|
22
|
+
start_line_number = @src.current_line_number
|
35
23
|
@src.pos += @src.matched_size
|
36
24
|
|
37
|
-
el = Element.new(:footnote_def)
|
25
|
+
el = Element.new(:footnote_def, nil, nil, location: start_line_number)
|
38
26
|
parse_blocks(el, @src[2].gsub(INDENT, ''))
|
39
|
-
|
27
|
+
if @footnotes[@src[1]]
|
28
|
+
warning("Duplicate footnote name '#{@src[1]}' on line #{start_line_number} - overwriting")
|
29
|
+
end
|
30
|
+
@tree.children << new_block_el(:eob, :footnote_def)
|
40
31
|
(@footnotes[@src[1]] = {})[:content] = el
|
41
|
-
@tree.children
|
32
|
+
@footnotes[@src[1]][:eob] = @tree.children.last
|
42
33
|
true
|
43
34
|
end
|
44
35
|
define_parser(:footnote_definition, FOOTNOTE_DEFINITION_START)
|
45
36
|
|
46
|
-
|
47
37
|
FOOTNOTE_MARKER_START = /\[\^(#{ALD_ID_NAME})\]/
|
48
38
|
|
49
39
|
# Parse the footnote marker at the current location.
|
50
40
|
def parse_footnote_marker
|
41
|
+
start_line_number = @src.current_line_number
|
51
42
|
@src.pos += @src.matched_size
|
52
43
|
fn_def = @footnotes[@src[1]]
|
53
44
|
if fn_def
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
fn_def
|
59
|
-
fn_def[:stack] = [@stack.map {|s| s.first}, @tree, fn_def[:marker]].flatten.compact
|
60
|
-
@tree.children << fn_def[:marker]
|
61
|
-
else
|
62
|
-
warning("Footnote marker '#{@src[1]}' already appeared in document, ignoring newly found marker")
|
63
|
-
add_text(@src.matched)
|
45
|
+
if fn_def[:eob]
|
46
|
+
update_attr_with_ial(fn_def[:eob].attr, fn_def[:eob].options[:ial] || {})
|
47
|
+
fn_def[:attr] = fn_def[:eob].attr
|
48
|
+
fn_def[:options] = fn_def[:eob].options
|
49
|
+
fn_def.delete(:eob)
|
64
50
|
end
|
51
|
+
fn_def[:marker] ||= []
|
52
|
+
fn_def[:marker].push(Element.new(:footnote, fn_def[:content], fn_def[:attr],
|
53
|
+
fn_def[:options].merge(name: @src[1], location: start_line_number)))
|
54
|
+
@tree.children << fn_def[:marker].last
|
65
55
|
else
|
66
|
-
warning("Footnote definition for '#{@src[1]}' not found")
|
56
|
+
warning("Footnote definition for '#{@src[1]}' not found on line #{start_line_number}")
|
67
57
|
add_text(@src.matched)
|
68
58
|
end
|
69
59
|
end
|
@@ -1,69 +1,69 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
1
|
+
# -*- coding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
4
|
-
# Copyright (C) 2009-
|
4
|
+
# Copyright (C) 2009-2019 Thomas Leitner <t_leitner@gmx.at>
|
5
5
|
#
|
6
|
-
# This file is part of kramdown.
|
7
|
-
#
|
8
|
-
# kramdown is free software: you can redistribute it and/or modify
|
9
|
-
# it under the terms of the GNU General Public License as published by
|
10
|
-
# the Free Software Foundation, either version 3 of the License, or
|
11
|
-
# (at your option) any later version.
|
12
|
-
#
|
13
|
-
# This program is distributed in the hope that it will be useful,
|
14
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
-
# GNU General Public License for more details.
|
17
|
-
#
|
18
|
-
# You should have received a copy of the GNU General Public License
|
19
|
-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
6
|
+
# This file is part of kramdown which is licensed under the MIT.
|
20
7
|
#++
|
21
8
|
#
|
22
9
|
|
23
10
|
require 'kramdown/parser/kramdown/block_boundary'
|
11
|
+
require 'rexml/xmltokens'
|
24
12
|
|
25
13
|
module Kramdown
|
26
14
|
module Parser
|
27
15
|
class Kramdown
|
28
16
|
|
29
|
-
|
30
|
-
SETEXT_HEADER_START = /^(#{OPT_SPACE}[^ \t].*?)#{HEADER_ID}[ \t]*?\n(-|=)+\s*?\n/
|
17
|
+
SETEXT_HEADER_START = /^#{OPT_SPACE}(?<contents>[^ \t].*)\n(?<level>[-=])[-=]*[ \t\r\f\v]*\n/
|
31
18
|
|
32
19
|
# Parse the Setext header at the current location.
|
33
20
|
def parse_setext_header
|
34
|
-
return false
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
text.strip!
|
39
|
-
el = new_block_el(:header, nil, nil, :level => (level == '-' ? 2 : 1), :raw_text => text)
|
40
|
-
add_text(text, el)
|
41
|
-
el.attr['id'] = id if id
|
42
|
-
@tree.children << el
|
21
|
+
return false unless after_block_boundary?
|
22
|
+
text, id = parse_header_contents
|
23
|
+
return false if text.empty?
|
24
|
+
add_header(@src["level"] == '-' ? 2 : 1, text, id)
|
43
25
|
true
|
44
26
|
end
|
45
27
|
define_parser(:setext_header, SETEXT_HEADER_START)
|
46
28
|
|
47
|
-
|
48
|
-
ATX_HEADER_START = /^\#{1,6}/
|
49
|
-
ATX_HEADER_MATCH = /^(\#{1,6})(.+?)\s*?#*#{HEADER_ID}\s*?\n/
|
29
|
+
ATX_HEADER_START = /^(?<level>\#{1,6})[\t ]*(?<contents>[^ \t].*)\n/
|
50
30
|
|
51
31
|
# Parse the Atx header at the current location.
|
52
32
|
def parse_atx_header
|
53
|
-
return false
|
54
|
-
|
55
|
-
|
56
|
-
level, text, id = @src[1], @src[2].to_s.strip, @src[3]
|
33
|
+
return false unless after_block_boundary?
|
34
|
+
text, id = parse_header_contents
|
35
|
+
text.sub!(/(?<!\\)#+\z/, '') && text.rstrip!
|
57
36
|
return false if text.empty?
|
37
|
+
add_header(@src["level"].length, text, id)
|
38
|
+
true
|
39
|
+
end
|
40
|
+
define_parser(:atx_header, ATX_HEADER_START)
|
41
|
+
|
42
|
+
protected
|
58
43
|
|
44
|
+
HEADER_ID = /[\t ]{#(?<id>#{REXML::XMLTokens::NAME_START_CHAR}#{REXML::XMLTokens::NAME_CHAR}*)}\z/
|
45
|
+
|
46
|
+
# Returns header text and optional ID.
|
47
|
+
def parse_header_contents
|
48
|
+
text = @src["contents"]
|
49
|
+
text.rstrip!
|
50
|
+
id_match = HEADER_ID.match(text)
|
51
|
+
if id_match
|
52
|
+
id = id_match["id"]
|
53
|
+
text = text[0...-id_match[0].length]
|
54
|
+
text.rstrip!
|
55
|
+
end
|
56
|
+
[text, id]
|
57
|
+
end
|
58
|
+
|
59
|
+
def add_header(level, text, id)
|
60
|
+
start_line_number = @src.current_line_number
|
59
61
|
@src.pos += @src.matched_size
|
60
|
-
el = new_block_el(:header, nil, nil, :level
|
62
|
+
el = new_block_el(:header, nil, nil, level: level, raw_text: text, location: start_line_number)
|
61
63
|
add_text(text, el)
|
62
64
|
el.attr['id'] = id if id
|
63
65
|
@tree.children << el
|
64
|
-
true
|
65
66
|
end
|
66
|
-
define_parser(:atx_header, ATX_HEADER_START)
|
67
67
|
|
68
68
|
end
|
69
69
|
end
|
@@ -1,22 +1,9 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
1
|
+
# -*- coding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
4
|
-
# Copyright (C) 2009-
|
4
|
+
# Copyright (C) 2009-2019 Thomas Leitner <t_leitner@gmx.at>
|
5
5
|
#
|
6
|
-
# This file is part of kramdown.
|
7
|
-
#
|
8
|
-
# kramdown is free software: you can redistribute it and/or modify
|
9
|
-
# it under the terms of the GNU General Public License as published by
|
10
|
-
# the Free Software Foundation, either version 3 of the License, or
|
11
|
-
# (at your option) any later version.
|
12
|
-
#
|
13
|
-
# This program is distributed in the hope that it will be useful,
|
14
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
-
# GNU General Public License for more details.
|
17
|
-
#
|
18
|
-
# You should have received a copy of the GNU General Public License
|
19
|
-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
6
|
+
# This file is part of kramdown which is licensed under the MIT.
|
20
7
|
#++
|
21
8
|
#
|
22
9
|
|
@@ -28,8 +15,9 @@ module Kramdown
|
|
28
15
|
|
29
16
|
# Parse the horizontal rule at the current location.
|
30
17
|
def parse_horizontal_rule
|
18
|
+
start_line_number = @src.current_line_number
|
31
19
|
@src.pos += @src.matched_size
|
32
|
-
@tree.children << new_block_el(:hr)
|
20
|
+
@tree.children << new_block_el(:hr, nil, nil, location: start_line_number)
|
33
21
|
true
|
34
22
|
end
|
35
23
|
define_parser(:horizontal_rule, HR_START)
|
@@ -1,22 +1,9 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
1
|
+
# -*- coding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
4
|
-
# Copyright (C) 2009-
|
4
|
+
# Copyright (C) 2009-2019 Thomas Leitner <t_leitner@gmx.at>
|
5
5
|
#
|
6
|
-
# This file is part of kramdown.
|
7
|
-
#
|
8
|
-
# kramdown is free software: you can redistribute it and/or modify
|
9
|
-
# it under the terms of the GNU General Public License as published by
|
10
|
-
# the Free Software Foundation, either version 3 of the License, or
|
11
|
-
# (at your option) any later version.
|
12
|
-
#
|
13
|
-
# This program is distributed in the hope that it will be useful,
|
14
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
-
# GNU General Public License for more details.
|
17
|
-
#
|
18
|
-
# You should have received a copy of the GNU General Public License
|
19
|
-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
6
|
+
# This file is part of kramdown which is licensed under the MIT.
|
20
7
|
#++
|
21
8
|
#
|
22
9
|
|
@@ -36,14 +23,17 @@ module Kramdown
|
|
36
23
|
TRAILING_WHITESPACE = /[ \t]*\n/
|
37
24
|
|
38
25
|
def handle_kramdown_html_tag(el, closed, handle_body)
|
39
|
-
|
26
|
+
if @block_ial
|
27
|
+
el.options[:ial] = @block_ial
|
28
|
+
@block_ial = nil
|
29
|
+
end
|
40
30
|
|
41
31
|
content_model = if @tree.type != :html_element || @tree.options[:content_model] != :raw
|
42
32
|
(@options[:parse_block_html] ? HTML_CONTENT_MODEL[el.value] : :raw)
|
43
33
|
else
|
44
34
|
:raw
|
45
35
|
end
|
46
|
-
if val = HTML_MARKDOWN_ATTR_MAP[el.attr.delete('markdown')]
|
36
|
+
if (val = HTML_MARKDOWN_ATTR_MAP[el.attr.delete('markdown')])
|
47
37
|
content_model = (val == :default ? HTML_CONTENT_MODEL[el.value] : val)
|
48
38
|
end
|
49
39
|
|
@@ -53,8 +43,8 @@ module Kramdown
|
|
53
43
|
|
54
44
|
if !closed && handle_body
|
55
45
|
if content_model == :block
|
56
|
-
|
57
|
-
warning("Found no end tag for '#{el.value}' - auto-closing it")
|
46
|
+
unless parse_blocks(el)
|
47
|
+
warning("Found no end tag for '#{el.value}' (line #{el.options[:location]}) - auto-closing it")
|
58
48
|
end
|
59
49
|
elsif content_model == :span
|
60
50
|
curpos = @src.pos
|
@@ -64,35 +54,33 @@ module Kramdown
|
|
64
54
|
else
|
65
55
|
add_text(@src.rest, el)
|
66
56
|
@src.terminate
|
67
|
-
warning("Found no end tag for '#{el.value}' - auto-closing it")
|
57
|
+
warning("Found no end tag for '#{el.value}' (line #{el.options[:location]}) - auto-closing it")
|
68
58
|
end
|
69
59
|
else
|
70
60
|
parse_raw_html(el, &method(:handle_kramdown_html_tag))
|
71
61
|
end
|
72
|
-
|
62
|
+
unless @tree.type == :html_element && @tree.options[:content_model] == :raw
|
63
|
+
@src.scan(TRAILING_WHITESPACE)
|
64
|
+
end
|
73
65
|
end
|
74
66
|
end
|
75
67
|
|
76
|
-
|
77
|
-
HTML_BLOCK_START = /^#{OPT_SPACE}<(#{REXML::Parsers::BaseParser::UNAME_STR}|\?|!--|\/)/
|
68
|
+
HTML_BLOCK_START = /^#{OPT_SPACE}<(#{REXML::Parsers::BaseParser::UNAME_STR}|!--|\/)/
|
78
69
|
|
79
70
|
# Parse the HTML at the current position as block-level HTML.
|
80
71
|
def parse_block_html
|
81
|
-
|
82
|
-
|
83
|
-
@
|
84
|
-
true
|
85
|
-
elsif result = @src.scan(HTML_INSTRUCTION_RE)
|
86
|
-
@tree.children << Element.new(:xml_pi, result, nil, :category => :block)
|
72
|
+
line = @src.current_line_number
|
73
|
+
if (result = @src.scan(HTML_COMMENT_RE))
|
74
|
+
@tree.children << Element.new(:xml_comment, result, nil, category: :block, location: line)
|
87
75
|
@src.scan(TRAILING_WHITESPACE)
|
88
76
|
true
|
89
77
|
else
|
90
|
-
if
|
78
|
+
if @src.check(/^#{OPT_SPACE}#{HTML_TAG_RE}/o) && !HTML_SPAN_ELEMENTS.include?(@src[1].downcase)
|
91
79
|
@src.pos += @src.matched_size
|
92
|
-
handle_html_start_tag(&method(:handle_kramdown_html_tag))
|
80
|
+
handle_html_start_tag(line, &method(:handle_kramdown_html_tag))
|
93
81
|
Kramdown::Parser::Html::ElementConverter.convert(@root, @tree.children.last) if @options[:html_to_native]
|
94
82
|
true
|
95
|
-
elsif
|
83
|
+
elsif @src.check(/^#{OPT_SPACE}#{HTML_TAG_CLOSE_RE}/o) && !HTML_SPAN_ELEMENTS.include?(@src[1].downcase)
|
96
84
|
name = @src[1].downcase
|
97
85
|
|
98
86
|
if @tree.type == :html_element && @tree.value == name
|
@@ -108,33 +96,37 @@ module Kramdown
|
|
108
96
|
end
|
109
97
|
define_parser(:block_html, HTML_BLOCK_START)
|
110
98
|
|
111
|
-
|
112
|
-
HTML_SPAN_START = /<(#{REXML::Parsers::BaseParser::UNAME_STR}|\?|!--|\/)/
|
99
|
+
HTML_SPAN_START = /<(#{REXML::Parsers::BaseParser::UNAME_STR}|!--|\/)/
|
113
100
|
|
114
101
|
# Parse the HTML at the current position as span-level HTML.
|
115
102
|
def parse_span_html
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
warning("Found invalidly used HTML closing tag for '#{@src[1]}'")
|
103
|
+
line = @src.current_line_number
|
104
|
+
if (result = @src.scan(HTML_COMMENT_RE))
|
105
|
+
@tree.children << Element.new(:xml_comment, result, nil, category: :span, location: line)
|
106
|
+
elsif (result = @src.scan(HTML_TAG_CLOSE_RE))
|
107
|
+
warning("Found invalidly used HTML closing tag for '#{@src[1]}' on line #{line}")
|
122
108
|
add_text(result)
|
123
|
-
elsif result = @src.scan(HTML_TAG_RE)
|
124
|
-
tag_name = @src[1]
|
109
|
+
elsif (result = @src.scan(HTML_TAG_RE))
|
110
|
+
tag_name = @src[1]
|
111
|
+
tag_name.downcase! if HTML_ELEMENT[tag_name.downcase]
|
125
112
|
if HTML_BLOCK_ELEMENTS.include?(tag_name)
|
126
|
-
warning("Found block HTML tag '#{tag_name}' in span-level text")
|
113
|
+
warning("Found block HTML tag '#{tag_name}' in span-level text on line #{line}")
|
127
114
|
add_text(result)
|
128
115
|
return
|
129
116
|
end
|
130
117
|
|
131
|
-
attrs =
|
132
|
-
|
118
|
+
attrs = parse_html_attributes(@src[2], line, HTML_ELEMENT[tag_name])
|
119
|
+
attrs.each_value {|value| value.gsub!(/\n+/, ' ') unless value.empty? }
|
133
120
|
|
134
|
-
do_parsing =
|
135
|
-
|
121
|
+
do_parsing = if HTML_CONTENT_MODEL[tag_name] == :raw || @tree.options[:content_model] == :raw
|
122
|
+
false
|
123
|
+
else
|
124
|
+
@options[:parse_span_html]
|
125
|
+
end
|
126
|
+
if (val = HTML_MARKDOWN_ATTR_MAP[attrs.delete('markdown')])
|
136
127
|
if val == :block
|
137
|
-
warning("Cannot use block-level parsing in span-level HTML tag
|
128
|
+
warning("Cannot use block-level parsing in span-level HTML tag (line #{line}) " \
|
129
|
+
"- using default mode")
|
138
130
|
elsif val == :span
|
139
131
|
do_parsing = true
|
140
132
|
elsif val == :default
|
@@ -144,17 +136,16 @@ module Kramdown
|
|
144
136
|
end
|
145
137
|
end
|
146
138
|
|
147
|
-
el = Element.new(:html_element, tag_name, attrs, :
|
148
|
-
:
|
139
|
+
el = Element.new(:html_element, tag_name, attrs, category: :span, location: line,
|
140
|
+
content_model: (do_parsing ? :span : :raw), is_closed: !!@src[4])
|
149
141
|
@tree.children << el
|
150
|
-
stop_re = /<\/#{Regexp.escape(tag_name)}\s*>/
|
151
|
-
|
152
|
-
|
153
|
-
elsif !@src[4]
|
142
|
+
stop_re = /<\/#{Regexp.escape(tag_name)}\s*>/
|
143
|
+
stop_re = Regexp.new(stop_re.source, Regexp::IGNORECASE) if HTML_ELEMENT[tag_name]
|
144
|
+
if !@src[4] && !HTML_ELEMENTS_WITHOUT_BODY.include?(el.value)
|
154
145
|
if parse_spans(el, stop_re, (do_parsing ? nil : [:span_html]))
|
155
146
|
@src.scan(stop_re)
|
156
147
|
else
|
157
|
-
warning("Found no end tag for '#{el.value}' - auto-closing it")
|
148
|
+
warning("Found no end tag for '#{el.value}' (line #{line}) - auto-closing it")
|
158
149
|
add_text(@src.rest, el)
|
159
150
|
@src.terminate
|
160
151
|
end
|
@@ -1,22 +1,9 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
1
|
+
# -*- coding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
4
|
-
# Copyright (C) 2009-
|
4
|
+
# Copyright (C) 2009-2019 Thomas Leitner <t_leitner@gmx.at>
|
5
5
|
#
|
6
|
-
# This file is part of kramdown.
|
7
|
-
#
|
8
|
-
# kramdown is free software: you can redistribute it and/or modify
|
9
|
-
# it under the terms of the GNU General Public License as published by
|
10
|
-
# the Free Software Foundation, either version 3 of the License, or
|
11
|
-
# (at your option) any later version.
|
12
|
-
#
|
13
|
-
# This program is distributed in the hope that it will be useful,
|
14
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
-
# GNU General Public License for more details.
|
17
|
-
#
|
18
|
-
# You should have received a copy of the GNU General Public License
|
19
|
-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
6
|
+
# This file is part of kramdown which is licensed under the MIT.
|
20
7
|
#++
|
21
8
|
#
|
22
9
|
|
@@ -28,12 +15,15 @@ module Kramdown
|
|
28
15
|
|
29
16
|
# Parse the HTML entity at the current location.
|
30
17
|
def parse_html_entity
|
18
|
+
start_line_number = @src.current_line_number
|
31
19
|
@src.pos += @src.matched_size
|
32
20
|
begin
|
33
|
-
|
34
|
-
|
21
|
+
value = ::Kramdown::Utils::Entities.entity(@src[1] || (@src[2]&.to_i) || @src[3].hex)
|
22
|
+
@tree.children << Element.new(:entity, value,
|
23
|
+
nil, original: @src.matched, location: start_line_number)
|
35
24
|
rescue ::Kramdown::Error
|
36
|
-
@tree.children << Element.new(:entity, ::Kramdown::Utils::Entities.entity('amp')
|
25
|
+
@tree.children << Element.new(:entity, ::Kramdown::Utils::Entities.entity('amp'),
|
26
|
+
nil, location: start_line_number)
|
37
27
|
add_text(@src.matched[1..-1])
|
38
28
|
end
|
39
29
|
end
|