kramdown 2.0.0.beta2 → 2.0.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 +4 -4
- data/CONTRIBUTERS +2 -1
- data/VERSION +1 -1
- data/lib/kramdown/converter/html.rb +22 -5
- data/lib/kramdown/converter/syntax_highlighter/rouge.rb +1 -0
- data/lib/kramdown/element.rb +6 -3
- data/lib/kramdown/options.rb +12 -0
- data/lib/kramdown/parser/kramdown.rb +3 -1
- data/lib/kramdown/parser/kramdown/extensions.rb +1 -1
- data/lib/kramdown/version.rb +1 -1
- data/man/man1/kramdown.1 +9 -0
- data/test/test_files.rb +3 -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/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
- metadata +9 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e61a5f6dbf5b13bfcf0164acaf6a0c6e8fa2cd2c39fc7368bf9f54be38e0552
|
4
|
+
data.tar.gz: e03352fce83854b256596c7718dd2c48251b5851f7e1ca06012d433526b6015b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3bf07ed2b152212b8aa8e50383b7cfc7a38a16d11441f6c5b2790c834020e3ef8ab82e6978bd86b3334740cc4b23a407f66b744ded4ee22bb6e75b210d3668cc
|
7
|
+
data.tar.gz: 0206cd73d6c8d75470701c197fb89d151e6f3c2c694b20af1068f8c4d03386f065194e92c2c3cea5ec37e72c5f52132ce282d2c80888f229811cefc62f2049ed
|
data/CONTRIBUTERS
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Count Name
|
2
2
|
======= ====
|
3
|
-
|
3
|
+
909 Thomas Leitner <t_leitner@gmx.at>
|
4
4
|
7 Christian Cornelssen <ccorn@1tein.de>
|
5
5
|
6 Gioele Barabucci <gioele@svario.it>
|
6
6
|
4 Ted Pak <powerpak006@gmail.com>
|
@@ -61,6 +61,7 @@
|
|
61
61
|
1 Cédric Boutillier <cedric.boutillier@gmail.com>
|
62
62
|
1 Ashwin Maroli <ashmaroli@gmail.com>
|
63
63
|
1 Ashe Connor <ashe@kivikakk.ee>
|
64
|
+
1 Antoine Cotten <hello@acotten.com>
|
64
65
|
1 Andrew <andrew.dale.wylie@gmail.com>
|
65
66
|
1 Alpha Chen <alpha.chen@gmail.com>
|
66
67
|
1 Alex Tomlins <alex.tomlins@digital.cabinet-office.gov.uk>
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0.0
|
1
|
+
2.0.0
|
@@ -84,11 +84,26 @@ module Kramdown
|
|
84
84
|
def convert_p(el, indent)
|
85
85
|
if el.options[:transparent]
|
86
86
|
inner(el, indent)
|
87
|
+
elsif el.children.size == 1 && el.children.first.type == :img &&
|
88
|
+
el.children.first.options[:ial]&.[](:refs)&.include?('standalone')
|
89
|
+
convert_standalone_image(el.children.first, indent)
|
87
90
|
else
|
88
91
|
format_as_block_html(el.type, el.attr, inner(el, indent), indent)
|
89
92
|
end
|
90
93
|
end
|
91
94
|
|
95
|
+
# Helper method used by +convert_p+ to convert a paragraph that only contains a single :img
|
96
|
+
# element.
|
97
|
+
def convert_standalone_image(el, indent)
|
98
|
+
attr = el.attr.dup
|
99
|
+
figure_attr = {}
|
100
|
+
figure_attr['class'] = attr.delete('class') if attr.key?('class')
|
101
|
+
figure_attr['id'] = attr.delete('id') if attr.key?('id')
|
102
|
+
body = "#{' ' * (indent + @indent)}<img#{html_attributes(attr)} />\n" \
|
103
|
+
"#{' ' * (indent + @indent)}<figcaption>#{attr['alt']}</figcaption>\n"
|
104
|
+
format_as_indented_block_html("figure", figure_attr, body, indent)
|
105
|
+
end
|
106
|
+
|
92
107
|
def convert_codeblock(el, indent)
|
93
108
|
attr = el.attr.dup
|
94
109
|
lang = extract_code_language!(attr)
|
@@ -271,17 +286,19 @@ module Kramdown
|
|
271
286
|
|
272
287
|
def convert_footnote(el, _indent)
|
273
288
|
repeat = ''
|
274
|
-
|
289
|
+
name = @options[:footnote_prefix] + el.options[:name]
|
290
|
+
if (footnote = @footnotes_by_name[name])
|
275
291
|
number = footnote[2]
|
276
292
|
repeat = ":#{footnote[3] += 1}"
|
277
293
|
else
|
278
294
|
number = @footnote_counter
|
279
295
|
@footnote_counter += 1
|
280
|
-
@footnotes << [
|
281
|
-
@footnotes_by_name[
|
296
|
+
@footnotes << [name, el.value, number, 0]
|
297
|
+
@footnotes_by_name[name] = @footnotes.last
|
282
298
|
end
|
283
|
-
"<sup id=\"fnref:#{
|
284
|
-
"<a href=\"#fn:#{
|
299
|
+
"<sup id=\"fnref:#{name}#{repeat}\">" \
|
300
|
+
"<a href=\"#fn:#{name}\" class=\"footnote\">" \
|
301
|
+
"#{number}</a></sup>"
|
285
302
|
end
|
286
303
|
|
287
304
|
def convert_raw(el, _indent)
|
@@ -24,6 +24,7 @@ module Kramdown::Converter::SyntaxHighlighter
|
|
24
24
|
def self.call(converter, text, lang, type, call_opts)
|
25
25
|
opts = options(converter, type)
|
26
26
|
call_opts[:default_lang] = opts[:default_lang]
|
27
|
+
return nil unless lang || opts[:default_lang] || opts[:guess_lang]
|
27
28
|
lexer = ::Rouge::Lexer.find_fancy(lang || opts[:default_lang], text)
|
28
29
|
return nil if opts[:disable] || !lexer || lexer.tag == "plaintext"
|
29
30
|
opts[:css_class] ||= 'highlight' # For backward compatibility when using Rouge 2.0
|
data/lib/kramdown/element.rb
CHANGED
@@ -42,6 +42,7 @@ module Kramdown
|
|
42
42
|
#
|
43
43
|
# :options:: This key may be used to store options that were set during parsing of the document.
|
44
44
|
#
|
45
|
+
# :footnote_count:: This key stores the number of actually referenced footnotes of the document.
|
45
46
|
#
|
46
47
|
# === :blank
|
47
48
|
#
|
@@ -500,9 +501,11 @@ module Kramdown
|
|
500
501
|
end
|
501
502
|
|
502
503
|
def inspect #:nodoc:
|
503
|
-
"<kd:#{@type}
|
504
|
-
"#{
|
505
|
-
"#{
|
504
|
+
"<kd:#{@type}" \
|
505
|
+
"#{value.nil? ? '' : ' value=' + value.inspect}" \
|
506
|
+
"#{attr.empty? ? '' : ' attr=' + attr.inspect}" \
|
507
|
+
"#{options.empty? ? '' : ' options=' + options.inspect}" \
|
508
|
+
"#{children.empty? ? '' : ' children=' + children.inspect}>"
|
506
509
|
end
|
507
510
|
|
508
511
|
CATEGORY = {} # :nodoc:
|
data/lib/kramdown/options.rb
CHANGED
@@ -550,6 +550,18 @@ module Kramdown
|
|
550
550
|
Used by: HTML converter
|
551
551
|
EOF
|
552
552
|
|
553
|
+
define(:footnote_prefix, String, '', <<~EOF)
|
554
|
+
Prefix used for footnote IDs
|
555
|
+
|
556
|
+
This option can be used to set a prefix for footnote IDs. This is useful
|
557
|
+
when rendering multiple documents into the same output file to avoid
|
558
|
+
duplicate IDs. The prefix should only contain characters that are valid
|
559
|
+
in an ID!
|
560
|
+
|
561
|
+
Default: ''
|
562
|
+
Used by: HTML
|
563
|
+
EOF
|
564
|
+
|
553
565
|
end
|
554
566
|
|
555
567
|
end
|
@@ -93,11 +93,13 @@ module Kramdown
|
|
93
93
|
update_tree(data[:content])
|
94
94
|
replace_abbreviations(data[:content])
|
95
95
|
end
|
96
|
+
footnote_count = 0
|
96
97
|
@footnotes.each do |name, data|
|
97
|
-
next if data.key?(:marker)
|
98
|
+
(footnote_count += 1; next) if data.key?(:marker)
|
98
99
|
line = data[:content].options[:location]
|
99
100
|
warning("Footnote definition for '#{name}' on line #{line} is unreferenced - ignoring")
|
100
101
|
end
|
102
|
+
@root.options[:footnote_count] = footnote_count
|
101
103
|
end
|
102
104
|
|
103
105
|
protected
|
@@ -39,7 +39,7 @@ module Kramdown
|
|
39
39
|
|
40
40
|
# Update the +ial+ with the information from the inline attribute list +opts+.
|
41
41
|
def update_ial_with_ial(ial, opts)
|
42
|
-
(ial[:refs] ||= [])
|
42
|
+
(ial[:refs] ||= []).concat(opts[:refs]) if opts.key?(:refs)
|
43
43
|
opts.each do |k, v|
|
44
44
|
if k == IAL_CLASS_ATTR
|
45
45
|
ial[k] = "#{ial[k]} #{v}".lstrip
|
data/lib/kramdown/version.rb
CHANGED
data/man/man1/kramdown.1
CHANGED
@@ -102,6 +102,15 @@ This option can be used to specify the number that is used for the first footnot
|
|
102
102
|
Default: 1 Used by: HTML converter
|
103
103
|
.RE
|
104
104
|
.TP
|
105
|
+
\fB\-\-footnote\-prefix\fP \fIARG\fP
|
106
|
+
Prefix used for footnote IDs
|
107
|
+
.RS
|
108
|
+
.P
|
109
|
+
This option can be used to set a prefix for footnote IDs\. This is useful when rendering multiple documents into the same output file to avoid duplicate IDs\. The prefix should only contain characters that are valid in an ID!
|
110
|
+
.P
|
111
|
+
Default: \[u2018]\[u2019] Used by: HTML
|
112
|
+
.RE
|
113
|
+
.TP
|
105
114
|
\fB\-\-header\-offset\fP \fIARG\fP
|
106
115
|
Sets the output offset for headers
|
107
116
|
.RS
|
data/test/test_files.rb
CHANGED
@@ -134,6 +134,7 @@ class TestFiles < Minitest::Test
|
|
134
134
|
'test/testcases/span/04_footnote/markers.text', # bc of footnote in header
|
135
135
|
'test/testcases/block/06_codeblock/with_lang_in_fenced_block_name_with_dash.text',
|
136
136
|
'test/testcases/block/06_codeblock/with_lang_in_fenced_block_any_char.text',
|
137
|
+
'test/testcases/block/03_paragraph/standalone_image.text', # bc of standalone image
|
137
138
|
].compact
|
138
139
|
Dir[File.dirname(__FILE__) + '/testcases/**/*.text'].each do |text_file|
|
139
140
|
next if EXCLUDE_LATEX_FILES.any? {|f| text_file =~ /#{f}$/ }
|
@@ -177,6 +178,7 @@ class TestFiles < Minitest::Test
|
|
177
178
|
'test/testcases/span/05_html/mark_element.text', # bc of tidy
|
178
179
|
'test/testcases/block/09_html/xml.text', # bc of tidy
|
179
180
|
'test/testcases/span/05_html/xml.text', # bc of tidy
|
181
|
+
'test/testcases/block/03_paragraph/standalone_image.text', # bc of standalone image
|
180
182
|
].compact
|
181
183
|
Dir[File.dirname(__FILE__) + '/testcases/**/*.text'].each do |text_file|
|
182
184
|
next if EXCLUDE_TEXT_FILES.any? {|f| text_file =~ /#{f}$/ }
|
@@ -225,6 +227,7 @@ class TestFiles < Minitest::Test
|
|
225
227
|
'test/testcases/span/05_html/mark_element.html', # bc of tidy
|
226
228
|
'test/testcases/block/09_html/xml.html', # bc of tidy
|
227
229
|
'test/testcases/span/05_html/xml.html', # bc of tidy
|
230
|
+
'test/testcases/block/03_paragraph/standalone_image.html', # bc of standalone image
|
228
231
|
].compact
|
229
232
|
Dir[File.dirname(__FILE__) + '/testcases/**/*.html'].each do |html_file|
|
230
233
|
next if EXCLUDE_HTML_KD_FILES.any? {|f| html_file =~ /#{f}$/ }
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<p>This is a<sup id="fnref:adf123-ab"><a href="#fn:adf123-ab" class="footnote">1</a></sup> footnote<sup id="fnref:adf123-ab:1"><a href="#fn:adf123-ab" class="footnote">1</a></sup>. And another<sup id="fnref:adf123-bc"><a href="#fn:adf123-bc" class="footnote">2</a></sup>.</p>
|
2
|
+
|
3
|
+
<div class="footnotes">
|
4
|
+
<ol>
|
5
|
+
<li id="fn:adf123-ab">
|
6
|
+
<p>Some text. <a href="#fnref:adf123-ab" class="reversefootnote">↩</a> <a href="#fnref:adf123-ab:1" class="reversefootnote">↩<sup>2</sup></a></p>
|
7
|
+
</li>
|
8
|
+
<li id="fn:adf123-bc">
|
9
|
+
<p>Some other text. <a href="#fnref:adf123-bc" class="reversefootnote">↩</a></p>
|
10
|
+
</li>
|
11
|
+
</ol>
|
12
|
+
</div>
|
@@ -0,0 +1 @@
|
|
1
|
+
:footnote_prefix: adf123-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kramdown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Leitner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-01-
|
11
|
+
date: 2019-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -148,6 +148,8 @@ files:
|
|
148
148
|
- test/testcases/block/03_paragraph/no_newline_at_end.text
|
149
149
|
- test/testcases/block/03_paragraph/one_para.html
|
150
150
|
- test/testcases/block/03_paragraph/one_para.text
|
151
|
+
- test/testcases/block/03_paragraph/standalone_image.html
|
152
|
+
- test/testcases/block/03_paragraph/standalone_image.text
|
151
153
|
- test/testcases/block/03_paragraph/two_para.html
|
152
154
|
- test/testcases/block/03_paragraph/two_para.text
|
153
155
|
- test/testcases/block/03_paragraph/with_html_to_native.html
|
@@ -522,6 +524,9 @@ files:
|
|
522
524
|
- test/testcases/span/04_footnote/footnote_nr.latex
|
523
525
|
- test/testcases/span/04_footnote/footnote_nr.options
|
524
526
|
- test/testcases/span/04_footnote/footnote_nr.text
|
527
|
+
- test/testcases/span/04_footnote/footnote_prefix.html
|
528
|
+
- test/testcases/span/04_footnote/footnote_prefix.options
|
529
|
+
- test/testcases/span/04_footnote/footnote_prefix.text
|
525
530
|
- test/testcases/span/04_footnote/inside_footnote.html
|
526
531
|
- test/testcases/span/04_footnote/inside_footnote.text
|
527
532
|
- test/testcases/span/04_footnote/markers.html
|
@@ -626,9 +631,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
626
631
|
version: '2.3'
|
627
632
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
628
633
|
requirements:
|
629
|
-
- - "
|
634
|
+
- - ">="
|
630
635
|
- !ruby/object:Gem::Version
|
631
|
-
version:
|
636
|
+
version: '0'
|
632
637
|
requirements: []
|
633
638
|
rubyforge_project:
|
634
639
|
rubygems_version: 2.7.3
|