kramdown 1.17.0 → 2.0.0.beta1
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.
Potentially problematic release.
This version of kramdown might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CONTRIBUTERS +4 -2
- data/VERSION +1 -1
- data/bin/kramdown +13 -14
- data/lib/kramdown.rb +2 -2
- data/lib/kramdown/converter.rb +6 -7
- data/lib/kramdown/converter/base.rb +18 -29
- data/lib/kramdown/converter/hash_ast.rb +4 -4
- data/lib/kramdown/converter/html.rb +82 -67
- data/lib/kramdown/converter/kramdown.rb +83 -78
- data/lib/kramdown/converter/latex.rb +53 -47
- data/lib/kramdown/converter/man.rb +22 -25
- data/lib/kramdown/converter/math_engine/mathjax.rb +10 -10
- data/lib/kramdown/converter/remove_html_tags.rb +2 -2
- data/lib/kramdown/converter/syntax_highlighter.rb +2 -2
- data/lib/kramdown/converter/syntax_highlighter/minted.rb +2 -2
- data/lib/kramdown/converter/syntax_highlighter/rouge.rb +5 -5
- data/lib/kramdown/converter/toc.rb +5 -5
- data/lib/kramdown/document.rb +9 -11
- data/lib/kramdown/element.rb +11 -9
- data/lib/kramdown/error.rb +2 -2
- data/lib/kramdown/options.rb +258 -384
- data/lib/kramdown/parser.rb +2 -3
- data/lib/kramdown/parser/base.rb +7 -6
- data/lib/kramdown/parser/html.rb +103 -95
- data/lib/kramdown/parser/kramdown.rb +32 -36
- data/lib/kramdown/parser/kramdown/abbreviation.rb +13 -10
- data/lib/kramdown/parser/kramdown/autolink.rb +3 -3
- data/lib/kramdown/parser/kramdown/blank_line.rb +2 -2
- data/lib/kramdown/parser/kramdown/block_boundary.rb +2 -2
- data/lib/kramdown/parser/kramdown/blockquote.rb +4 -5
- data/lib/kramdown/parser/kramdown/codeblock.rb +4 -5
- data/lib/kramdown/parser/kramdown/codespan.rb +5 -5
- data/lib/kramdown/parser/kramdown/emphasis.rb +6 -6
- data/lib/kramdown/parser/kramdown/eob.rb +2 -2
- data/lib/kramdown/parser/kramdown/escaped_chars.rb +2 -2
- data/lib/kramdown/parser/kramdown/extensions.rb +31 -26
- data/lib/kramdown/parser/kramdown/footnote.rb +7 -6
- data/lib/kramdown/parser/kramdown/header.rb +6 -6
- data/lib/kramdown/parser/kramdown/horizontal_rule.rb +3 -3
- data/lib/kramdown/parser/kramdown/html.rb +31 -26
- data/lib/kramdown/parser/kramdown/html_entity.rb +6 -5
- data/lib/kramdown/parser/kramdown/line_break.rb +3 -3
- data/lib/kramdown/parser/kramdown/link.rb +13 -11
- data/lib/kramdown/parser/kramdown/list.rb +38 -40
- data/lib/kramdown/parser/kramdown/math.rb +4 -5
- data/lib/kramdown/parser/kramdown/paragraph.rb +5 -5
- data/lib/kramdown/parser/kramdown/smart_quotes.rb +23 -23
- data/lib/kramdown/parser/kramdown/table.rb +18 -17
- data/lib/kramdown/parser/kramdown/typographic_symbol.rb +8 -8
- data/lib/kramdown/parser/markdown.rb +9 -8
- data/lib/kramdown/utils.rb +5 -6
- data/lib/kramdown/utils/configurable.rb +7 -6
- data/lib/kramdown/utils/entities.rb +286 -289
- data/lib/kramdown/utils/html.rb +10 -12
- data/lib/kramdown/utils/lru_cache.rb +3 -2
- data/lib/kramdown/utils/string_scanner.rb +2 -3
- data/lib/kramdown/utils/unidecoder.rb +8 -6
- data/lib/kramdown/version.rb +3 -3
- data/man/man1/kramdown.1 +3 -107
- data/test/run_tests.rb +6 -6
- data/test/test_files.rb +122 -298
- data/test/test_location.rb +8 -30
- data/test/test_string_scanner_kramdown.rb +6 -9
- data/test/testcases/block/06_codeblock/highlighting-opts.html +6 -6
- data/test/testcases/block/06_codeblock/highlighting.html +5 -6
- data/test/testcases/block/06_codeblock/with_lang_in_fenced_block.options +1 -1
- data/test/testcases/block/07_horizontal_rule/error.html +2 -2
- 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_to_native/typography.html +1 -1
- data/test/testcases/block/09_html/simple.html +1 -1
- data/test/testcases/block/12_extension/options3.html +7 -6
- data/test/testcases/block/12_extension/options3.text +2 -2
- data/test/testcases/span/01_link/inline.html +1 -1
- data/test/testcases/span/01_link/reference.html +3 -3
- data/test/testcases/span/03_codespan/highlighting.html +1 -1
- data/test/testcases/span/text_substitutions/entities_as_char.html +1 -1
- metadata +5 -234
- data/Rakefile +0 -341
- data/benchmark/benchmark.rb +0 -43
- 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 -12
- data/benchmark/timing.sh +0 -10
- data/doc/_design.scss +0 -441
- data/doc/bg.png +0 -0
- data/doc/default.scss +0 -217
- data/doc/default.template +0 -62
- data/doc/documentation.page +0 -84
- data/doc/documentation.template +0 -36
- data/doc/index.page +0 -113
- data/doc/installation.page +0 -88
- data/doc/links.markdown +0 -6
- data/doc/metainfo +0 -13
- data/doc/news.feed +0 -9
- data/doc/news.page +0 -29
- data/doc/options.page +0 -49
- data/doc/quickref.page +0 -603
- data/doc/sidebar.template +0 -22
- data/doc/sitemap.sitemap +0 -5
- data/doc/syntax.page +0 -1799
- data/doc/tests.page +0 -104
- data/doc/virtual +0 -14
- data/lib/kramdown/converter/math_engine/itex2mml.rb +0 -39
- data/lib/kramdown/converter/math_engine/katex.rb +0 -35
- data/lib/kramdown/converter/math_engine/mathjaxnode.rb +0 -56
- data/lib/kramdown/converter/math_engine/ritex.rb +0 -38
- data/lib/kramdown/converter/math_engine/sskatex.rb +0 -97
- data/lib/kramdown/converter/pdf.rb +0 -625
- data/lib/kramdown/converter/syntax_highlighter/coderay.rb +0 -81
- data/lib/kramdown/parser/gfm.rb +0 -188
- data/lib/kramdown/utils/ordered_hash.rb +0 -18
- 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 -60
- data/test/testcases/block/15_math/itex2mml.html +0 -1
- data/test/testcases/block/15_math/itex2mml.options +0 -1
- data/test/testcases/block/15_math/itex2mml.text +0 -1
- data/test/testcases/block/15_math/katex.html.19 +0 -2
- data/test/testcases/block/15_math/katex.options +0 -1
- data/test/testcases/block/15_math/katex.text +0 -2
- data/test/testcases/block/15_math/mathjaxnode.html.19 +0 -27
- data/test/testcases/block/15_math/mathjaxnode.options +0 -1
- data/test/testcases/block/15_math/mathjaxnode.text +0 -1
- data/test/testcases/block/15_math/mathjaxnode_notexhints.html.19 +0 -23
- data/test/testcases/block/15_math/mathjaxnode_notexhints.options +0 -3
- data/test/testcases/block/15_math/mathjaxnode_notexhints.text +0 -1
- data/test/testcases/block/15_math/mathjaxnode_semantics.html.19 +0 -32
- data/test/testcases/block/15_math/mathjaxnode_semantics.options +0 -3
- data/test/testcases/block/15_math/mathjaxnode_semantics.text +0 -1
- data/test/testcases/block/15_math/ritex.html +0 -1
- data/test/testcases/block/15_math/ritex.options +0 -1
- data/test/testcases/block/15_math/ritex.text +0 -1
- data/test/testcases/block/15_math/sskatex.html.19 +0 -2
- data/test/testcases/block/15_math/sskatex.options +0 -1
- data/test/testcases/block/15_math/sskatex.text +0 -2
- 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/math/itex2mml.html +0 -1
- data/test/testcases/span/math/itex2mml.options +0 -1
- data/test/testcases/span/math/itex2mml.text +0 -1
- data/test/testcases/span/math/katex.html.19 +0 -1
- data/test/testcases/span/math/katex.options +0 -1
- data/test/testcases/span/math/katex.text +0 -1
- data/test/testcases/span/math/mathjaxnode.html.19 +0 -27
- data/test/testcases/span/math/mathjaxnode.options +0 -1
- data/test/testcases/span/math/mathjaxnode.text +0 -1
- data/test/testcases/span/math/ritex.html +0 -1
- data/test/testcases/span/math/ritex.options +0 -1
- data/test/testcases/span/math/ritex.text +0 -1
- data/test/testcases/span/math/sskatex.html.19 +0 -1
- data/test/testcases/span/math/sskatex.options +0 -1
- data/test/testcases/span/math/sskatex.text +0 -1
- data/test/testcases/span/text_substitutions/entities_as_char.html.19 +0 -1
- data/test/testcases_gfm/atx_header.html +0 -3
- data/test/testcases_gfm/atx_header.text +0 -3
- data/test/testcases_gfm/backticks_disable_highlighting.html +0 -2
- data/test/testcases_gfm/backticks_disable_highlighting.options +0 -1
- data/test/testcases_gfm/backticks_disable_highlighting.text +0 -3
- data/test/testcases_gfm/backticks_syntax.html +0 -20
- data/test/testcases_gfm/backticks_syntax.text +0 -19
- data/test/testcases_gfm/codeblock_fenced.html +0 -20
- data/test/testcases_gfm/codeblock_fenced.options +0 -1
- data/test/testcases_gfm/codeblock_fenced.text +0 -21
- data/test/testcases_gfm/hard_line_breaks.html +0 -3
- data/test/testcases_gfm/hard_line_breaks.text +0 -3
- data/test/testcases_gfm/hard_line_breaks_off.html +0 -2
- data/test/testcases_gfm/hard_line_breaks_off.options +0 -1
- data/test/testcases_gfm/hard_line_breaks_off.text +0 -2
- data/test/testcases_gfm/header_ids.html +0 -27
- data/test/testcases_gfm/header_ids.html.19 +0 -27
- data/test/testcases_gfm/header_ids.options +0 -1
- data/test/testcases_gfm/header_ids.text +0 -27
- data/test/testcases_gfm/header_ids_with_prefix.html +0 -3
- data/test/testcases_gfm/header_ids_with_prefix.options +0 -2
- data/test/testcases_gfm/header_ids_with_prefix.text +0 -3
- data/test/testcases_gfm/no_typographic.html +0 -3
- data/test/testcases_gfm/no_typographic.html.19 +0 -3
- data/test/testcases_gfm/no_typographic.options +0 -1
- data/test/testcases_gfm/no_typographic.text +0 -3
- data/test/testcases_gfm/paragraph_end-disabled.html +0 -31
- data/test/testcases_gfm/paragraph_end-disabled.options +0 -1
- data/test/testcases_gfm/paragraph_end-disabled.text +0 -27
- data/test/testcases_gfm/paragraph_end.html +0 -38
- data/test/testcases_gfm/paragraph_end.text +0 -27
- data/test/testcases_gfm/strikethrough.html +0 -27
- data/test/testcases_gfm/strikethrough.html.19 +0 -27
- data/test/testcases_gfm/strikethrough.text +0 -27
- data/test/testcases_gfm/task_list.html +0 -40
- data/test/testcases_gfm/task_list.text +0 -26
- data/test/testcases_gfm/two_para_hard_line_breaks.html +0 -4
- data/test/testcases_gfm/two_para_hard_line_breaks.text +0 -4
@@ -1,7 +1,7 @@
|
|
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
6
|
# This file is part of kramdown which is licensed under the MIT.
|
7
7
|
#++
|
@@ -29,14 +29,16 @@ module Kramdown
|
|
29
29
|
@stack = []
|
30
30
|
end
|
31
31
|
|
32
|
-
def convert(el, opts = {:
|
32
|
+
def convert(el, opts = {indent: 0})
|
33
33
|
res = send("convert_#{el.type}", el, opts)
|
34
|
+
res = res.dup if res.frozen?
|
34
35
|
if ![:html_element, :li, :dt, :dd, :td].include?(el.type) && (ial = ial_for_element(el))
|
35
36
|
res << ial
|
36
37
|
res << "\n\n" if Element.category(el) == :block
|
37
38
|
elsif [:ul, :dl, :ol, :codeblock].include?(el.type) && opts[:next] &&
|
38
39
|
([el.type, :codeblock].include?(opts[:next].type) ||
|
39
|
-
(opts[:next].type == :blank && opts[:nnext] &&
|
40
|
+
(opts[:next].type == :blank && opts[:nnext] &&
|
41
|
+
[el.type, :codeblock].include?(opts[:nnext].type)))
|
40
42
|
res << "^\n\n"
|
41
43
|
elsif Element.category(el) == :block &&
|
42
44
|
![:li, :dd, :dt, :td, :th, :tr, :thead, :tbody, :tfoot, :blank].include?(el.type) &&
|
@@ -47,23 +49,23 @@ module Kramdown
|
|
47
49
|
res
|
48
50
|
end
|
49
51
|
|
50
|
-
def inner(el, opts = {:
|
52
|
+
def inner(el, opts = {indent: 0})
|
51
53
|
@stack.push(el)
|
52
|
-
result = ''
|
54
|
+
result = +''
|
53
55
|
el.children.each_with_index do |inner_el, index|
|
54
56
|
options = opts.dup
|
55
57
|
options[:index] = index
|
56
|
-
options[:prev] = (index == 0 ? nil : el.children[index-1])
|
57
|
-
options[:pprev] = (index <= 1 ? nil : el.children[index-2])
|
58
|
-
options[:next] = (index == el.children.length - 1 ? nil : el.children[index+1])
|
59
|
-
options[:nnext] = (index >= el.children.length - 2 ? nil : el.children[index+2])
|
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])
|
60
62
|
result << convert(inner_el, options)
|
61
63
|
end
|
62
64
|
@stack.pop
|
63
65
|
result
|
64
66
|
end
|
65
67
|
|
66
|
-
def convert_blank(
|
68
|
+
def convert_blank(_el, _opts)
|
67
69
|
""
|
68
70
|
end
|
69
71
|
|
@@ -82,8 +84,8 @@ module Kramdown
|
|
82
84
|
def convert_p(el, opts)
|
83
85
|
w = @options[:line_width] - opts[:indent].to_s.to_i
|
84
86
|
first, second, *rest = inner(el, opts).strip.gsub(/(.{1,#{w}})( +|$\n?)/, "\\1\n").split(/\n/)
|
85
|
-
first
|
86
|
-
second
|
87
|
+
first&.gsub!(/^(?:(#|>)|(\d+)\.|([+-]\s))/) { $1 || $3 ? "\\#{$1 || $3}" : "#{$2}\\." }
|
88
|
+
second&.gsub!(/^([=-]+\s*?)$/, "\\\1")
|
87
89
|
res = [first, second, *rest].compact.join("\n") + "\n"
|
88
90
|
if el.children.length == 1 && el.children.first.type == :math
|
89
91
|
res = "\\#{res}"
|
@@ -93,41 +95,40 @@ module Kramdown
|
|
93
95
|
res
|
94
96
|
end
|
95
97
|
|
96
|
-
|
97
|
-
|
98
|
-
el.value.split(/\n/).map {|l| l.empty? ? " " : " #{l}"}.join("\n") + "\n"
|
98
|
+
def convert_codeblock(el, _opts)
|
99
|
+
el.value.split(/\n/).map {|l| l.empty? ? " " : " #{l}" }.join("\n") + "\n"
|
99
100
|
end
|
100
101
|
|
101
102
|
def convert_blockquote(el, opts)
|
102
103
|
opts[:indent] += 2
|
103
|
-
inner(el, opts).chomp.split(/\n/).map {|l| "> #{l}"}.join("\n") << "\n"
|
104
|
+
inner(el, opts).chomp.split(/\n/).map {|l| "> #{l}" }.join("\n") << "\n"
|
104
105
|
end
|
105
106
|
|
106
107
|
def convert_header(el, opts)
|
107
|
-
res = ''
|
108
|
+
res = +''
|
108
109
|
res << "#{'#' * output_header_level(el.options[:level])} #{inner(el, opts)}"
|
109
|
-
res[-1, 1] = "\\#" if res[-1] ==
|
110
|
+
res[-1, 1] = "\\#" if res[-1] == '#'
|
110
111
|
res << " {##{el.attr['id']}}" if el.attr['id'] && !el.attr['id'].strip.empty?
|
111
112
|
res << "\n"
|
112
113
|
end
|
113
114
|
|
114
|
-
def convert_hr(
|
115
|
+
def convert_hr(_el, _opts)
|
115
116
|
"* * *\n"
|
116
117
|
end
|
117
118
|
|
118
119
|
def convert_ul(el, opts)
|
119
120
|
inner(el, opts).sub(/\n+\Z/, "\n")
|
120
121
|
end
|
121
|
-
alias
|
122
|
-
alias
|
122
|
+
alias convert_ol convert_ul
|
123
|
+
alias convert_dl convert_ul
|
123
124
|
|
124
125
|
def convert_li(el, opts)
|
125
126
|
sym, width = if @stack.last.type == :ul
|
126
|
-
['* ', el.children.first && el.children.first.type == :codeblock ? 4 : 2]
|
127
|
+
[+'* ', el.children.first && el.children.first.type == :codeblock ? 4 : 2]
|
127
128
|
else
|
128
129
|
["#{opts[:index] + 1}.".ljust(4), 4]
|
129
130
|
end
|
130
|
-
if ial = ial_for_element(el)
|
131
|
+
if (ial = ial_for_element(el))
|
131
132
|
sym << ial << " "
|
132
133
|
end
|
133
134
|
|
@@ -135,12 +136,12 @@ module Kramdown
|
|
135
136
|
text = inner(el, opts)
|
136
137
|
newlines = text.scan(/\n*\Z/).first
|
137
138
|
first, *last = text.split(/\n/)
|
138
|
-
last = last.map {|l| " "*width + l}.join("\n")
|
139
|
+
last = last.map {|l| " " * width + l }.join("\n")
|
139
140
|
text = (first.nil? ? "\n" : first + (last.empty? ? "" : "\n") + last + newlines)
|
140
141
|
if el.children.first && el.children.first.type == :p && !el.children.first.options[:transparent]
|
141
|
-
res = "#{sym}#{text}"
|
142
|
+
res = +"#{sym}#{text}"
|
142
143
|
res << "^\n" if el.children.size == 1 && @stack.last.children.last == el &&
|
143
|
-
(@stack.last.children.any? {|c| c.children.first.type != :p} || @stack.last.children.size == 1)
|
144
|
+
(@stack.last.children.any? {|c| c.children.first.type != :p } || @stack.last.children.size == 1)
|
144
145
|
res
|
145
146
|
elsif el.children.first && el.children.first.type == :codeblock
|
146
147
|
"#{sym}\n #{text}"
|
@@ -150,8 +151,8 @@ module Kramdown
|
|
150
151
|
end
|
151
152
|
|
152
153
|
def convert_dd(el, opts)
|
153
|
-
sym, width = ": ", (el.children.first && el.children.first.type == :codeblock ? 4 : 2)
|
154
|
-
if ial = ial_for_element(el)
|
154
|
+
sym, width = +": ", (el.children.first && el.children.first.type == :codeblock ? 4 : 2)
|
155
|
+
if (ial = ial_for_element(el))
|
155
156
|
sym << ial << " "
|
156
157
|
end
|
157
158
|
|
@@ -159,10 +160,10 @@ module Kramdown
|
|
159
160
|
text = inner(el, opts)
|
160
161
|
newlines = text.scan(/\n*\Z/).first
|
161
162
|
first, *last = text.split(/\n/)
|
162
|
-
last = last.map {|l| " "*width + l}.join("\n")
|
163
|
+
last = last.map {|l| " " * width + l }.join("\n")
|
163
164
|
text = first.to_s + (last.empty? ? "" : "\n") + last + newlines
|
164
165
|
text.chomp! if text =~ /\n\n\Z/ && opts[:next] && opts[:next].type == :dd
|
165
|
-
text << "\n" if
|
166
|
+
text << "\n" if text !~ /\n\n\Z/ && opts[:next] && opts[:next].type == :dt
|
166
167
|
text << "\n" if el.children.empty?
|
167
168
|
if el.children.first && el.children.first.type == :p && !el.children.first.options[:transparent]
|
168
169
|
"\n#{sym}#{text}"
|
@@ -174,34 +175,37 @@ module Kramdown
|
|
174
175
|
end
|
175
176
|
|
176
177
|
def convert_dt(el, opts)
|
177
|
-
result = ''
|
178
|
-
if ial = ial_for_element(el)
|
178
|
+
result = +''
|
179
|
+
if (ial = ial_for_element(el))
|
179
180
|
result << ial << " "
|
180
181
|
end
|
181
182
|
result << inner(el, opts) << "\n"
|
182
183
|
end
|
183
184
|
|
184
|
-
HTML_TAGS_WITH_BODY=['div', 'script', 'iframe', 'textarea']
|
185
|
+
HTML_TAGS_WITH_BODY = ['div', 'script', 'iframe', 'textarea']
|
185
186
|
|
186
187
|
def convert_html_element(el, opts)
|
187
188
|
markdown_attr = el.options[:category] == :block && el.children.any? do |c|
|
188
|
-
c.type != :html_element && (c.type != :p || !c.options[:transparent]) &&
|
189
|
+
c.type != :html_element && (c.type != :p || !c.options[:transparent]) &&
|
190
|
+
Element.category(c) == :block
|
189
191
|
end
|
190
|
-
opts[:force_raw_text] = true if %w
|
191
|
-
opts[:raw_text] = opts[:force_raw_text] || opts[:block_raw_text] ||
|
192
|
+
opts[:force_raw_text] = true if %w[script pre code].include?(el.value)
|
193
|
+
opts[:raw_text] = opts[:force_raw_text] || opts[:block_raw_text] || \
|
194
|
+
(el.options[:category] != :span && !markdown_attr)
|
192
195
|
opts[:block_raw_text] = true if el.options[:category] == :block && opts[:raw_text]
|
193
196
|
res = inner(el, opts)
|
194
197
|
if el.options[:category] == :span
|
195
|
-
"<#{el.value}#{html_attributes(el.attr)}"
|
198
|
+
"<#{el.value}#{html_attributes(el.attr)}" + \
|
199
|
+
(!res.empty? || HTML_TAGS_WITH_BODY.include?(el.value) ? ">#{res}</#{el.value}>" : " />")
|
196
200
|
else
|
197
|
-
output = ''
|
201
|
+
output = +''
|
198
202
|
attr = el.attr.dup
|
199
203
|
attr['markdown'] = '1' if markdown_attr
|
200
204
|
output << "<#{el.value}#{html_attributes(attr)}"
|
201
205
|
if !res.empty? && el.options[:content_model] != :block
|
202
206
|
output << ">#{res}</#{el.value}>"
|
203
207
|
elsif !res.empty?
|
204
|
-
output << ">\n#{res}"
|
208
|
+
output << ">\n#{res}" << "</#{el.value}>"
|
205
209
|
elsif HTML_TAGS_WITH_BODY.include?(el.value)
|
206
210
|
output << "></#{el.value}>"
|
207
211
|
else
|
@@ -212,14 +216,15 @@ module Kramdown
|
|
212
216
|
end
|
213
217
|
end
|
214
218
|
|
215
|
-
def convert_xml_comment(el,
|
216
|
-
if el.options[:category] == :block &&
|
219
|
+
def convert_xml_comment(el, _opts)
|
220
|
+
if el.options[:category] == :block &&
|
221
|
+
(@stack.last.type != :html_element || @stack.last.options[:content_model] != :raw)
|
217
222
|
el.value + "\n"
|
218
223
|
else
|
219
224
|
el.value.dup
|
220
225
|
end
|
221
226
|
end
|
222
|
-
alias
|
227
|
+
alias convert_xml_pi convert_xml_comment
|
223
228
|
|
224
229
|
def convert_table(el, opts)
|
225
230
|
opts[:alignment] = el.options[:alignment]
|
@@ -228,10 +233,10 @@ module Kramdown
|
|
228
233
|
|
229
234
|
def convert_thead(el, opts)
|
230
235
|
rows = inner(el, opts)
|
231
|
-
if opts[:alignment].all? {|a| a == :default}
|
232
|
-
"#{rows}
|
236
|
+
if opts[:alignment].all? {|a| a == :default }
|
237
|
+
"#{rows}|#{'-' * 10}\n"
|
233
238
|
else
|
234
|
-
"#{rows}| "
|
239
|
+
"#{rows}| " + opts[:alignment].map do |a|
|
235
240
|
case a
|
236
241
|
when :left then ":-"
|
237
242
|
when :right then "-:"
|
@@ -243,25 +248,25 @@ module Kramdown
|
|
243
248
|
end
|
244
249
|
|
245
250
|
def convert_tbody(el, opts)
|
246
|
-
res = ''
|
251
|
+
res = +''
|
247
252
|
res << inner(el, opts)
|
248
|
-
res << '|' << '-'*10 << "\n" if opts[:next] && opts[:next].type == :tbody
|
253
|
+
res << '|' << '-' * 10 << "\n" if opts[:next] && opts[:next].type == :tbody
|
249
254
|
res
|
250
255
|
end
|
251
256
|
|
252
257
|
def convert_tfoot(el, opts)
|
253
|
-
"
|
258
|
+
"|#{'=' * 10}\n#{inner(el, opts)}"
|
254
259
|
end
|
255
260
|
|
256
261
|
def convert_tr(el, opts)
|
257
|
-
"|
|
262
|
+
"| #{el.children.map {|c| convert(c, opts) }.join(' | ')} |\n"
|
258
263
|
end
|
259
264
|
|
260
265
|
def convert_td(el, opts)
|
261
266
|
inner(el, opts)
|
262
267
|
end
|
263
268
|
|
264
|
-
def convert_comment(el,
|
269
|
+
def convert_comment(el, _opts)
|
265
270
|
if el.options[:category] == :block
|
266
271
|
"{::comment}\n#{el.value}\n{:/}\n"
|
267
272
|
else
|
@@ -269,7 +274,7 @@ module Kramdown
|
|
269
274
|
end
|
270
275
|
end
|
271
276
|
|
272
|
-
def convert_br(
|
277
|
+
def convert_br(_el, _opts)
|
273
278
|
" \n"
|
274
279
|
end
|
275
280
|
|
@@ -277,7 +282,7 @@ module Kramdown
|
|
277
282
|
if el.attr['href'].empty?
|
278
283
|
"[#{inner(el, opts)}]()"
|
279
284
|
elsif el.attr['href'] =~ /^(?:http|ftp)/ || el.attr['href'].count("()") > 0
|
280
|
-
index = if link_el = @linkrefs.find {|c| c.attr['href'] == el.attr['href']}
|
285
|
+
index = if (link_el = @linkrefs.find {|c| c.attr['href'] == el.attr['href'] })
|
281
286
|
@linkrefs.index(link_el) + 1
|
282
287
|
else
|
283
288
|
@linkrefs << el
|
@@ -290,7 +295,7 @@ module Kramdown
|
|
290
295
|
end
|
291
296
|
end
|
292
297
|
|
293
|
-
def convert_img(el,
|
298
|
+
def convert_img(el, _opts)
|
294
299
|
alt_text = el.attr['alt'].to_s.gsub(ESCAPED_CHAR_RE) { $1 ? "\\#{$1}" : $2 }
|
295
300
|
src = el.attr['src'].to_s
|
296
301
|
if src.empty?
|
@@ -306,19 +311,19 @@ module Kramdown
|
|
306
311
|
end
|
307
312
|
end
|
308
313
|
|
309
|
-
def convert_codespan(el,
|
314
|
+
def convert_codespan(el, _opts)
|
310
315
|
delim = (el.value.scan(/`+/).max || '') + '`'
|
311
316
|
"#{delim}#{' ' if delim.size > 1}#{el.value}#{' ' if delim.size > 1}#{delim}"
|
312
317
|
end
|
313
318
|
|
314
|
-
def convert_footnote(el,
|
319
|
+
def convert_footnote(el, _opts)
|
315
320
|
@footnotes << [el.options[:name], el.value]
|
316
321
|
"[^#{el.options[:name]}]"
|
317
322
|
end
|
318
323
|
|
319
|
-
def convert_raw(el,
|
324
|
+
def convert_raw(el, _opts)
|
320
325
|
attr = (el.options[:type] || []).join(' ')
|
321
|
-
attr = " type=\"#{attr}\""
|
326
|
+
attr = " type=\"#{attr}\"" unless attr.empty?
|
322
327
|
if @stack.last.type == :html_element
|
323
328
|
el.value
|
324
329
|
elsif el.options[:category] == :block
|
@@ -338,28 +343,28 @@ module Kramdown
|
|
338
343
|
(opts[:next] && [:em, :strong].include?(opts[:next].type) && !ial_for_element(el) ? '{::}' : '')
|
339
344
|
end
|
340
345
|
|
341
|
-
def convert_entity(el,
|
346
|
+
def convert_entity(el, _opts)
|
342
347
|
entity_to_str(el.value, el.options[:original])
|
343
348
|
end
|
344
349
|
|
345
350
|
TYPOGRAPHIC_SYMS = {
|
346
|
-
:
|
347
|
-
:
|
348
|
-
:
|
351
|
+
mdash: '---', ndash: '--', hellip: '...',
|
352
|
+
laquo_space: '<< ', raquo_space: ' >>',
|
353
|
+
laquo: '<<', raquo: '>>'
|
349
354
|
}
|
350
|
-
def convert_typographic_sym(el,
|
355
|
+
def convert_typographic_sym(el, _opts)
|
351
356
|
TYPOGRAPHIC_SYMS[el.value]
|
352
357
|
end
|
353
358
|
|
354
|
-
def convert_smart_quote(el,
|
359
|
+
def convert_smart_quote(el, _opts)
|
355
360
|
el.value.to_s =~ /[rl]dquo/ ? "\"" : "'"
|
356
361
|
end
|
357
362
|
|
358
|
-
def convert_math(el,
|
363
|
+
def convert_math(el, _opts)
|
359
364
|
"$$#{el.value}$$" + (el.options[:category] == :block ? "\n" : '')
|
360
365
|
end
|
361
366
|
|
362
|
-
def convert_abbreviation(el,
|
367
|
+
def convert_abbreviation(el, _opts)
|
363
368
|
el.value
|
364
369
|
end
|
365
370
|
|
@@ -372,27 +377,27 @@ module Kramdown
|
|
372
377
|
end
|
373
378
|
|
374
379
|
def create_link_defs
|
375
|
-
res = ''
|
376
|
-
res << "\n\n"
|
380
|
+
res = +''
|
381
|
+
res << "\n\n" unless @linkrefs.empty?
|
377
382
|
@linkrefs.each_with_index do |el, i|
|
378
383
|
title = parse_title(el.attr['title'])
|
379
|
-
res << "[#{i+1}]: #{el.attr['href']}#{title}\n"
|
384
|
+
res << "[#{i + 1}]: #{el.attr['href']}#{title}\n"
|
380
385
|
end
|
381
386
|
res
|
382
387
|
end
|
383
388
|
|
384
389
|
def create_footnote_defs
|
385
|
-
res = ''
|
390
|
+
res = +''
|
386
391
|
@footnotes.each do |name, data|
|
387
392
|
res << "[^#{name}]:\n"
|
388
|
-
res << inner(data).chomp.split(/\n/).map {|l| " #{l}"}.join("\n") + "\n\n"
|
393
|
+
res << inner(data).chomp.split(/\n/).map {|l| " #{l}" }.join("\n") + "\n\n"
|
389
394
|
end
|
390
395
|
res
|
391
396
|
end
|
392
397
|
|
393
398
|
def create_abbrev_defs
|
394
399
|
return '' unless @root.options[:abbrev_defs]
|
395
|
-
res = ''
|
400
|
+
res = +''
|
396
401
|
@root.options[:abbrev_defs].each do |name, text|
|
397
402
|
res << "*[#{name}]: #{text}\n"
|
398
403
|
res << ial_for_element(Element.new(:unused, nil, @root.options[:abbrev_attr][name])).to_s << "\n\n"
|
@@ -402,25 +407,25 @@ module Kramdown
|
|
402
407
|
|
403
408
|
# Return the IAL containing the attributes of the element +el+.
|
404
409
|
def ial_for_element(el)
|
405
|
-
res = el.attr.map do |k,v|
|
410
|
+
res = el.attr.map do |k, v|
|
406
411
|
next if [:img, :a].include?(el.type) && ['href', 'src', 'alt', 'title'].include?(k)
|
407
412
|
next if el.type == :header && k == 'id' && !v.strip.empty?
|
408
413
|
if v.nil?
|
409
414
|
''
|
410
415
|
elsif k == 'class' && !v.empty? && !v.index(/[\.#]/)
|
411
|
-
" " + v.split(/\s+/).map {|w| ".#{w}"}.join(" ")
|
416
|
+
" " + v.split(/\s+/).map {|w| ".#{w}" }.join(" ")
|
412
417
|
elsif k == 'id' && !v.strip.empty?
|
413
418
|
" ##{v}"
|
414
419
|
else
|
415
|
-
" #{k}=\"#{v
|
420
|
+
" #{k}=\"#{v}\""
|
416
421
|
end
|
417
422
|
end.compact.join('')
|
418
|
-
res = "toc"
|
423
|
+
res = "toc" + (res.strip.empty? ? '' : " #{res}") if (el.type == :ul || el.type == :ol) &&
|
419
424
|
(el.options[:ial][:refs].include?('toc') rescue nil)
|
420
|
-
res = "footnotes"
|
425
|
+
res = "footnotes" + (res.strip.empty? ? '' : " #{res}") if (el.type == :ul || el.type == :ol) &&
|
421
426
|
(el.options[:ial][:refs].include?('footnotes') rescue nil)
|
422
427
|
if el.type == :dl && el.options[:ial] && el.options[:ial][:refs]
|
423
|
-
auto_ids = el.options[:ial][:refs].select {|ref| ref
|
428
|
+
auto_ids = el.options[:ial][:refs].select {|ref| ref.start_with?('auto_ids') }.join(" ")
|
424
429
|
res = auto_ids << (res.strip.empty? ? '' : " #{res}") unless auto_ids.empty?
|
425
430
|
end
|
426
431
|
res.strip.empty? ? nil : "{:#{res}}"
|
@@ -1,7 +1,7 @@
|
|
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
6
|
# This file is part of kramdown which is licensed under the MIT.
|
7
7
|
#++
|
@@ -44,8 +44,8 @@ module Kramdown
|
|
44
44
|
|
45
45
|
# Return the converted content of the children of +el+ as a string.
|
46
46
|
def inner(el, opts)
|
47
|
-
result = ''
|
48
|
-
options = opts.dup.merge(:
|
47
|
+
result = +''
|
48
|
+
options = opts.dup.merge(parent: el)
|
49
49
|
el.children.each_with_index do |inner_el, index|
|
50
50
|
options[:index] = index
|
51
51
|
options[:result] = result
|
@@ -58,16 +58,17 @@ module Kramdown
|
|
58
58
|
inner(el, opts)
|
59
59
|
end
|
60
60
|
|
61
|
-
def convert_blank(
|
61
|
+
def convert_blank(_el, opts)
|
62
62
|
opts[:result] =~ /\n\n\Z|\A\Z/ ? "" : "\n"
|
63
63
|
end
|
64
64
|
|
65
|
-
def convert_text(el,
|
65
|
+
def convert_text(el, _opts)
|
66
66
|
escape(el.value)
|
67
67
|
end
|
68
68
|
|
69
69
|
def convert_p(el, opts)
|
70
|
-
if el.children.size == 1 && el.children.first.type == :img &&
|
70
|
+
if el.children.size == 1 && el.children.first.type == :img &&
|
71
|
+
!(img = convert_img(el.children.first, opts)).empty?
|
71
72
|
convert_standalone_image(el, opts, img)
|
72
73
|
else
|
73
74
|
"#{latex_link_target(el)}#{inner(el, opts)}\n\n"
|
@@ -76,12 +77,14 @@ module Kramdown
|
|
76
77
|
|
77
78
|
# Helper method used by +convert_p+ to convert a paragraph that only contains a single :img
|
78
79
|
# element.
|
79
|
-
def convert_standalone_image(el,
|
80
|
+
def convert_standalone_image(el, _opts, img)
|
80
81
|
attrs = attribute_list(el)
|
81
|
-
"\\begin{figure}#{attrs}\n\\begin{center}\n#{img}\n\\end{center}\n
|
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"
|
82
85
|
end
|
83
86
|
|
84
|
-
def convert_codeblock(el,
|
87
|
+
def convert_codeblock(el, _opts)
|
85
88
|
show_whitespace = el.attr['class'].to_s =~ /\bshow-whitespaces\b/
|
86
89
|
lang = extract_code_language(el.attr)
|
87
90
|
|
@@ -91,13 +94,14 @@ module Kramdown
|
|
91
94
|
"#{latex_link_target(el)}#{highlighted_code}\n"
|
92
95
|
elsif show_whitespace || lang
|
93
96
|
options = []
|
94
|
-
options <<
|
97
|
+
options << (show_whitespace ? "showspaces=true,showtabs=true" : "showspaces=false,showtabs=false")
|
95
98
|
options << "language=#{lang}" if lang
|
96
99
|
options << "basicstyle=\\ttfamily\\footnotesize,columns=fixed,frame=tlbr"
|
97
100
|
id = el.attr['id']
|
98
101
|
options << "label=#{id}" if id
|
99
102
|
attrs = attribute_list(el)
|
100
|
-
"#{latex_link_target(el)}\\begin{lstlisting}[#{options.join(',')}]\n
|
103
|
+
"#{latex_link_target(el)}\\begin{lstlisting}[#{options.join(',')}]\n" \
|
104
|
+
"#{el.value}\n\\end{lstlisting}#{attrs}\n"
|
101
105
|
else
|
102
106
|
"#{latex_link_target(el)}\\begin{verbatim}#{el.value}\\end{verbatim}\n"
|
103
107
|
end
|
@@ -117,7 +121,7 @@ module Kramdown
|
|
117
121
|
end
|
118
122
|
end
|
119
123
|
|
120
|
-
def convert_hr(el,
|
124
|
+
def convert_hr(el, _opts)
|
121
125
|
attrs = attribute_list(el)
|
122
126
|
"#{latex_link_target(el)}\\begin{center}#{attrs}\n\\rule{3in}{0.4pt}\n\\end{center}#{attrs}\n"
|
123
127
|
end
|
@@ -130,7 +134,7 @@ module Kramdown
|
|
130
134
|
latex_environment(el.type == :ul ? 'itemize' : 'enumerate', el, inner(el, opts))
|
131
135
|
end
|
132
136
|
end
|
133
|
-
alias
|
137
|
+
alias convert_ol convert_ul
|
134
138
|
|
135
139
|
def convert_dl(el, opts)
|
136
140
|
latex_environment('description', el, inner(el, opts))
|
@@ -159,22 +163,23 @@ module Kramdown
|
|
159
163
|
end
|
160
164
|
end
|
161
165
|
|
162
|
-
def convert_xml_comment(el,
|
163
|
-
el.value.split(/\n/).map {|l| "% #{l}"}.join("\n") + "\n"
|
166
|
+
def convert_xml_comment(el, _opts)
|
167
|
+
el.value.split(/\n/).map {|l| "% #{l}" }.join("\n") + "\n"
|
164
168
|
end
|
165
169
|
|
166
|
-
def convert_xml_pi(
|
170
|
+
def convert_xml_pi(_el, _opts)
|
167
171
|
warning("Can't convert XML PI")
|
168
172
|
''
|
169
173
|
end
|
170
174
|
|
171
|
-
TABLE_ALIGNMENT_CHAR = {:
|
175
|
+
TABLE_ALIGNMENT_CHAR = {default: 'l', left: 'l', center: 'c', right: 'r'} # :nodoc:
|
172
176
|
|
173
177
|
def convert_table(el, opts)
|
174
178
|
@data[:packages] << 'longtable'
|
175
|
-
align = el.options[:alignment].map {|a| TABLE_ALIGNMENT_CHAR[a]}.join('|')
|
179
|
+
align = el.options[:alignment].map {|a| TABLE_ALIGNMENT_CHAR[a] }.join('|')
|
176
180
|
attrs = attribute_list(el)
|
177
|
-
"#{latex_link_target(el)}\\begin{longtable}{|#{align}|}#{attrs}\n
|
181
|
+
"#{latex_link_target(el)}\\begin{longtable}{|#{align}|}#{attrs}\n" \
|
182
|
+
"\\hline\n#{inner(el, opts)}\\hline\n\\end{longtable}#{attrs}\n\n"
|
178
183
|
end
|
179
184
|
|
180
185
|
def convert_thead(el, opts)
|
@@ -190,33 +195,34 @@ module Kramdown
|
|
190
195
|
end
|
191
196
|
|
192
197
|
def convert_tr(el, opts)
|
193
|
-
el.children.map {|c| send("convert_#{c.type}", c, opts)}.join(' & ') << "\\\\\n"
|
198
|
+
el.children.map {|c| send("convert_#{c.type}", c, opts) }.join(' & ') << "\\\\\n"
|
194
199
|
end
|
195
200
|
|
196
201
|
def convert_td(el, opts)
|
197
202
|
inner(el, opts)
|
198
203
|
end
|
199
204
|
|
200
|
-
def convert_comment(el,
|
201
|
-
el.value.split(/\n/).map {|l| "% #{l}"}.join("\n") << "\n"
|
205
|
+
def convert_comment(el, _opts)
|
206
|
+
el.value.split(/\n/).map {|l| "% #{l}" }.join("\n") << "\n"
|
202
207
|
end
|
203
208
|
|
204
|
-
def convert_br(
|
205
|
-
res = "\\newline"
|
206
|
-
res << "\n" if (c = opts[:parent].children[opts[:index]+1]) &&
|
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/)
|
207
213
|
res
|
208
214
|
end
|
209
215
|
|
210
216
|
def convert_a(el, opts)
|
211
217
|
url = el.attr['href']
|
212
218
|
if url.start_with?('#')
|
213
|
-
"\\hyperlink{#{url[1..-1].gsub('%',
|
219
|
+
"\\hyperlink{#{url[1..-1].gsub('%', '\\%')}}{#{inner(el, opts)}}"
|
214
220
|
else
|
215
|
-
"\\href{#{url.gsub('%',
|
221
|
+
"\\href{#{url.gsub('%', '\\%')}}{#{inner(el, opts)}}"
|
216
222
|
end
|
217
223
|
end
|
218
224
|
|
219
|
-
def convert_img(el,
|
225
|
+
def convert_img(el, _opts)
|
220
226
|
line = el.options[:location]
|
221
227
|
if el.attr['src'] =~ /^(https?|ftps?):\/\//
|
222
228
|
warning("Cannot include non-local image#{line ? " (line #{line})" : ''}")
|
@@ -230,7 +236,7 @@ module Kramdown
|
|
230
236
|
end
|
231
237
|
end
|
232
238
|
|
233
|
-
def convert_codespan(el,
|
239
|
+
def convert_codespan(el, _opts)
|
234
240
|
lang = extract_code_language(el.attr)
|
235
241
|
if @options[:syntax_highlighter] == :minted &&
|
236
242
|
(highlighted_code = highlight_code(el.value, lang, :span))
|
@@ -246,7 +252,7 @@ module Kramdown
|
|
246
252
|
"\\footnote{#{inner(el.value, opts).rstrip}}"
|
247
253
|
end
|
248
254
|
|
249
|
-
def convert_raw(el,
|
255
|
+
def convert_raw(el, _opts)
|
250
256
|
if !el.options[:type] || el.options[:type].empty? || el.options[:type].include?('latex')
|
251
257
|
el.value + (el.options[:category] == :block ? "\n" : '')
|
252
258
|
else
|
@@ -511,7 +517,7 @@ module Kramdown
|
|
511
517
|
8194 => ['\hskip .5em\relax'],
|
512
518
|
8195 => ['\quad'],
|
513
519
|
} # :nodoc:
|
514
|
-
ENTITY_CONV_TABLE.
|
520
|
+
ENTITY_CONV_TABLE.each_value {|v| v[0] = "{}#{v[0]}" }
|
515
521
|
|
516
522
|
def entity_to_latex(entity)
|
517
523
|
text, package = ENTITY_CONV_TABLE[entity.code_point]
|
@@ -524,16 +530,16 @@ module Kramdown
|
|
524
530
|
end
|
525
531
|
end
|
526
532
|
|
527
|
-
def convert_entity(el,
|
533
|
+
def convert_entity(el, _opts)
|
528
534
|
entity_to_latex(el.value)
|
529
535
|
end
|
530
536
|
|
531
537
|
TYPOGRAPHIC_SYMS = {
|
532
|
-
:
|
533
|
-
:
|
534
|
-
:
|
538
|
+
mdash: '---', ndash: '--', hellip: '\ldots{}',
|
539
|
+
laquo_space: '\guillemotleft{}~', raquo_space: '~\guillemotright{}',
|
540
|
+
laquo: '\guillemotleft{}', raquo: '\guillemotright{}'
|
535
541
|
} # :nodoc:
|
536
|
-
def convert_typographic_sym(el,
|
542
|
+
def convert_typographic_sym(el, _opts)
|
537
543
|
if (result = @options[:typographic_symbols][el.value])
|
538
544
|
escape(result)
|
539
545
|
else
|
@@ -543,11 +549,11 @@ module Kramdown
|
|
543
549
|
|
544
550
|
def convert_smart_quote(el, opts)
|
545
551
|
res = entity_to_latex(smart_quote_entity(el)).chomp('{}')
|
546
|
-
res << "{}" if ((nel = opts[:parent].children[opts[:index]+1]) && nel.type == :smart_quote) || res =~ /\w$/
|
552
|
+
res << "{}" if ((nel = opts[:parent].children[opts[:index] + 1]) && nel.type == :smart_quote) || res =~ /\w$/
|
547
553
|
res
|
548
554
|
end
|
549
555
|
|
550
|
-
def convert_math(el,
|
556
|
+
def convert_math(el, _opts)
|
551
557
|
@data[:packages] += %w[amssymb amsmath amsthm amsfonts]
|
552
558
|
if el.options[:category] == :block
|
553
559
|
if el.value =~ /\A\s*\\begin\{/
|
@@ -560,14 +566,14 @@ module Kramdown
|
|
560
566
|
end
|
561
567
|
end
|
562
568
|
|
563
|
-
def convert_abbreviation(el,
|
569
|
+
def convert_abbreviation(el, _opts)
|
564
570
|
@data[:packages] += %w[acronym]
|
565
571
|
"\\ac{#{normalize_abbreviation_key(el.value)}}"
|
566
572
|
end
|
567
573
|
|
568
574
|
# Normalize the abbreviation key so that it only contains allowed ASCII character
|
569
575
|
def normalize_abbreviation_key(key)
|
570
|
-
key.gsub(/\W/) {|m| m.unpack('H*').first}
|
576
|
+
key.gsub(/\W/) {|m| m.unpack('H*').first }
|
571
577
|
end
|
572
578
|
|
573
579
|
# Wrap the +text+ inside a LaTeX environment of type +type+. The element +el+ is passed on to
|
@@ -583,7 +589,7 @@ module Kramdown
|
|
583
589
|
# additionally to the \hypertarget command.
|
584
590
|
def latex_link_target(el, add_label = false)
|
585
591
|
if (id = el.attr['id'])
|
586
|
-
"\\hypertarget{#{id}}{}
|
592
|
+
"\\hypertarget{#{id}}{}#{add_label ? "\\label{#{id}}" : ''}"
|
587
593
|
else
|
588
594
|
nil
|
589
595
|
end
|
@@ -591,8 +597,8 @@ module Kramdown
|
|
591
597
|
|
592
598
|
# Return a LaTeX comment containing all attributes as 'key="value"' pairs.
|
593
599
|
def attribute_list(el)
|
594
|
-
attrs = el.attr.map {|k,v| v.nil? ? '' : " #{k}=\"#{v
|
595
|
-
attrs = " % #{attrs}"
|
600
|
+
attrs = el.attr.map {|k, v| v.nil? ? '' : " #{k}=\"#{v}\"" }.compact.sort.join('')
|
601
|
+
attrs = " % #{attrs}" unless attrs.empty?
|
596
602
|
attrs
|
597
603
|
end
|
598
604
|
|
@@ -605,12 +611,12 @@ module Kramdown
|
|
605
611
|
">" => "\\textgreater{}",
|
606
612
|
"[" => "{[}",
|
607
613
|
"]" => "{]}",
|
608
|
-
}.merge(Hash[*("{}$%&_#".
|
609
|
-
ESCAPE_RE = Regexp.union(*ESCAPE_MAP.collect {|k,
|
614
|
+
}.merge(Hash[*("{}$%&_#".each_char.map {|c| [c, "\\#{c}"] }.flatten)]) # :nodoc:
|
615
|
+
ESCAPE_RE = Regexp.union(*ESCAPE_MAP.collect {|k, _v| k }) # :nodoc:
|
610
616
|
|
611
617
|
# Escape the special LaTeX characters in the string +str+.
|
612
618
|
def escape(str)
|
613
|
-
str.gsub(ESCAPE_RE) {|m| ESCAPE_MAP[m]}
|
619
|
+
str.gsub(ESCAPE_RE) {|m| ESCAPE_MAP[m] }
|
614
620
|
end
|
615
621
|
|
616
622
|
end
|