kramdown 2.5.1 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CONTRIBUTERS +15 -14
- data/README.md +18 -16
- data/VERSION +1 -1
- data/lib/kramdown/converter/base.rb +1 -1
- data/lib/kramdown/converter/hash_ast.rb +1 -1
- data/lib/kramdown/converter/html.rb +10 -3
- data/lib/kramdown/converter/kramdown.rb +1 -1
- data/lib/kramdown/converter/latex.rb +1 -1
- data/lib/kramdown/converter/man.rb +1 -1
- data/lib/kramdown/converter/math_engine/mathjax.rb +1 -1
- data/lib/kramdown/converter/remove_html_tags.rb +1 -1
- data/lib/kramdown/converter/syntax_highlighter/minted.rb +1 -1
- data/lib/kramdown/converter/syntax_highlighter/rouge.rb +32 -3
- data/lib/kramdown/converter/syntax_highlighter.rb +1 -1
- data/lib/kramdown/converter/toc.rb +1 -1
- data/lib/kramdown/converter.rb +1 -1
- data/lib/kramdown/document.rb +1 -1
- data/lib/kramdown/element.rb +1 -1
- data/lib/kramdown/error.rb +1 -1
- data/lib/kramdown/options.rb +22 -3
- data/lib/kramdown/parser/base.rb +2 -2
- data/lib/kramdown/parser/html.rb +13 -6
- data/lib/kramdown/parser/kramdown/abbreviation.rb +2 -2
- data/lib/kramdown/parser/kramdown/autolink.rb +1 -1
- data/lib/kramdown/parser/kramdown/blank_line.rb +1 -1
- data/lib/kramdown/parser/kramdown/block_boundary.rb +2 -2
- data/lib/kramdown/parser/kramdown/blockquote.rb +1 -1
- data/lib/kramdown/parser/kramdown/codeblock.rb +2 -2
- data/lib/kramdown/parser/kramdown/codespan.rb +1 -1
- data/lib/kramdown/parser/kramdown/emphasis.rb +4 -3
- data/lib/kramdown/parser/kramdown/eob.rb +1 -1
- data/lib/kramdown/parser/kramdown/escaped_chars.rb +1 -1
- data/lib/kramdown/parser/kramdown/extensions.rb +9 -7
- data/lib/kramdown/parser/kramdown/footnote.rb +1 -1
- data/lib/kramdown/parser/kramdown/header.rb +1 -1
- data/lib/kramdown/parser/kramdown/horizontal_rule.rb +1 -1
- data/lib/kramdown/parser/kramdown/html.rb +8 -6
- data/lib/kramdown/parser/kramdown/html_entity.rb +1 -1
- data/lib/kramdown/parser/kramdown/line_break.rb +1 -1
- data/lib/kramdown/parser/kramdown/link.rb +37 -5
- data/lib/kramdown/parser/kramdown/list.rb +6 -4
- data/lib/kramdown/parser/kramdown/math.rb +1 -1
- data/lib/kramdown/parser/kramdown/paragraph.rb +1 -1
- data/lib/kramdown/parser/kramdown/smart_quotes.rb +1 -1
- data/lib/kramdown/parser/kramdown/table.rb +2 -2
- data/lib/kramdown/parser/kramdown/typographic_symbol.rb +1 -1
- data/lib/kramdown/parser/kramdown.rb +11 -4
- data/lib/kramdown/parser/markdown.rb +1 -1
- data/lib/kramdown/parser.rb +1 -1
- data/lib/kramdown/utils/configurable.rb +1 -1
- data/lib/kramdown/utils/entities.rb +1 -1
- data/lib/kramdown/utils/html.rb +1 -1
- data/lib/kramdown/utils/lru_cache.rb +1 -1
- data/lib/kramdown/utils/string_scanner.rb +8 -9
- data/lib/kramdown/utils/unidecoder.rb +1 -1
- data/lib/kramdown/utils.rb +1 -1
- data/lib/kramdown/version.rb +2 -2
- data/lib/kramdown.rb +1 -1
- data/man/man1/kramdown.1 +6 -2
- data/test/run_tests.rb +1 -1
- data/test/test_files.rb +8 -2
- data/test/test_location.rb +1 -1
- data/test/test_string_scanner_kramdown.rb +1 -1
- data/test/testcases/block/04_header/with_custom_header_links.html +1 -0
- data/test/testcases/block/04_header/with_custom_header_links.options +4 -0
- data/test/testcases/block/04_header/with_custom_header_links.text +1 -0
- data/test/testcases/span/01_link/imagelinks.html +4 -0
- data/test/testcases/span/01_link/imagelinks.text +7 -0
- data/test/testcases/span/01_link/unclosed_brackets.html +5 -0
- data/test/testcases/span/01_link/unclosed_brackets.text +5 -0
- data/test/testcases/span/04_footnote/empty_definition.html +12 -0
- data/test/testcases/span/04_footnote/empty_definition.text +3 -0
- metadata +14 -7
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# -*- coding: utf-8; frozen_string_literal: true -*-
|
|
2
2
|
#
|
|
3
3
|
#--
|
|
4
|
-
# Copyright (C) 2009-
|
|
4
|
+
# Copyright (C) 2009-2026 Thomas Leitner <t_leitner@gmx.at>
|
|
5
5
|
#
|
|
6
6
|
# This file is part of kramdown which is licensed under the MIT.
|
|
7
7
|
#++
|
|
@@ -22,8 +22,9 @@ module Kramdown
|
|
|
22
22
|
element = (result.length == 2 ? :strong : :em)
|
|
23
23
|
type = result[0..0]
|
|
24
24
|
|
|
25
|
-
if (type == '_' && @src.pre_match
|
|
26
|
-
|
|
25
|
+
if (type == '_' && (tmp = @src.pre_match).match?(/[[:alnum:]]-?[[:alnum:]]*_*\z/, [tmp.size - 50, 0].max)) ||
|
|
26
|
+
@src.match?(/\s/) ||
|
|
27
|
+
@tree.type == element || @stack.any? {|el, _| el.type == element }
|
|
27
28
|
add_text(result)
|
|
28
29
|
return
|
|
29
30
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# -*- coding: utf-8; frozen_string_literal: true -*-
|
|
2
2
|
#
|
|
3
3
|
#--
|
|
4
|
-
# Copyright (C) 2009-
|
|
4
|
+
# Copyright (C) 2009-2026 Thomas Leitner <t_leitner@gmx.at>
|
|
5
5
|
#
|
|
6
6
|
# This file is part of kramdown which is licensed under the MIT.
|
|
7
7
|
#++
|
|
@@ -18,7 +18,7 @@ module Kramdown
|
|
|
18
18
|
def parse_attribute_list(str, opts)
|
|
19
19
|
return if str.strip.empty? || str.strip == ':'
|
|
20
20
|
attrs = str.scan(ALD_TYPE_ANY)
|
|
21
|
-
attrs.each do |key, sep, val, ref, id_and_or_class, _, _|
|
|
21
|
+
attrs.each do |key, sep, val, ref, id_and_or_class, _, _, unmatched|
|
|
22
22
|
if ref
|
|
23
23
|
(opts[:refs] ||= []) << ref
|
|
24
24
|
elsif id_and_or_class
|
|
@@ -29,6 +29,8 @@ module Kramdown
|
|
|
29
29
|
opts['id'] = id_attr
|
|
30
30
|
end
|
|
31
31
|
end
|
|
32
|
+
elsif unmatched
|
|
33
|
+
warning("IAL/ALD contains invalid part: #{unmatched}")
|
|
32
34
|
else
|
|
33
35
|
val.gsub!(/\\(\}|#{sep})/, "\\1")
|
|
34
36
|
opts[key] = val
|
|
@@ -146,7 +148,7 @@ module Kramdown
|
|
|
146
148
|
ALD_TYPE_ID_OR_CLASS = /#{ALD_TYPE_ID_NAME}|#{ALD_TYPE_CLASS_NAME}/
|
|
147
149
|
ALD_TYPE_ID_OR_CLASS_MULTI = /((?:#{ALD_TYPE_ID_NAME}|#{ALD_TYPE_CLASS_NAME})+)/
|
|
148
150
|
ALD_TYPE_REF = /(#{ALD_ID_NAME})/
|
|
149
|
-
ALD_TYPE_ANY = /(?:\A|\s)(?:#{ALD_TYPE_KEY_VALUE_PAIR}|#{ALD_TYPE_REF}|#{ALD_TYPE_ID_OR_CLASS_MULTI})(?=\s|\Z)/
|
|
151
|
+
ALD_TYPE_ANY = /(?:\A|\s)(?:#{ALD_TYPE_KEY_VALUE_PAIR}|#{ALD_TYPE_REF}|#{ALD_TYPE_ID_OR_CLASS_MULTI}|(\S+))(?=\s|\Z)/
|
|
150
152
|
ALD_START = /^#{OPT_SPACE}\{:(#{ALD_ID_NAME}):(#{ALD_ANY_CHARS}+)\}\s*?\n/
|
|
151
153
|
|
|
152
154
|
EXT_STOP_STR = "\\{:/(%s)?\\}"
|
|
@@ -166,14 +168,14 @@ module Kramdown
|
|
|
166
168
|
parse_attribute_list(@src[2], @alds[@src[1]] ||= {})
|
|
167
169
|
@tree.children << new_block_el(:eob, :ald)
|
|
168
170
|
true
|
|
169
|
-
elsif @src.
|
|
171
|
+
elsif @src.match?(EXT_BLOCK_START)
|
|
170
172
|
parse_extension_start_tag(:block)
|
|
171
173
|
elsif @src.scan(IAL_BLOCK_START)
|
|
172
174
|
if (last_child = @tree.children.last) && last_child.type != :blank &&
|
|
173
175
|
(last_child.type != :eob ||
|
|
174
176
|
[:link_def, :abbrev_def, :footnote_def].include?(last_child.value))
|
|
175
177
|
parse_attribute_list(@src[1], last_child.options[:ial] ||= {})
|
|
176
|
-
@tree.children << new_block_el(:eob, :ial) unless @src.
|
|
178
|
+
@tree.children << new_block_el(:eob, :ial) unless @src.match?(IAL_BLOCK_START)
|
|
177
179
|
else
|
|
178
180
|
parse_attribute_list(@src[1], @block_ial ||= {})
|
|
179
181
|
end
|
|
@@ -190,9 +192,9 @@ module Kramdown
|
|
|
190
192
|
|
|
191
193
|
# Parse the extension span at the current location.
|
|
192
194
|
def parse_span_extensions
|
|
193
|
-
if @src.
|
|
195
|
+
if @src.match?(EXT_SPAN_START)
|
|
194
196
|
parse_extension_start_tag(:span)
|
|
195
|
-
elsif @src.
|
|
197
|
+
elsif @src.match?(IAL_SPAN_START)
|
|
196
198
|
if (last_child = @tree.children.last) && last_child.type != :text
|
|
197
199
|
@src.pos += @src.matched_size
|
|
198
200
|
attr = {}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# -*- coding: utf-8; frozen_string_literal: true -*-
|
|
2
2
|
#
|
|
3
3
|
#--
|
|
4
|
-
# Copyright (C) 2009-
|
|
4
|
+
# Copyright (C) 2009-2026 Thomas Leitner <t_leitner@gmx.at>
|
|
5
5
|
#
|
|
6
6
|
# This file is part of kramdown which is licensed under the MIT.
|
|
7
7
|
#++
|
|
@@ -72,16 +72,17 @@ module Kramdown
|
|
|
72
72
|
# Parse the HTML at the current position as block-level HTML.
|
|
73
73
|
def parse_block_html
|
|
74
74
|
line = @src.current_line_number
|
|
75
|
-
if (
|
|
75
|
+
if @src.skip(/<!--/) && (r = @src.exist?(/-->/); @src.pos -= 4; r)
|
|
76
|
+
result = @src.scan(HTML_COMMENT_RE)
|
|
76
77
|
@tree.children << Element.new(:xml_comment, result, nil, category: :block, location: line)
|
|
77
78
|
@src.scan(TRAILING_WHITESPACE)
|
|
78
79
|
true
|
|
79
|
-
elsif @src.
|
|
80
|
+
elsif @src.match?(/^#{OPT_SPACE}#{HTML_TAG_RE}/o) && !HTML_SPAN_ELEMENTS.include?(@src[1].downcase)
|
|
80
81
|
@src.pos += @src.matched_size
|
|
81
82
|
handle_html_start_tag(line) {|iel, ic, ih| handle_kramdown_html_tag(iel, ic, ih) }
|
|
82
83
|
Kramdown::Parser::Html::ElementConverter.convert(@root, @tree.children.last) if @options[:html_to_native]
|
|
83
84
|
true
|
|
84
|
-
elsif @src.
|
|
85
|
+
elsif @src.match?(/^#{OPT_SPACE}#{HTML_TAG_CLOSE_RE}/o) && !HTML_SPAN_ELEMENTS.include?(@src[1].downcase)
|
|
85
86
|
name = @src[1].downcase
|
|
86
87
|
|
|
87
88
|
if @tree.type == :html_element && @tree.value == name
|
|
@@ -101,9 +102,10 @@ module Kramdown
|
|
|
101
102
|
# Parse the HTML at the current position as span-level HTML.
|
|
102
103
|
def parse_span_html
|
|
103
104
|
line = @src.current_line_number
|
|
104
|
-
if (
|
|
105
|
+
if @src.skip(/<!--/) && (r = @src.exist?(/-->/); @src.pos -= 4; r)
|
|
106
|
+
result = @src.scan(HTML_COMMENT_RE)
|
|
105
107
|
@tree.children << Element.new(:xml_comment, result, nil, category: :span, location: line)
|
|
106
|
-
elsif @src.
|
|
108
|
+
elsif @src.skip(/<!\[CDATA\[/) && (r = @src.exist?(/\]\]>/); @src.pos -= 9; r)
|
|
107
109
|
add_text(escape_html(@src[1]))
|
|
108
110
|
elsif (result = @src.scan(HTML_TAG_CLOSE_RE))
|
|
109
111
|
warning("Found invalidly used HTML closing tag for '#{@src[1]}' on line #{line}")
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# -*- coding: utf-8; frozen_string_literal: true -*-
|
|
2
2
|
#
|
|
3
3
|
#--
|
|
4
|
-
# Copyright (C) 2009-
|
|
4
|
+
# Copyright (C) 2009-2026 Thomas Leitner <t_leitner@gmx.at>
|
|
5
5
|
#
|
|
6
6
|
# This file is part of kramdown which is licensed under the MIT.
|
|
7
7
|
#++
|
|
@@ -43,7 +43,7 @@ module Kramdown
|
|
|
43
43
|
el.attr['href'] = href
|
|
44
44
|
else
|
|
45
45
|
el.attr['src'] = href
|
|
46
|
-
el.attr['alt']
|
|
46
|
+
el.attr['alt'] ||= alt_text
|
|
47
47
|
el.children.clear
|
|
48
48
|
end
|
|
49
49
|
el.attr['title'] = title if title
|
|
@@ -55,11 +55,13 @@ module Kramdown
|
|
|
55
55
|
LINK_INLINE_ID_RE = /\s*?\[([^\]]+)?\]/
|
|
56
56
|
LINK_INLINE_TITLE_RE = /\s*?(["'])(.+?)\1\s*?\)/m
|
|
57
57
|
LINK_START = /!?\[(?=[^^])/
|
|
58
|
+
LINK_EMPHASIS_CONTEXT = Hash.new(0).merge!(em: 1, strong: 2).freeze
|
|
58
59
|
|
|
59
60
|
# Parse the link at the current scanner position. This method is used to parse normal links as
|
|
60
61
|
# well as image links.
|
|
61
62
|
def parse_link
|
|
62
63
|
start_line_number = @src.current_line_number
|
|
64
|
+
start_pos = @src.pos
|
|
63
65
|
result = @src.scan(LINK_START)
|
|
64
66
|
cur_pos = @src.pos
|
|
65
67
|
saved_pos = @src.save_pos
|
|
@@ -72,15 +74,45 @@ module Kramdown
|
|
|
72
74
|
add_text(result)
|
|
73
75
|
return
|
|
74
76
|
end
|
|
77
|
+
|
|
78
|
+
# Failed bracket scans are cached per source position to avoid quadratic or even exponential
|
|
79
|
+
# runtime on unclosed brackets. Since the scan result depends on whether emphasis may be
|
|
80
|
+
# parsed, the emphasis context (stored in the two lowest bits) is part of the cache key.
|
|
81
|
+
unless @link_scan_failures_src.equal?(@src)
|
|
82
|
+
@link_scan_failures_src, @link_scan_failures = @src, {}
|
|
83
|
+
end
|
|
84
|
+
context = @stack.inject(LINK_EMPHASIS_CONTEXT[@tree.type]) do |memo, (t, _)|
|
|
85
|
+
memo | LINK_EMPHASIS_CONTEXT[t&.type]
|
|
86
|
+
end
|
|
87
|
+
start_key = (start_pos << 2) | context
|
|
88
|
+
if @link_scan_failures[start_key]
|
|
89
|
+
@src.terminate if @tree.type == :a || @tree.type == :img
|
|
90
|
+
add_text(result)
|
|
91
|
+
return
|
|
92
|
+
end
|
|
93
|
+
|
|
75
94
|
el = Element.new(link_type, nil, nil, location: start_line_number)
|
|
76
95
|
|
|
77
96
|
count = 1
|
|
97
|
+
brackets = []
|
|
78
98
|
found = parse_spans(el, LINK_BRACKET_STOP_RE) do
|
|
79
|
-
|
|
80
|
-
count
|
|
99
|
+
closing = @src[1]
|
|
100
|
+
count += (closing ? -1 : 1)
|
|
101
|
+
level = count - el.children.count {|c| c.type == :img }
|
|
102
|
+
brackets << [(closing || @src.matched_size == 2) ? nil : @src.pos, level]
|
|
103
|
+
level == 0
|
|
81
104
|
end
|
|
82
105
|
unless found
|
|
106
|
+
# An opening bracket found during the scan can only start a link if a later bracket has a
|
|
107
|
+
# level of one less than the opening bracket.
|
|
108
|
+
levels = {}
|
|
109
|
+
brackets.reverse_each do |pos, level|
|
|
110
|
+
@link_scan_failures[(pos << 2) | context] = true if pos && !levels[level - 1]
|
|
111
|
+
levels[level] = true
|
|
112
|
+
end
|
|
113
|
+
@link_scan_failures[start_key] = true
|
|
83
114
|
@src.revert_pos(saved_pos)
|
|
115
|
+
@src.terminate if @tree.type == :a || @tree.type == :img
|
|
84
116
|
add_text(result)
|
|
85
117
|
return
|
|
86
118
|
end
|
|
@@ -88,7 +120,7 @@ module Kramdown
|
|
|
88
120
|
@src.scan(LINK_BRACKET_STOP_RE)
|
|
89
121
|
|
|
90
122
|
# reference style link or no link url
|
|
91
|
-
if @src.scan(LINK_INLINE_ID_RE) || !@src.
|
|
123
|
+
if @src.scan(LINK_INLINE_ID_RE) || !@src.match?(/\(/)
|
|
92
124
|
emit_warning = !@src[1]
|
|
93
125
|
link_id = normalize_link_id(@src[1] || alt_text)
|
|
94
126
|
if @link_defs.key?(link_id)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# -*- coding: utf-8; frozen_string_literal: true -*-
|
|
2
2
|
#
|
|
3
3
|
#--
|
|
4
|
-
# Copyright (C) 2009-
|
|
4
|
+
# Copyright (C) 2009-2026 Thomas Leitner <t_leitner@gmx.at>
|
|
5
5
|
#
|
|
6
6
|
# This file is part of kramdown which is licensed under the MIT.
|
|
7
7
|
#++
|
|
@@ -24,6 +24,8 @@ module Kramdown
|
|
|
24
24
|
content_re = /^(?:(?:\t| {4}){#{indentation / 4}} {#{indentation % 4}}|(?:\t| {4}){#{indentation / 4 + 1}}).*\S.*\n/
|
|
25
25
|
lazy_re = /(?!^ {0,#{[indentation, 3].min}}(?:#{IAL_BLOCK}|#{LAZY_END_HTML_STOP}|#{LAZY_END_HTML_START})).*\S.*\n/
|
|
26
26
|
|
|
27
|
+
h.shift if h.size > 100
|
|
28
|
+
|
|
27
29
|
h[indentation] = [content_re, lazy_re, indent_re]
|
|
28
30
|
end
|
|
29
31
|
|
|
@@ -53,7 +55,7 @@ module Kramdown
|
|
|
53
55
|
# Parse the ordered or unordered list at the current location.
|
|
54
56
|
def parse_list
|
|
55
57
|
start_line_number = @src.current_line_number
|
|
56
|
-
type, list_start_re = (@src.
|
|
58
|
+
type, list_start_re = (@src.match?(LIST_START_UL) ? [:ul, LIST_START_UL] : [:ol, LIST_START_OL])
|
|
57
59
|
list = new_block_el(type, nil, nil, location: start_line_number)
|
|
58
60
|
|
|
59
61
|
item = nil
|
|
@@ -63,7 +65,7 @@ module Kramdown
|
|
|
63
65
|
last_is_blank = false
|
|
64
66
|
until @src.eos?
|
|
65
67
|
start_line_number = @src.current_line_number
|
|
66
|
-
if last_is_blank && @src.
|
|
68
|
+
if last_is_blank && @src.match?(HR_START)
|
|
67
69
|
break
|
|
68
70
|
elsif @src.scan(EOB_MARKER)
|
|
69
71
|
eob_found = true
|
|
@@ -200,7 +202,7 @@ module Kramdown
|
|
|
200
202
|
def_start_re = fetch_pattern(:dl, indentation)
|
|
201
203
|
first_as_para = false
|
|
202
204
|
last_is_blank = false
|
|
203
|
-
elsif @src.
|
|
205
|
+
elsif @src.match?(EOB_MARKER)
|
|
204
206
|
break
|
|
205
207
|
elsif (result = @src.scan(content_re)) || (!last_is_blank && (result = @src.scan(lazy_re)))
|
|
206
208
|
result.sub!(/^(\t+)/) { " " * ($1 ? 4 * $1.length : 0) }
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# -*- coding: utf-8; frozen_string_literal: true -*-
|
|
2
2
|
#
|
|
3
3
|
#--
|
|
4
|
-
# Copyright (C) 2009-
|
|
4
|
+
# Copyright (C) 2009-2026 Thomas Leitner <t_leitner@gmx.at>
|
|
5
5
|
#
|
|
6
6
|
# This file is part of kramdown which is licensed under the MIT.
|
|
7
7
|
#++
|
|
@@ -44,7 +44,7 @@ module Kramdown
|
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
until @src.eos?
|
|
47
|
-
break unless @src.
|
|
47
|
+
break unless @src.match?(TABLE_LINE)
|
|
48
48
|
if @src.scan(TABLE_SEP_LINE)
|
|
49
49
|
if rows.empty?
|
|
50
50
|
# nothing to do, ignoring multiple consecutive separator lines
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# -*- coding: utf-8; frozen_string_literal: true -*-
|
|
2
2
|
#
|
|
3
3
|
#--
|
|
4
|
-
# Copyright (C) 2009-
|
|
4
|
+
# Copyright (C) 2009-2026 Thomas Leitner <t_leitner@gmx.at>
|
|
5
5
|
#
|
|
6
6
|
# This file is part of kramdown which is licensed under the MIT.
|
|
7
7
|
#++
|
|
@@ -81,6 +81,7 @@ module Kramdown
|
|
|
81
81
|
:typographic_syms, :line_break, :escaped_chars]
|
|
82
82
|
|
|
83
83
|
@span_pattern_cache ||= Hash.new {|h, k| h[k] = {} }
|
|
84
|
+
@stack_counter = 0
|
|
84
85
|
end
|
|
85
86
|
private_class_method(:new, :allocate)
|
|
86
87
|
|
|
@@ -138,6 +139,8 @@ module Kramdown
|
|
|
138
139
|
|
|
139
140
|
# Parse all block-level elements in +text+ into the element +el+.
|
|
140
141
|
def parse_blocks(el, text = nil)
|
|
142
|
+
@stack_counter += 1
|
|
143
|
+
raise Kramdown::Error, "Elements nested too deep at block level" if @stack_counter > 100
|
|
141
144
|
@stack.push([@tree, @src, @block_ial])
|
|
142
145
|
@tree, @block_ial = el, nil
|
|
143
146
|
@src = (text.nil? ? @src : ::Kramdown::Utils::StringScanner.new(text, el.options[:location]))
|
|
@@ -145,7 +148,7 @@ module Kramdown
|
|
|
145
148
|
status = catch(:stop_block_parsing) do
|
|
146
149
|
until @src.eos?
|
|
147
150
|
@block_parsers.any? do |name|
|
|
148
|
-
if @src.
|
|
151
|
+
if @src.match?(@parsers[name].start_re)
|
|
149
152
|
send(@parsers[name].method)
|
|
150
153
|
else
|
|
151
154
|
false
|
|
@@ -158,6 +161,7 @@ module Kramdown
|
|
|
158
161
|
end
|
|
159
162
|
|
|
160
163
|
@tree, @src, @block_ial = *@stack.pop
|
|
164
|
+
@stack_counter -= 1
|
|
161
165
|
status
|
|
162
166
|
end
|
|
163
167
|
|
|
@@ -213,6 +217,8 @@ module Kramdown
|
|
|
213
217
|
#
|
|
214
218
|
# The parameter +text_type+ specifies the type which should be used for created text nodes.
|
|
215
219
|
def parse_spans(el, stop_re = nil, parsers = nil, text_type = @text_type)
|
|
220
|
+
@stack_counter += 1
|
|
221
|
+
raise Kramdown::Error, "Elements nested too deep at span level" if @stack_counter > 100
|
|
216
222
|
@stack.push([@tree, @text_type]) unless @tree.nil?
|
|
217
223
|
@tree, @text_type = el, text_type
|
|
218
224
|
|
|
@@ -226,11 +232,11 @@ module Kramdown
|
|
|
226
232
|
while !@src.eos? && !stop_re_found
|
|
227
233
|
if (result = @src.scan_until(used_re))
|
|
228
234
|
add_text(result)
|
|
229
|
-
if stop_re && @src.
|
|
235
|
+
if stop_re && @src.match?(stop_re)
|
|
230
236
|
stop_re_found = (block_given? ? yield : true)
|
|
231
237
|
end
|
|
232
238
|
processed = parsers.any? do |name|
|
|
233
|
-
if @src.
|
|
239
|
+
if @src.match?(@parsers[name].start_re)
|
|
234
240
|
send(@parsers[name].method)
|
|
235
241
|
true
|
|
236
242
|
else
|
|
@@ -245,6 +251,7 @@ module Kramdown
|
|
|
245
251
|
end
|
|
246
252
|
|
|
247
253
|
@tree, @text_type = @stack.pop
|
|
254
|
+
@stack_counter -= 1
|
|
248
255
|
|
|
249
256
|
stop_re_found
|
|
250
257
|
end
|
data/lib/kramdown/parser.rb
CHANGED
data/lib/kramdown/utils/html.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# -*- coding: utf-8; frozen_string_literal: true -*-
|
|
2
2
|
#
|
|
3
3
|
#--
|
|
4
|
-
# Copyright (C) 2009-
|
|
4
|
+
# Copyright (C) 2009-2026 Thomas Leitner <t_leitner@gmx.at>
|
|
5
5
|
#
|
|
6
6
|
# This file is part of kramdown which is licensed under the MIT.
|
|
7
7
|
#++
|
|
@@ -65,14 +65,13 @@ module Kramdown
|
|
|
65
65
|
# NOTE: Normally we'd have to add one to the count of newlines to get the correct line number.
|
|
66
66
|
# However we add the one indirectly by using a one-based start_line_number.
|
|
67
67
|
def current_line_number
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
@previous_line_number
|
|
68
|
+
cur_pos = pos
|
|
69
|
+
if cur_pos > @previous_pos
|
|
70
|
+
@previous_line_number += string.byteslice(@previous_pos, cur_pos - @previous_pos).
|
|
71
|
+
force_encoding(Encoding::BINARY).count("\n")
|
|
72
|
+
@previous_pos = cur_pos
|
|
73
|
+
end
|
|
74
|
+
string.getbyte(cur_pos) == 10 ? @previous_line_number + 1 : @previous_line_number
|
|
76
75
|
end
|
|
77
76
|
|
|
78
77
|
end
|
data/lib/kramdown/utils.rb
CHANGED
data/lib/kramdown/version.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# -*- coding: utf-8; frozen_string_literal: true -*-
|
|
2
2
|
#
|
|
3
3
|
#--
|
|
4
|
-
# Copyright (C) 2009-
|
|
4
|
+
# Copyright (C) 2009-2026 Thomas Leitner <t_leitner@gmx.at>
|
|
5
5
|
#
|
|
6
6
|
# This file is part of kramdown which is licensed under the MIT.
|
|
7
7
|
#++
|
|
@@ -10,6 +10,6 @@
|
|
|
10
10
|
module Kramdown
|
|
11
11
|
|
|
12
12
|
# The kramdown version.
|
|
13
|
-
VERSION = '2.
|
|
13
|
+
VERSION = '2.6.0'
|
|
14
14
|
|
|
15
15
|
end
|
data/lib/kramdown.rb
CHANGED
data/man/man1/kramdown.1
CHANGED
|
@@ -136,11 +136,15 @@ The value needs to be an array of option names\.
|
|
|
136
136
|
Default: [template] Used by: HTML converter
|
|
137
137
|
.RE
|
|
138
138
|
.TP
|
|
139
|
-
\fB\-\-
|
|
139
|
+
\fB\-\-header\-links\fP \fIARG\fP
|
|
140
140
|
Adds anchor tags within headers that can be used to generate permalinks when not using a table of contents\.
|
|
141
141
|
.RS
|
|
142
142
|
.P
|
|
143
|
-
The anchor tags are empty
|
|
143
|
+
If the value is \fBfalse\fP, no header links are used; if \fBtrue\fP, the defaults are used: The anchor tags are empty and at the start of the header element\. This can be changed by using a hash as value with the following symbol keys:
|
|
144
|
+
.IP \(bu 4
|
|
145
|
+
content: Defines the content of the anchor tag, default is \[u2018]\[u2019]\&\.
|
|
146
|
+
.IP \(bu 4
|
|
147
|
+
position: Whether the anchor tag is placed at the \[u2018]start\[u2019] or the \[u2018]end\[u2019] of the header tag, default is \[u2018]start\[u2019]\&\.
|
|
144
148
|
.P
|
|
145
149
|
Default: false
|
|
146
150
|
.RE
|
data/test/run_tests.rb
CHANGED