motion-kramdown 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -7
- data/lib/kramdown.rb +1 -1
- data/lib/kramdown/compatibility.rb +1 -1
- data/lib/kramdown/converter.rb +1 -1
- data/lib/kramdown/converter/base.rb +2 -1
- data/lib/kramdown/converter/html.rb +10 -5
- data/lib/kramdown/converter/kramdown.rb +13 -7
- data/lib/kramdown/converter/latex.rb +2 -1
- data/lib/kramdown/converter/math_engine/itex2mml.rb +1 -1
- data/lib/kramdown/converter/math_engine/mathjax.rb +18 -3
- data/lib/kramdown/converter/math_engine/ritex.rb +1 -1
- data/lib/kramdown/converter/pdf.rb +3 -2
- data/lib/kramdown/converter/remove_html_tags.rb +3 -1
- data/lib/kramdown/converter/syntax_highlighter.rb +53 -0
- data/lib/kramdown/converter/syntax_highlighter/coderay.rb +1 -1
- data/lib/kramdown/converter/syntax_highlighter/rouge.rb +2 -2
- data/lib/kramdown/converter/toc.rb +2 -2
- data/lib/kramdown/document.rb +5 -5
- data/lib/kramdown/element.rb +4 -1
- data/lib/kramdown/error.rb +1 -1
- data/lib/kramdown/options.rb +4 -3
- data/lib/kramdown/parser.rb +1 -1
- data/lib/kramdown/parser/base.rb +8 -4
- data/lib/kramdown/parser/gfm.rb +9 -1
- data/lib/kramdown/parser/html.rb +18 -3
- data/lib/kramdown/parser/kramdown.rb +8 -5
- data/lib/kramdown/parser/kramdown/abbreviation.rb +10 -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 +1 -1
- data/lib/kramdown/parser/kramdown/blockquote.rb +1 -1
- data/lib/kramdown/parser/kramdown/codeblock.rb +1 -1
- 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 +8 -7
- data/lib/kramdown/parser/kramdown/footnote.rb +12 -4
- 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 +7 -4
- 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 +8 -5
- data/lib/kramdown/parser/kramdown/list.rb +17 -5
- data/lib/kramdown/parser/kramdown/math.rb +3 -3
- data/lib/kramdown/parser/kramdown/paragraph.rb +3 -3
- data/lib/kramdown/parser/kramdown/smart_quotes.rb +1 -1
- data/lib/kramdown/parser/kramdown/table.rb +1 -1
- data/lib/kramdown/parser/kramdown/typographic_symbol.rb +1 -1
- data/lib/kramdown/parser/markdown.rb +2 -2
- data/lib/kramdown/utils.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 +3 -1
- data/lib/kramdown/utils/ordered_hash.rb +1 -1
- data/lib/kramdown/utils/string_scanner.rb +8 -0
- data/lib/kramdown/utils/unidecoder.rb +1 -1
- data/lib/kramdown/version.rb +2 -2
- data/lib/rubymotion/version.rb +1 -1
- data/spec/bench_mark.rb +43 -30
- data/spec/document_tree.rb +12 -2
- data/spec/gfm_to_html.rb +4 -1
- data/spec/html_to_html.rb +27 -9
- data/spec/html_to_kramdown_to_html.rb +4 -1
- data/spec/kramdown_to_xxx.rb +3 -1
- data/spec/text_to_kramdown_to_html.rb +4 -0
- data/spec/text_to_latex.rb +1 -1
- metadata +5 -4
data/lib/kramdown/element.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
3
|
#--
|
4
|
-
# Copyright (C) 2009-
|
4
|
+
# Copyright (C) 2009-2015 Thomas Leitner <t_leitner@gmx.at>
|
5
5
|
#
|
6
6
|
# This file is part of kramdown which is licensed under the MIT.
|
7
7
|
#++
|
@@ -37,6 +37,9 @@ module Kramdown
|
|
37
37
|
# :abbrev_defs:: This key may be used to store the mapping of abbreviation to abbreviation
|
38
38
|
# definition.
|
39
39
|
#
|
40
|
+
# :abbrev_attr:: This key may be used to store the mapping of abbreviation to abbreviation
|
41
|
+
# attributes.
|
42
|
+
#
|
40
43
|
# :options:: This key may be used to store options that were set during parsing of the document.
|
41
44
|
#
|
42
45
|
#
|
data/lib/kramdown/error.rb
CHANGED
data/lib/kramdown/options.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
3
|
#--
|
4
|
-
# Copyright (C) 2009-
|
4
|
+
# Copyright (C) 2009-2015 Thomas Leitner <t_leitner@gmx.at>
|
5
5
|
#
|
6
6
|
# This file is part of kramdown which is licensed under the MIT.
|
7
7
|
#++
|
@@ -418,7 +418,8 @@ specified levels are used for the table of contents.
|
|
418
418
|
Default: 1..6
|
419
419
|
Used by: HTML/Latex converter
|
420
420
|
EOF
|
421
|
-
|
421
|
+
case val
|
422
|
+
when String
|
422
423
|
if val =~ /^(\d)\.\.(\d)$/
|
423
424
|
val = Range.new($1.to_i, $2.to_i).to_a
|
424
425
|
elsif val =~ /^\d(?:,\d)*$/
|
@@ -426,7 +427,7 @@ EOF
|
|
426
427
|
else
|
427
428
|
raise Kramdown::Error, "Invalid syntax for option toc_levels"
|
428
429
|
end
|
429
|
-
|
430
|
+
when Array, Range
|
430
431
|
val = val.map {|s| s.to_i}.uniq
|
431
432
|
else
|
432
433
|
raise Kramdown::Error, "Invalid type #{val.class} for option toc_levels"
|
data/lib/kramdown/parser.rb
CHANGED
data/lib/kramdown/parser/base.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
3
|
#--
|
4
|
-
# Copyright (C) 2009-
|
4
|
+
# Copyright (C) 2009-2015 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
|
-
# RM require 'kramdown/utils
|
10
|
+
# RM require 'kramdown/utils'
|
11
|
+
# RM require 'kramdown/parser'
|
11
12
|
|
12
13
|
module Kramdown
|
13
14
|
|
@@ -51,7 +52,8 @@ module Kramdown
|
|
51
52
|
def initialize(source, options)
|
52
53
|
@source = source
|
53
54
|
@options = Kramdown::Options.merge(options)
|
54
|
-
@root = Element.new(:root, nil, nil, :encoding => (source.encoding rescue nil), :location => 1
|
55
|
+
@root = Element.new(:root, nil, nil, :encoding => (source.encoding rescue nil), :location => 1,
|
56
|
+
:options => {}, :abbrev_defs => {}, :abbrev_attr => {})
|
55
57
|
@warnings = []
|
56
58
|
@text_type = :text
|
57
59
|
end
|
@@ -88,7 +90,9 @@ module Kramdown
|
|
88
90
|
# +\n+ and makes sure +source+ ends with a new line character).
|
89
91
|
def adapt_source(source)
|
90
92
|
if source.respond_to?(:encode)
|
91
|
-
|
93
|
+
if !source.valid_encoding?
|
94
|
+
raise "The source text contains invalid characters for the used encoding #{source.encoding}"
|
95
|
+
end
|
92
96
|
source = source.encode('UTF-8')
|
93
97
|
end
|
94
98
|
source.gsub(/\r\n?/, "\n").chomp + "\n"
|
data/lib/kramdown/parser/gfm.rb
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
#--
|
4
|
+
# Copyright (C) 2009-2015 Thomas Leitner <t_leitner@gmx.at>
|
5
|
+
#
|
6
|
+
# This file is part of kramdown which is licensed under the MIT.
|
7
|
+
#++
|
8
|
+
#
|
2
9
|
|
3
|
-
|
10
|
+
|
11
|
+
# RM require 'kramdown/parser'
|
4
12
|
|
5
13
|
module Kramdown
|
6
14
|
module Parser
|
data/lib/kramdown/parser/html.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
3
|
#--
|
4
|
-
# Copyright (C) 2009-
|
4
|
+
# Copyright (C) 2009-2015 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,7 @@
|
|
10
10
|
# RM require 'rexml/parsers/baseparser'
|
11
11
|
# RM require 'strscan'
|
12
12
|
# RM require 'kramdown/utils'
|
13
|
+
# RM require 'kramdown/parser'
|
13
14
|
|
14
15
|
module Kramdown
|
15
16
|
|
@@ -78,8 +79,7 @@ module Kramdown
|
|
78
79
|
def handle_html_start_tag(line = nil) # :yields: el, closed, handle_body
|
79
80
|
name = @src[1].downcase
|
80
81
|
closed = !@src[4].nil?
|
81
|
-
attrs =
|
82
|
-
@src[2].scan(HTML_ATTRIBUTE_RE).each {|attr,sep,val| attrs[attr.downcase] = val || ""}
|
82
|
+
attrs = parse_html_attributes(@src[2], line)
|
83
83
|
|
84
84
|
el = Element.new(:html_element, name, attrs, :category => :block)
|
85
85
|
el.options[:location] = line if line
|
@@ -97,6 +97,21 @@ module Kramdown
|
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
|
+
# Parses the given string for HTML attributes and returns the resulting hash.
|
101
|
+
#
|
102
|
+
# If the optional +line+ parameter is supplied, it is used in warning messages.
|
103
|
+
def parse_html_attributes(str, line = nil)
|
104
|
+
attrs = Utils::OrderedHash.new
|
105
|
+
str.scan(HTML_ATTRIBUTE_RE).each do |attr, sep, val|
|
106
|
+
attr.downcase!
|
107
|
+
if attrs.has_key?(attr)
|
108
|
+
warning("Duplicate HTML attribute '#{attr}' on line #{line || '?'} - overwriting previous one")
|
109
|
+
end
|
110
|
+
attrs[attr] = val || ""
|
111
|
+
end
|
112
|
+
attrs
|
113
|
+
end
|
114
|
+
|
100
115
|
# Handle the raw HTML tag at the current position.
|
101
116
|
def handle_raw_html_tag(name)
|
102
117
|
curpos = @src.pos
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
3
|
#--
|
4
|
-
# Copyright (C) 2009-
|
4
|
+
# Copyright (C) 2009-2015 Thomas Leitner <t_leitner@gmx.at>
|
5
5
|
#
|
6
6
|
# This file is part of kramdown which is licensed under the MIT.
|
7
7
|
#++
|
@@ -9,6 +9,7 @@
|
|
9
9
|
|
10
10
|
# RM require 'strscan'
|
11
11
|
# RM require 'stringio'
|
12
|
+
# RM require 'kramdown/parser'
|
12
13
|
|
13
14
|
#TODO: use [[:alpha:]] in all regexp to allow parsing of international values in 1.9.1
|
14
15
|
#NOTE: use @src.pre_match only before other check/match?/... operations, otherwise the content is changed
|
@@ -66,7 +67,6 @@ module Kramdown
|
|
66
67
|
|
67
68
|
reset_env
|
68
69
|
|
69
|
-
@root.options[:abbrev_defs] = {}
|
70
70
|
@alds = {}
|
71
71
|
@footnotes = {}
|
72
72
|
@link_defs = {}
|
@@ -88,6 +88,7 @@ module Kramdown
|
|
88
88
|
configure_parser
|
89
89
|
parse_blocks(@root, adapt_source(source))
|
90
90
|
update_tree(@root)
|
91
|
+
correct_abbreviations_attributes
|
91
92
|
replace_abbreviations(@root)
|
92
93
|
@footnotes.each {|name,data| update_tree(data[:content])}
|
93
94
|
end
|
@@ -134,7 +135,6 @@ module Kramdown
|
|
134
135
|
|
135
136
|
status = catch(:stop_block_parsing) do
|
136
137
|
while !@src.eos?
|
137
|
-
block_ial_set = @block_ial
|
138
138
|
@block_parsers.any? do |name|
|
139
139
|
if @src.check(@parsers[name].start_re)
|
140
140
|
send(@parsers[name].method)
|
@@ -145,7 +145,6 @@ module Kramdown
|
|
145
145
|
warning('Warning: this should not occur - no block parser handled the line')
|
146
146
|
add_text(@src.scan(/.*\n/))
|
147
147
|
end
|
148
|
-
@block_ial = nil if block_ial_set
|
149
148
|
end
|
150
149
|
end
|
151
150
|
|
@@ -165,6 +164,7 @@ module Kramdown
|
|
165
164
|
parse_spans(child)
|
166
165
|
child.children
|
167
166
|
elsif child.type == :eob
|
167
|
+
update_attr_with_ial(child.attr, child.options[:ial]) if child.options[:ial]
|
168
168
|
[]
|
169
169
|
elsif child.type == :blank
|
170
170
|
if last_blank
|
@@ -290,7 +290,10 @@ module Kramdown
|
|
290
290
|
# exists. This method should always be used for creating a block-level element!
|
291
291
|
def new_block_el(*args)
|
292
292
|
el = Element.new(*args)
|
293
|
-
|
293
|
+
if @block_ial
|
294
|
+
el.options[:ial] = @block_ial
|
295
|
+
@block_ial = nil
|
296
|
+
end
|
294
297
|
el
|
295
298
|
end
|
296
299
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
3
|
#--
|
4
|
-
# Copyright (C) 2009-
|
4
|
+
# Copyright (C) 2009-2015 Thomas Leitner <t_leitner@gmx.at>
|
5
5
|
#
|
6
6
|
# This file is part of kramdown which is licensed under the MIT.
|
7
7
|
#++
|
@@ -20,12 +20,20 @@ module Kramdown
|
|
20
20
|
abbrev_id, abbrev_text = @src[1], @src[2]
|
21
21
|
abbrev_text.strip!
|
22
22
|
warning("Duplicate abbreviation ID '#{abbrev_id}' on line #{start_line_number} - overwriting") if @root.options[:abbrev_defs][abbrev_id]
|
23
|
+
@tree.children << new_block_el(:eob, :abbrev_def)
|
23
24
|
@root.options[:abbrev_defs][abbrev_id] = abbrev_text
|
24
|
-
@
|
25
|
+
@root.options[:abbrev_attr][abbrev_id] = @tree.children.last
|
25
26
|
true
|
26
27
|
end
|
27
28
|
define_parser(:abbrev_definition, ABBREV_DEFINITION_START)
|
28
29
|
|
30
|
+
# Correct abbreviation attributes.
|
31
|
+
def correct_abbreviations_attributes
|
32
|
+
@root.options[:abbrev_attr].keys.each do |k|
|
33
|
+
@root.options[:abbrev_attr][k] = @root.options[:abbrev_attr][k].attr
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
29
37
|
# Replace the abbreviation text with elements.
|
30
38
|
def replace_abbreviations(el, regexps = nil)
|
31
39
|
return if @root.options[:abbrev_defs].empty?
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
3
|
#--
|
4
|
-
# Copyright (C) 2009-
|
4
|
+
# Copyright (C) 2009-2015 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,7 +22,7 @@ module Kramdown
|
|
22
22
|
element = (result.length == 2 ? :strong : :em)
|
23
23
|
type = result[0..0]
|
24
24
|
|
25
|
-
if (type == '_' && @src.pre_match =~ /[[:alnum:]]\z/
|
25
|
+
if (type == '_' && @src.pre_match =~ /[[:alnum:]]\z/) || @src.check(/\s/) ||
|
26
26
|
@tree.type == element || @stack.any? {|el, _| el.type == element}
|
27
27
|
add_text(result)
|
28
28
|
return
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
3
|
#--
|
4
|
-
# Copyright (C) 2009-
|
4
|
+
# Copyright (C) 2009-2015 Thomas Leitner <t_leitner@gmx.at>
|
5
5
|
#
|
6
6
|
# This file is part of kramdown which is licensed under the MIT.
|
7
7
|
#++
|
@@ -117,7 +117,7 @@ module Kramdown
|
|
117
117
|
end.each do |k,v|
|
118
118
|
warning("Unknown kramdown option '#{k}'")
|
119
119
|
end
|
120
|
-
@tree.children <<
|
120
|
+
@tree.children << new_block_el(:eob, :extension) if type == :block
|
121
121
|
true
|
122
122
|
else
|
123
123
|
false
|
@@ -129,7 +129,7 @@ module Kramdown
|
|
129
129
|
ALD_ANY_CHARS = /\\\}|[^\}]/
|
130
130
|
ALD_ID_NAME = /\w#{ALD_ID_CHARS}*/
|
131
131
|
ALD_TYPE_KEY_VALUE_PAIR = /(#{ALD_ID_NAME})=("|')((?:\\\}|\\\2|[^\}\2])*?)\2/
|
132
|
-
ALD_TYPE_CLASS_NAME = /\.(
|
132
|
+
ALD_TYPE_CLASS_NAME = /\.(-?#{ALD_ID_NAME})/
|
133
133
|
ALD_TYPE_ID_NAME = /#([A-Za-z][\w:-]*)/
|
134
134
|
ALD_TYPE_ID_OR_CLASS = /#{ALD_TYPE_ID_NAME}|#{ALD_TYPE_CLASS_NAME}/
|
135
135
|
ALD_TYPE_ID_OR_CLASS_MULTI = /((?:#{ALD_TYPE_ID_NAME}|#{ALD_TYPE_CLASS_NAME})+)/
|
@@ -152,16 +152,17 @@ module Kramdown
|
|
152
152
|
def parse_block_extensions
|
153
153
|
if @src.scan(ALD_START)
|
154
154
|
parse_attribute_list(@src[2], @alds[@src[1]] ||= Utils::OrderedHash.new)
|
155
|
-
@tree.children <<
|
155
|
+
@tree.children << new_block_el(:eob, :ald)
|
156
156
|
true
|
157
157
|
elsif @src.check(EXT_BLOCK_START)
|
158
158
|
parse_extension_start_tag(:block)
|
159
159
|
elsif @src.scan(IAL_BLOCK_START)
|
160
|
-
if @tree.children.last && @tree.children.last.type != :blank &&
|
160
|
+
if @tree.children.last && @tree.children.last.type != :blank &&
|
161
|
+
(@tree.children.last.type != :eob || [:link_def, :abbrev_def, :footnote_def].include?(@tree.children.last.value))
|
161
162
|
parse_attribute_list(@src[1], @tree.children.last.options[:ial] ||= Utils::OrderedHash.new)
|
162
|
-
@tree.children <<
|
163
|
+
@tree.children << new_block_el(:eob, :ial) unless @src.check(IAL_BLOCK_START)
|
163
164
|
else
|
164
|
-
parse_attribute_list(@src[1], @block_ial
|
165
|
+
parse_attribute_list(@src[1], @block_ial ||= Utils::OrderedHash.new)
|
165
166
|
end
|
166
167
|
true
|
167
168
|
else
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
3
|
#--
|
4
|
-
# Copyright (C) 2009-
|
4
|
+
# Copyright (C) 2009-2015 Thomas Leitner <t_leitner@gmx.at>
|
5
5
|
#
|
6
6
|
# This file is part of kramdown which is licensed under the MIT.
|
7
7
|
#++
|
@@ -25,8 +25,9 @@ module Kramdown
|
|
25
25
|
el = Element.new(:footnote_def, nil, nil, :location => start_line_number)
|
26
26
|
parse_blocks(el, @src[2].gsub(INDENT, ''))
|
27
27
|
warning("Duplicate footnote name '#{@src[1]}' on line #{start_line_number} - overwriting") if @footnotes[@src[1]]
|
28
|
+
@tree.children << new_block_el(:eob, :footnote_def)
|
28
29
|
(@footnotes[@src[1]] = {})[:content] = el
|
29
|
-
@tree.children
|
30
|
+
@footnotes[@src[1]][:eob] = @tree.children.last
|
30
31
|
true
|
31
32
|
end
|
32
33
|
define_parser(:footnote_definition, FOOTNOTE_DEFINITION_START)
|
@@ -40,9 +41,15 @@ module Kramdown
|
|
40
41
|
@src.pos += @src.matched_size
|
41
42
|
fn_def = @footnotes[@src[1]]
|
42
43
|
if fn_def
|
44
|
+
if fn_def[:eob]
|
45
|
+
update_attr_with_ial(fn_def[:eob].attr, fn_def[:eob].options[:ial] || {})
|
46
|
+
fn_def[:attr] = fn_def[:eob].attr
|
47
|
+
fn_def[:options] = fn_def[:eob].options
|
48
|
+
fn_def.delete(:eob)
|
49
|
+
end
|
43
50
|
fn_def[:marker] ||= []
|
44
|
-
fn_def[:marker].push(Element.new(:footnote, fn_def[:content],
|
45
|
-
|
51
|
+
fn_def[:marker].push(Element.new(:footnote, fn_def[:content], fn_def[:attr],
|
52
|
+
fn_def[:options].merge(:name => @src[1], :location => start_line_number)))
|
46
53
|
@tree.children << fn_def[:marker].last
|
47
54
|
else
|
48
55
|
warning("Footnote definition for '#{@src[1]}' not found on line #{start_line_number}")
|
@@ -54,3 +61,4 @@ module Kramdown
|
|
54
61
|
end
|
55
62
|
end
|
56
63
|
end
|
64
|
+
|