motion-kramdown 0.6.0 → 1.16.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +6 -2
- data/lib/kramdown.rb +1 -1
- data/lib/kramdown/converter.rb +10 -11
- data/lib/kramdown/converter/base.rb +19 -12
- data/lib/kramdown/converter/hash_ast.rb +38 -0
- data/lib/kramdown/converter/html.rb +71 -39
- data/lib/kramdown/converter/kramdown.rb +19 -10
- data/lib/kramdown/converter/latex.rb +28 -10
- data/lib/kramdown/converter/man.rb +303 -0
- data/lib/kramdown/converter/math_engine/itex2mml.rb +2 -2
- data/lib/kramdown/converter/math_engine/mathjax.rb +13 -3
- data/lib/kramdown/converter/math_engine/mathjaxnode.rb +56 -0
- data/lib/kramdown/converter/math_engine/ritex.rb +2 -2
- data/lib/kramdown/converter/math_engine/sskatex.rb +97 -0
- data/lib/kramdown/converter/pdf.rb +6 -6
- data/lib/kramdown/converter/remove_html_tags.rb +5 -3
- data/lib/kramdown/converter/syntax_highlighter.rb +5 -2
- data/lib/kramdown/converter/syntax_highlighter/coderay.rb +8 -5
- data/lib/kramdown/converter/syntax_highlighter/minted.rb +35 -0
- data/lib/kramdown/converter/syntax_highlighter/rouge.rb +48 -10
- data/lib/kramdown/converter/toc.rb +2 -2
- data/lib/kramdown/document.rb +16 -19
- data/lib/kramdown/element.rb +5 -1
- data/lib/kramdown/error.rb +1 -1
- data/lib/kramdown/options.rb +103 -7
- data/lib/kramdown/parser.rb +1 -1
- data/lib/kramdown/parser/base.rb +12 -18
- data/lib/kramdown/parser/gfm.rb +142 -11
- data/lib/kramdown/parser/html.rb +28 -18
- data/lib/kramdown/parser/kramdown.rb +45 -36
- data/lib/kramdown/parser/kramdown/abbreviation.rb +1 -1
- data/lib/kramdown/parser/kramdown/autolink.rb +2 -8
- data/lib/kramdown/parser/kramdown/blank_line.rb +2 -2
- data/lib/kramdown/parser/kramdown/block_boundary.rb +4 -4
- data/lib/kramdown/parser/kramdown/blockquote.rb +4 -4
- data/lib/kramdown/parser/kramdown/codeblock.rb +11 -8
- data/lib/kramdown/parser/kramdown/codespan.rb +1 -1
- data/lib/kramdown/parser/kramdown/emphasis.rb +2 -2
- 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 +6 -3
- data/lib/kramdown/parser/kramdown/footnote.rb +4 -5
- data/lib/kramdown/parser/kramdown/header.rb +2 -2
- data/lib/kramdown/parser/kramdown/horizontal_rule.rb +1 -1
- data/lib/kramdown/parser/kramdown/html.rb +8 -8
- data/lib/kramdown/parser/kramdown/html_entity.rb +2 -2
- data/lib/kramdown/parser/kramdown/line_break.rb +1 -1
- data/lib/kramdown/parser/kramdown/link.rb +5 -4
- data/lib/kramdown/parser/kramdown/list.rb +17 -10
- data/lib/kramdown/parser/kramdown/math.rb +2 -2
- data/lib/kramdown/parser/kramdown/paragraph.rb +19 -8
- data/lib/kramdown/parser/kramdown/smart_quotes.rb +3 -3
- data/lib/kramdown/parser/kramdown/table.rb +10 -12
- data/lib/kramdown/parser/kramdown/typographic_symbol.rb +1 -1
- data/lib/kramdown/parser/markdown.rb +2 -2
- data/lib/kramdown/utils.rb +2 -1
- data/lib/kramdown/utils/configurable.rb +2 -2
- data/lib/kramdown/utils/entities.rb +1 -1
- data/lib/kramdown/utils/html.rb +2 -2
- data/lib/kramdown/utils/lru_cache.rb +40 -0
- data/lib/kramdown/utils/ordered_hash.rb +2 -71
- data/lib/kramdown/utils/string_scanner.rb +2 -2
- data/lib/kramdown/utils/unidecoder.rb +2 -2
- data/lib/kramdown/version.rb +2 -2
- data/lib/rubymotion/require_override.rb +9 -0
- data/lib/rubymotion/version.rb +1 -1
- data/spec/{helpers → motion-kramdown/_helpers}/it_behaves_like.rb +0 -0
- data/spec/{helpers → motion-kramdown/_helpers}/option_file.rb +2 -2
- data/spec/{helpers → motion-kramdown/_helpers}/tidy.rb +0 -0
- data/spec/motion-kramdown/bench_mark.rb +37 -0
- data/spec/{document_tree.rb → motion-kramdown/document_tree.rb} +11 -1
- data/spec/{gfm_to_html.rb → motion-kramdown/gfm_to_html.rb} +51 -18
- data/spec/{html_to_html.rb → motion-kramdown/html_to_html.rb} +27 -9
- data/spec/{html_to_kramdown_to_html.rb → motion-kramdown/html_to_kramdown_to_html.rb} +35 -16
- data/spec/motion-kramdown/kramdown_to_xxx.rb +75 -0
- data/spec/{test_location.rb → motion-kramdown/test_location.rb} +0 -0
- data/spec/{test_string_scanner_kramdown.rb → motion-kramdown/test_string_scanner_kramdown.rb} +0 -0
- data/spec/motion-kramdown/text_manpage.rb +11 -0
- data/spec/{text_to_kramdown_to_html.rb → motion-kramdown/text_to_kramdown_to_html.rb} +30 -19
- data/spec/{text_to_latex.rb → motion-kramdown/text_to_latex.rb} +0 -0
- data/spec/{helpers/spec_options.rb → spec_helper.rb} +13 -2
- metadata +54 -33
- data/lib/kramdown/compatibility.rb +0 -36
- data/spec/bench_mark.rb +0 -43
- data/spec/kramdown_to_xxx.rb +0 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 60142424142433a2b5ffdb6d598820aa55a3cb3e1f1f75aa5a9ce177b6ba41ba
|
4
|
+
data.tar.gz: 6c7371fbba67b2996585abbcdc1957d8e4600c3507055d58833265a17522ddb4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb1786361e980d753ac54bc88cbc206361f8d7486886bdd6f14fbb54eb04029ea9bf64fcce02328eb978490e5aba81957df6d3387d5259e72bdc6aec2bcf8537
|
7
|
+
data.tar.gz: d0c0d4212fda52d3e3faa7c8a98ddfda404894977d81375f41223bbe38324b313d4a6f88c6f769eda652f48135a2c25ccb51d68d5a24175a170b5444dc9618cf
|
data/README.md
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
# motion-kramdown
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/motion-kramdown.svg)](http://badge.fury.io/rb/motion-kramdown)
|
4
|
+
[![Build Status](https://travis-ci.org/digitalmoksha/motion-kramdown.svg?branch=master)](https://travis-ci.org/digitalmoksha/motion-kramdown)
|
5
|
+
[![Platform](https://img.shields.io/badge/platform-macos%20|%20ios-lightgrey.svg)](https://shields.io/)
|
6
|
+
[![Language](https://img.shields.io/badge/language-RubyMotion-red.svg)](http://www.rubymotion.com)
|
4
7
|
|
5
8
|
[kramdown](https://github.com/gettalong/kramdown) Markdown parser, for use with RubyMotion on iOS and OS X.
|
6
9
|
|
7
|
-
Currently implements: _kramdown_ 1.
|
10
|
+
Currently implements: _kramdown_ 1.16.2
|
8
11
|
|
9
12
|
## Introduction
|
10
13
|
|
@@ -83,4 +86,5 @@ All credit for _kramdown_ belongs to Thomas Leitner. _motion-kramdown_ is a sim
|
|
83
86
|
|
84
87
|
_motion-kramdown_ is released under the MIT license (see the **COPYING** file) and therefore can easily be used in commercial projects.
|
85
88
|
|
86
|
-
However, if you use _motion-kramdown_ in a commercial setting, please consider **contributing back any changes** for the benefit of the community and/or
|
89
|
+
However, if you use _motion-kramdown_ in a commercial setting, please consider **contributing back any changes** for the benefit of the community and/or
|
90
|
+
[**becoming a patron**](https://www.patreon.com/gettalong) - thanks!
|
data/lib/kramdown.rb
CHANGED
data/lib/kramdown/converter.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
3
|
#--
|
4
|
-
# Copyright (C) 2009-
|
4
|
+
# Copyright (C) 2009-2016 Thomas Leitner <t_leitner@gmx.at>
|
5
5
|
#
|
6
6
|
# This file is part of kramdown which is licensed under the MIT.
|
7
7
|
#++
|
8
8
|
#
|
9
9
|
|
10
|
-
|
10
|
+
require 'kramdown/utils'
|
11
11
|
|
12
12
|
module Kramdown
|
13
13
|
|
@@ -26,17 +26,19 @@ module Kramdown
|
|
26
26
|
# RM autoload :Toc, 'kramdown/converter/toc'
|
27
27
|
# RM autoload :RemoveHtmlTags, 'kramdown/converter/remove_html_tags'
|
28
28
|
# RM autoload :Pdf, 'kramdown/converter/pdf'
|
29
|
+
# RM autoload :HashAST, 'kramdown/converter/hash_ast'
|
30
|
+
# RM autoload :Man, 'kramdown/converter/man'
|
29
31
|
|
30
32
|
extend ::Kramdown::Utils::Configurable
|
31
33
|
|
32
34
|
configurable(:syntax_highlighter)
|
33
35
|
|
34
|
-
# RM ["Coderay", "Rouge"].each do |klass_name|
|
36
|
+
# RM ["Minted", "Coderay", "Rouge"].each do |klass_name|
|
35
37
|
# RM kn_down = klass_name.downcase.intern
|
36
38
|
# RM add_syntax_highlighter(kn_down) do |converter, text, lang, type, opts|
|
37
39
|
# RM require "kramdown/converter/syntax_highlighter/#{kn_down}"
|
38
40
|
# RM klass = ::Kramdown::Utils.deep_const_get("::Kramdown::Converter::SyntaxHighlighter::#{klass_name}")
|
39
|
-
# RM
|
41
|
+
# RM. if !klass.const_defined?(:AVAILABLE) || klass::AVAILABLE
|
40
42
|
# RM add_syntax_highlighter(kn_down, klass)
|
41
43
|
# RM else
|
42
44
|
# RM add_syntax_highlighter(kn_down) {|*args| nil}
|
@@ -44,18 +46,15 @@ module Kramdown
|
|
44
46
|
# RM syntax_highlighter(kn_down).call(converter, text, lang, type, opts)
|
45
47
|
# RM end
|
46
48
|
# RM end
|
47
|
-
# RM
|
49
|
+
# RM
|
48
50
|
# RM configurable(:math_engine)
|
49
|
-
# RM
|
50
|
-
# RM
|
51
|
-
# RM add_math_engine(:mathjax, ::Kramdown::Converter::MathEngine::Mathjax)
|
52
|
-
# RM
|
53
|
-
# RM ["Ritex", "Itex2MML"].each do |klass_name|
|
51
|
+
# RM
|
52
|
+
# RM ['Mathjax', "MathjaxNode", "SsKaTeX", "Ritex", "Itex2MML"].each do |klass_name|
|
54
53
|
# RM kn_down = klass_name.downcase.intern
|
55
54
|
# RM add_math_engine(kn_down) do |converter, el, opts|
|
56
55
|
# RM require "kramdown/converter/math_engine/#{kn_down}"
|
57
56
|
# RM klass = ::Kramdown::Utils.deep_const_get("::Kramdown::Converter::MathEngine::#{klass_name}")
|
58
|
-
# RM if klass::AVAILABLE
|
57
|
+
# RM if !klass.const_defined?(:AVAILABLE) || klass::AVAILABLE
|
59
58
|
# RM add_math_engine(kn_down, klass)
|
60
59
|
# RM else
|
61
60
|
# RM add_math_engine(kn_down) {|*args| nil}
|
@@ -1,15 +1,15 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
3
|
#--
|
4
|
-
# Copyright (C) 2009-
|
4
|
+
# Copyright (C) 2009-2016 Thomas Leitner <t_leitner@gmx.at>
|
5
5
|
#
|
6
6
|
# This file is part of kramdown which is licensed under the MIT.
|
7
7
|
#++
|
8
8
|
#
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
require 'erb'
|
11
|
+
require 'kramdown/utils'
|
12
|
+
require 'kramdown/document'
|
13
13
|
|
14
14
|
module Kramdown
|
15
15
|
|
@@ -67,7 +67,7 @@ module Kramdown
|
|
67
67
|
false
|
68
68
|
end
|
69
69
|
|
70
|
-
# Returns whether the template should be applied
|
70
|
+
# Returns whether the template should be applied after the conversion of the tree.
|
71
71
|
#
|
72
72
|
# Defaults to true.
|
73
73
|
def apply_template_after?
|
@@ -182,8 +182,8 @@ module Kramdown
|
|
182
182
|
|
183
183
|
# Extract the code block/span language from the attributes.
|
184
184
|
def extract_code_language(attr)
|
185
|
-
if attr['class'] && attr['class'] =~ /\blanguage-\
|
186
|
-
attr['class'].scan(/\blanguage-(\
|
185
|
+
if attr['class'] && attr['class'] =~ /\blanguage-\S+/
|
186
|
+
attr['class'].scan(/\blanguage-(\S+)/).first.first
|
187
187
|
end
|
188
188
|
end
|
189
189
|
|
@@ -192,7 +192,7 @@ module Kramdown
|
|
192
192
|
# *Warning*: This version will modify the given attributes if a language is present.
|
193
193
|
def extract_code_language!(attr)
|
194
194
|
lang = extract_code_language(attr)
|
195
|
-
attr['class'] = attr['class'].sub(/\blanguage-\
|
195
|
+
attr['class'] = attr['class'].sub(/\blanguage-\S+/, '').strip if lang
|
196
196
|
attr.delete('class') if lang && attr['class'].empty?
|
197
197
|
lang
|
198
198
|
end
|
@@ -231,10 +231,7 @@ module Kramdown
|
|
231
231
|
# ID.
|
232
232
|
def generate_id(str)
|
233
233
|
str = ::Kramdown::Utils::Unidecoder.decode(str) if @options[:transliterated_header_ids]
|
234
|
-
gen_id = str
|
235
|
-
gen_id.tr!('^a-zA-Z0-9 -', '')
|
236
|
-
gen_id.tr!(' ', '-')
|
237
|
-
gen_id.downcase!
|
234
|
+
gen_id = basic_generate_id(str)
|
238
235
|
gen_id = 'section' if gen_id.length == 0
|
239
236
|
@used_ids ||= {}
|
240
237
|
if @used_ids.has_key?(gen_id)
|
@@ -245,6 +242,16 @@ module Kramdown
|
|
245
242
|
@options[:auto_id_prefix] + gen_id
|
246
243
|
end
|
247
244
|
|
245
|
+
# The basic version of the ID generator, without any special provisions for empty or unique
|
246
|
+
# IDs.
|
247
|
+
def basic_generate_id(str)
|
248
|
+
gen_id = str.gsub(/^[^a-zA-Z]+/, '')
|
249
|
+
gen_id.tr!('^a-zA-Z0-9 -', '')
|
250
|
+
gen_id.tr!(' ', '-')
|
251
|
+
gen_id.downcase!
|
252
|
+
gen_id
|
253
|
+
end
|
254
|
+
|
248
255
|
SMART_QUOTE_INDICES = {:lsquo => 0, :rsquo => 1, :ldquo => 2, :rdquo => 3} # :nodoc:
|
249
256
|
|
250
257
|
# Return the entity that represents the given smart_quote element.
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
#--
|
4
|
+
# Copyright (C) 2009-2016 Thomas Leitner <t_leitner@gmx.at>
|
5
|
+
#
|
6
|
+
# This file is part of kramdown which is licensed under the MIT.
|
7
|
+
#++
|
8
|
+
#
|
9
|
+
|
10
|
+
require 'kramdown/parser'
|
11
|
+
require 'kramdown/converter'
|
12
|
+
require 'kramdown/utils'
|
13
|
+
|
14
|
+
module Kramdown
|
15
|
+
|
16
|
+
module Converter
|
17
|
+
|
18
|
+
# Converts a Kramdown::Document to a nested hash for further processing or debug output.
|
19
|
+
class HashAST < Base
|
20
|
+
|
21
|
+
def convert(el)
|
22
|
+
hash = {:type => el.type}
|
23
|
+
hash[:attr] = el.attr unless el.attr.empty?
|
24
|
+
hash[:value] = el.value unless el.value.nil?
|
25
|
+
hash[:options] = el.options unless el.options.empty?
|
26
|
+
unless el.children.empty?
|
27
|
+
hash[:children] = []
|
28
|
+
el.children.each {|child| hash[:children] << convert(child)}
|
29
|
+
end
|
30
|
+
hash
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
HashAst = HashAST
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -1,15 +1,15 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
3
|
#--
|
4
|
-
# Copyright (C) 2009-
|
4
|
+
# Copyright (C) 2009-2016 Thomas Leitner <t_leitner@gmx.at>
|
5
5
|
#
|
6
6
|
# This file is part of kramdown which is licensed under the MIT.
|
7
7
|
#++
|
8
8
|
#
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
require 'kramdown/parser'
|
11
|
+
require 'kramdown/converter'
|
12
|
+
require 'kramdown/utils'
|
13
13
|
|
14
14
|
module Kramdown
|
15
15
|
|
@@ -92,10 +92,11 @@ module Kramdown
|
|
92
92
|
def convert_codeblock(el, indent)
|
93
93
|
attr = el.attr.dup
|
94
94
|
lang = extract_code_language!(attr)
|
95
|
-
|
95
|
+
hl_opts = {}
|
96
|
+
highlighted_code = highlight_code(el.value, el.options[:lang] || lang, :block, hl_opts)
|
96
97
|
|
97
98
|
if highlighted_code
|
98
|
-
add_syntax_highlighter_to_class_attr(attr)
|
99
|
+
add_syntax_highlighter_to_class_attr(attr, lang || hl_opts[:default_lang])
|
99
100
|
"#{' '*indent}<div#{html_attributes(attr)}>#{highlighted_code}#{' '*indent}</div>\n"
|
100
101
|
else
|
101
102
|
result = escape_html(el.value)
|
@@ -164,7 +165,14 @@ module Kramdown
|
|
164
165
|
alias :convert_dd :convert_li
|
165
166
|
|
166
167
|
def convert_dt(el, indent)
|
167
|
-
|
168
|
+
attr = el.attr.dup
|
169
|
+
@stack.last.options[:ial][:refs].each do |ref|
|
170
|
+
if ref =~ /\Aauto_ids(?:-([\w-]+))?/
|
171
|
+
attr['id'] = ($1 ? $1 : '') << basic_generate_id(el.options[:raw_text])
|
172
|
+
break
|
173
|
+
end
|
174
|
+
end if !attr['id'] && @stack.last.options[:ial] && @stack.last.options[:ial][:refs]
|
175
|
+
format_as_block_html(el.type, attr, inner(el, indent), indent)
|
168
176
|
end
|
169
177
|
|
170
178
|
def convert_html_element(el, indent)
|
@@ -235,14 +243,7 @@ module Kramdown
|
|
235
243
|
end
|
236
244
|
|
237
245
|
def convert_a(el, indent)
|
238
|
-
|
239
|
-
attr = el.attr.dup
|
240
|
-
if attr['href'].start_with?('mailto:')
|
241
|
-
mail_addr = attr['href'][7..-1]
|
242
|
-
attr['href'] = obfuscate('mailto') << ":" << obfuscate(mail_addr)
|
243
|
-
res = obfuscate(res) if res == mail_addr
|
244
|
-
end
|
245
|
-
format_as_span_html(el.type, attr, res)
|
246
|
+
format_as_span_html(el.type, el.attr, inner(el, indent))
|
246
247
|
end
|
247
248
|
|
248
249
|
def convert_img(el, indent)
|
@@ -252,9 +253,10 @@ module Kramdown
|
|
252
253
|
def convert_codespan(el, indent)
|
253
254
|
attr = el.attr.dup
|
254
255
|
lang = extract_code_language(attr)
|
255
|
-
|
256
|
+
hl_opts = {}
|
257
|
+
result = highlight_code(el.value, lang, :span, hl_opts)
|
256
258
|
if result
|
257
|
-
add_syntax_highlighter_to_class_attr(attr)
|
259
|
+
add_syntax_highlighter_to_class_attr(attr, hl_opts[:default_lang])
|
258
260
|
else
|
259
261
|
result = escape_html(el.value)
|
260
262
|
end
|
@@ -303,7 +305,11 @@ module Kramdown
|
|
303
305
|
:raquo => [::Kramdown::Utils::Entities.entity('raquo')]
|
304
306
|
} # :nodoc:
|
305
307
|
def convert_typographic_sym(el, indent)
|
306
|
-
|
308
|
+
if (result = @options[:typographic_symbols][el.value])
|
309
|
+
escape_html(result, :text)
|
310
|
+
else
|
311
|
+
TYPOGRAPHIC_SYMS[el.value].map {|e| entity_to_str(e)}.join('')
|
312
|
+
end
|
307
313
|
end
|
308
314
|
|
309
315
|
def convert_smart_quote(el, indent)
|
@@ -313,10 +319,14 @@ module Kramdown
|
|
313
319
|
def convert_math(el, indent)
|
314
320
|
if (result = format_math(el, :indent => indent))
|
315
321
|
result
|
316
|
-
elsif el.options[:category] == :block
|
317
|
-
format_as_block_html('pre', el.attr, "$$\n#{el.value}\n$$", indent)
|
318
322
|
else
|
319
|
-
|
323
|
+
attr = el.attr.dup
|
324
|
+
(attr['class'] = (attr['class'] || '') << " kdmath").lstrip!
|
325
|
+
if el.options[:category] == :block
|
326
|
+
format_as_block_html('div', attr, "$$\n#{el.value}\n$$", indent)
|
327
|
+
else
|
328
|
+
format_as_span_html('span', attr, "$#{el.value}$")
|
329
|
+
end
|
320
330
|
end
|
321
331
|
end
|
322
332
|
|
@@ -330,7 +340,7 @@ module Kramdown
|
|
330
340
|
def convert_root(el, indent)
|
331
341
|
result = inner(el, indent)
|
332
342
|
if @footnote_location
|
333
|
-
result.sub!(/#{@footnote_location}/, footnote_content)
|
343
|
+
result.sub!(/#{@footnote_location}/, footnote_content.gsub(/\\/, "\\\\\\\\"))
|
334
344
|
else
|
335
345
|
result << footnote_content
|
336
346
|
end
|
@@ -341,7 +351,7 @@ module Kramdown
|
|
341
351
|
else
|
342
352
|
''
|
343
353
|
end
|
344
|
-
result.sub!(/#{@toc_code.last}/, text)
|
354
|
+
result.sub!(/#{@toc_code.last}/, text.gsub(/\\/, "\\\\\\\\"))
|
345
355
|
end
|
346
356
|
result
|
347
357
|
end
|
@@ -362,9 +372,11 @@ module Kramdown
|
|
362
372
|
"#{' '*indent}<#{name}#{html_attributes(attr)}>\n#{body}#{' '*indent}</#{name}>\n"
|
363
373
|
end
|
364
374
|
|
365
|
-
# Add the syntax highlighter name to the 'class' attribute of the given attribute hash.
|
366
|
-
|
375
|
+
# Add the syntax highlighter name to the 'class' attribute of the given attribute hash. And
|
376
|
+
# overwrites or add a "language-LANG" part using the +lang+ parameter if +lang+ is not nil.
|
377
|
+
def add_syntax_highlighter_to_class_attr(attr, lang = nil)
|
367
378
|
(attr['class'] = (attr['class'] || '') + " highlighter-#{@options[:syntax_highlighter]}").lstrip!
|
379
|
+
attr['class'].sub!(/\blanguage-\S+|(^)/) { "language-#{lang}#{$1 ? ' ' : ''}" } if lang
|
368
380
|
end
|
369
381
|
|
370
382
|
# Generate and return an element tree for the table of contents.
|
@@ -378,7 +390,7 @@ module Kramdown
|
|
378
390
|
a = Element.new(:a, nil)
|
379
391
|
a.attr['href'] = "##{id}"
|
380
392
|
a.attr['id'] = "#{sections.attr['id']}-#{id}"
|
381
|
-
a.children.concat(
|
393
|
+
a.children.concat(fix_for_toc_entry(Marshal.load(Marshal.dump(children))))
|
382
394
|
li.children.last.children << a
|
383
395
|
li.children << Element.new(type)
|
384
396
|
|
@@ -405,6 +417,21 @@ module Kramdown
|
|
405
417
|
sections
|
406
418
|
end
|
407
419
|
|
420
|
+
# Fixes the elements for use in a TOC entry.
|
421
|
+
def fix_for_toc_entry(elements)
|
422
|
+
remove_footnotes(elements)
|
423
|
+
unwrap_links(elements)
|
424
|
+
elements
|
425
|
+
end
|
426
|
+
|
427
|
+
# Remove all link elements by unwrapping them.
|
428
|
+
def unwrap_links(elements)
|
429
|
+
elements.map! do |c|
|
430
|
+
unwrap_links(c.children)
|
431
|
+
c.type == :a ? c.children : c
|
432
|
+
end.flatten!
|
433
|
+
end
|
434
|
+
|
408
435
|
# Remove all footnotes from the given elements.
|
409
436
|
def remove_footnotes(elements)
|
410
437
|
elements.delete_if do |c|
|
@@ -419,7 +446,7 @@ module Kramdown
|
|
419
446
|
text.each_byte do |b|
|
420
447
|
result << (b > 128 ? b.chr : "&#%03d;" % b)
|
421
448
|
end
|
422
|
-
result.force_encoding(text.encoding)
|
449
|
+
result.force_encoding(text.encoding)
|
423
450
|
result
|
424
451
|
end
|
425
452
|
|
@@ -430,28 +457,33 @@ module Kramdown
|
|
430
457
|
ol = Element.new(:ol)
|
431
458
|
ol.attr['start'] = @footnote_start if @footnote_start != 1
|
432
459
|
i = 0
|
460
|
+
backlink_text = escape_html(@options[:footnote_backlink], :text)
|
433
461
|
while i < @footnotes.length
|
434
462
|
name, data, _, repeat = *@footnotes[i]
|
435
463
|
li = Element.new(:li, nil, {'id' => "fn:#{name}"})
|
436
464
|
li.children = Marshal.load(Marshal.dump(data.children))
|
437
|
-
|
438
|
-
#------------------------------------------------------------------------------
|
439
|
-
# RM Crash due to an object being autoreleased one too many times in RubyMotion.
|
440
|
-
# pre-initializing `para` before it's assigned in the `if` statement seems to
|
441
|
-
# fix it.
|
442
|
-
para = nil
|
443
465
|
|
444
|
-
|
445
|
-
|
466
|
+
para = nil
|
467
|
+
if li.children.last.type == :p || @options[:footnote_backlink_inline]
|
468
|
+
parent = li
|
469
|
+
while !parent.children.empty? && ![:p, :header].include?(parent.children.last.type)
|
470
|
+
parent = parent.children.last
|
471
|
+
end
|
472
|
+
para = parent.children.last
|
446
473
|
insert_space = true
|
447
|
-
|
474
|
+
end
|
475
|
+
|
476
|
+
unless para
|
448
477
|
li.children << (para = Element.new(:p))
|
449
478
|
insert_space = false
|
450
479
|
end
|
451
480
|
|
452
|
-
|
453
|
-
|
454
|
-
para.children << Element.new(:raw, FOOTNOTE_BACKLINK_FMT % [
|
481
|
+
unless @options[:footnote_backlink].empty?
|
482
|
+
nbsp = entity_to_str(ENTITY_NBSP)
|
483
|
+
para.children << Element.new(:raw, FOOTNOTE_BACKLINK_FMT % [insert_space ? nbsp : '', name, backlink_text])
|
484
|
+
(1..repeat).each do |index|
|
485
|
+
para.children << Element.new(:raw, FOOTNOTE_BACKLINK_FMT % [nbsp, "#{name}:#{index}", "#{backlink_text}<sup>#{index+1}</sup>"])
|
486
|
+
end
|
455
487
|
end
|
456
488
|
|
457
489
|
ol.children << Element.new(:raw, convert(li, 4))
|
@@ -1,14 +1,14 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
3
|
#--
|
4
|
-
# Copyright (C) 2009-
|
4
|
+
# Copyright (C) 2009-2016 Thomas Leitner <t_leitner@gmx.at>
|
5
5
|
#
|
6
6
|
# This file is part of kramdown which is licensed under the MIT.
|
7
7
|
#++
|
8
8
|
#
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
require 'kramdown/converter'
|
11
|
+
require 'kramdown/utils'
|
12
12
|
|
13
13
|
module Kramdown
|
14
14
|
|
@@ -31,7 +31,7 @@ module Kramdown
|
|
31
31
|
|
32
32
|
def convert(el, opts = {:indent => 0})
|
33
33
|
res = send("convert_#{el.type}", el, opts)
|
34
|
-
if ![:html_element, :li, :dd, :td].include?(el.type) && (ial = ial_for_element(el))
|
34
|
+
if ![:html_element, :li, :dt, :dd, :td].include?(el.type) && (ial = ial_for_element(el))
|
35
35
|
res << ial
|
36
36
|
res << "\n\n" if Element.category(el) == :block
|
37
37
|
elsif [:ul, :dl, :ol, :codeblock].include?(el.type) && opts[:next] &&
|
@@ -174,7 +174,11 @@ module Kramdown
|
|
174
174
|
end
|
175
175
|
|
176
176
|
def convert_dt(el, opts)
|
177
|
-
|
177
|
+
result = ''
|
178
|
+
if ial = ial_for_element(el)
|
179
|
+
result << ial << " "
|
180
|
+
end
|
181
|
+
result << inner(el, opts) << "\n"
|
178
182
|
end
|
179
183
|
|
180
184
|
HTML_TAGS_WITH_BODY=['div', 'script', 'iframe', 'textarea']
|
@@ -288,14 +292,15 @@ module Kramdown
|
|
288
292
|
|
289
293
|
def convert_img(el, opts)
|
290
294
|
alt_text = el.attr['alt'].to_s.gsub(ESCAPED_CHAR_RE) { $1 ? "\\#{$1}" : $2 }
|
291
|
-
|
295
|
+
src = el.attr['src'].to_s
|
296
|
+
if src.empty?
|
292
297
|
"![#{alt_text}]()"
|
293
298
|
else
|
294
299
|
title = parse_title(el.attr['title'])
|
295
|
-
link = if
|
296
|
-
"<#{
|
300
|
+
link = if src.count("()") > 0
|
301
|
+
"<#{src}>"
|
297
302
|
else
|
298
|
-
|
303
|
+
src
|
299
304
|
end
|
300
305
|
"![#{alt_text}](#{link}#{title})"
|
301
306
|
end
|
@@ -402,7 +407,7 @@ module Kramdown
|
|
402
407
|
next if el.type == :header && k == 'id' && !v.strip.empty?
|
403
408
|
if v.nil?
|
404
409
|
''
|
405
|
-
elsif k == 'class' && !v.empty?
|
410
|
+
elsif k == 'class' && !v.empty? && !v.index(/[\.#]/)
|
406
411
|
" " + v.split(/\s+/).map {|w| ".#{w}"}.join(" ")
|
407
412
|
elsif k == 'id' && !v.strip.empty?
|
408
413
|
" ##{v}"
|
@@ -414,6 +419,10 @@ module Kramdown
|
|
414
419
|
(el.options[:ial] && (el.options[:ial][:refs] || []).include?('toc')) # RM can't use rescue nil
|
415
420
|
res = "footnotes" << (res.strip.empty? ? '' : " #{res}") if (el.type == :ul || el.type == :ol) &&
|
416
421
|
(el.options[:ial] && (el.options[:ial][:refs] || []).include?('footnotes')) # RM can't use rescue nil
|
422
|
+
if el.type == :dl && el.options[:ial] && el.options[:ial][:refs]
|
423
|
+
auto_ids = el.options[:ial][:refs].select {|ref| ref =~ /\Aauto_ids/}.join(" ")
|
424
|
+
res = auto_ids << (res.strip.empty? ? '' : " #{res}") unless auto_ids.empty?
|
425
|
+
end
|
417
426
|
res.strip.empty? ? nil : "{:#{res}}"
|
418
427
|
end
|
419
428
|
|