kramdown 0.2.0 → 0.3.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.
- data/ChangeLog +267 -0
- data/VERSION +1 -1
- data/benchmark/benchmark.rb +2 -1
- data/benchmark/generate_data.rb +110 -0
- data/benchmark/historic-jruby-1.4.0.dat +7 -0
- data/benchmark/historic-ruby-1.8.6.dat +7 -0
- data/benchmark/historic-ruby-1.8.7.dat +7 -0
- data/benchmark/historic-ruby-1.9.1p243.dat +7 -0
- data/benchmark/historic-ruby-1.9.2dev.dat +7 -0
- data/benchmark/static-jruby-1.4.0.dat +7 -0
- data/benchmark/static-ruby-1.8.6.dat +7 -0
- data/benchmark/static-ruby-1.8.7.dat +7 -0
- data/benchmark/static-ruby-1.9.1p243.dat +7 -0
- data/benchmark/static-ruby-1.9.2dev.dat +7 -0
- data/benchmark/testing.sh +1 -1
- data/doc/index.page +5 -5
- data/doc/installation.page +3 -3
- data/doc/quickref.page +3 -3
- data/doc/syntax.page +133 -101
- data/doc/tests.page +9 -1
- data/lib/kramdown/compatibility.rb +34 -0
- data/lib/kramdown/converter.rb +26 -8
- data/lib/kramdown/document.rb +2 -1
- data/lib/kramdown/parser.rb +1 -1192
- data/lib/kramdown/parser/kramdown.rb +272 -0
- data/lib/kramdown/parser/kramdown/attribute_list.rb +102 -0
- data/lib/kramdown/parser/kramdown/autolink.rb +42 -0
- data/lib/kramdown/parser/kramdown/blank_line.rb +43 -0
- data/lib/kramdown/parser/kramdown/blockquote.rb +42 -0
- data/lib/kramdown/parser/kramdown/codeblock.rb +62 -0
- data/lib/kramdown/parser/kramdown/codespan.rb +57 -0
- data/lib/kramdown/parser/kramdown/emphasis.rb +69 -0
- data/lib/kramdown/parser/kramdown/eob.rb +39 -0
- data/lib/kramdown/parser/kramdown/escaped_chars.rb +38 -0
- data/lib/kramdown/parser/kramdown/extension.rb +65 -0
- data/lib/kramdown/parser/kramdown/footnote.rb +72 -0
- data/lib/kramdown/parser/kramdown/header.rb +81 -0
- data/lib/kramdown/parser/kramdown/horizontal_rule.rb +39 -0
- data/lib/kramdown/parser/kramdown/html.rb +253 -0
- data/lib/kramdown/{deprecated.rb → parser/kramdown/html_entity.rb} +10 -12
- data/lib/kramdown/parser/kramdown/line_break.rb +38 -0
- data/lib/kramdown/parser/kramdown/link.rb +153 -0
- data/lib/kramdown/parser/kramdown/list.rb +225 -0
- data/lib/kramdown/parser/kramdown/paragraph.rb +44 -0
- data/lib/kramdown/parser/kramdown/typographic_symbol.rb +48 -0
- data/lib/kramdown/version.rb +1 -1
- data/test/testcases/block/09_html/comment.html +1 -0
- data/test/testcases/block/09_html/comment.text +1 -1
- data/test/testcases/block/09_html/content_model/tables.text +2 -2
- data/test/testcases/block/09_html/not_parsed.html +10 -0
- data/test/testcases/block/09_html/not_parsed.text +9 -0
- data/test/testcases/block/09_html/parse_as_raw.html +4 -0
- data/test/testcases/block/09_html/parse_as_raw.text +2 -0
- data/test/testcases/block/09_html/parse_block_html.html +4 -0
- data/test/testcases/block/09_html/parse_block_html.text +3 -0
- data/test/testcases/block/09_html/processing_instruction.html +1 -0
- data/test/testcases/block/09_html/processing_instruction.text +1 -1
- data/test/testcases/block/09_html/simple.html +8 -15
- data/test/testcases/block/09_html/simple.text +2 -12
- data/test/testcases/span/02_emphasis/normal.html +8 -4
- data/test/testcases/span/02_emphasis/normal.text +6 -2
- data/test/testcases/span/05_html/markdown_attr.html +2 -1
- data/test/testcases/span/05_html/markdown_attr.text +2 -1
- data/test/testcases/span/05_html/normal.html +6 -2
- data/test/testcases/span/05_html/normal.text +4 -0
- metadata +35 -4
- data/lib/kramdown/parser/registry.rb +0 -62
@@ -0,0 +1,42 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
#--
|
4
|
+
# Copyright (C) 2009 Thomas Leitner <t_leitner@gmx.at>
|
5
|
+
#
|
6
|
+
# This file is part of kramdown.
|
7
|
+
#
|
8
|
+
# kramdown is free software: you can redistribute it and/or modify
|
9
|
+
# it under the terms of the GNU General Public License as published by
|
10
|
+
# the Free Software Foundation, either version 3 of the License, or
|
11
|
+
# (at your option) any later version.
|
12
|
+
#
|
13
|
+
# This program is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License
|
19
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
20
|
+
#++
|
21
|
+
#
|
22
|
+
|
23
|
+
module Kramdown
|
24
|
+
module Parser
|
25
|
+
class Kramdown
|
26
|
+
|
27
|
+
BLOCKQUOTE_START = /^#{OPT_SPACE}> ?/
|
28
|
+
BLOCKQUOTE_MATCH = /(^#{OPT_SPACE}>.*?\n)+/
|
29
|
+
|
30
|
+
# Parse the blockquote at the current location.
|
31
|
+
def parse_blockquote
|
32
|
+
result = @src.scan(BLOCKQUOTE_MATCH).gsub(BLOCKQUOTE_START, '')
|
33
|
+
el = Element.new(:blockquote)
|
34
|
+
@tree.children << el
|
35
|
+
parse_blocks(el, result)
|
36
|
+
true
|
37
|
+
end
|
38
|
+
define_parser(:blockquote, BLOCKQUOTE_START)
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
#--
|
4
|
+
# Copyright (C) 2009 Thomas Leitner <t_leitner@gmx.at>
|
5
|
+
#
|
6
|
+
# This file is part of kramdown.
|
7
|
+
#
|
8
|
+
# kramdown is free software: you can redistribute it and/or modify
|
9
|
+
# it under the terms of the GNU General Public License as published by
|
10
|
+
# the Free Software Foundation, either version 3 of the License, or
|
11
|
+
# (at your option) any later version.
|
12
|
+
#
|
13
|
+
# This program is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License
|
19
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
20
|
+
#++
|
21
|
+
#
|
22
|
+
|
23
|
+
module Kramdown
|
24
|
+
module Parser
|
25
|
+
class Kramdown
|
26
|
+
|
27
|
+
CODEBLOCK_START = INDENT
|
28
|
+
CODEBLOCK_MATCH = /(?:#{INDENT}.*?\S.*?\n)+/
|
29
|
+
|
30
|
+
# Parse the indented codeblock at the current location.
|
31
|
+
def parse_codeblock
|
32
|
+
result = @src.scan(CODEBLOCK_MATCH).gsub(INDENT, '')
|
33
|
+
children = @tree.children
|
34
|
+
if children.length >= 2 && children[-1].type == :blank && children[-2].type == :codeblock
|
35
|
+
children[-2].value << children[-1].value.gsub(INDENT, '') << result
|
36
|
+
children.pop
|
37
|
+
else
|
38
|
+
@tree.children << Element.new(:codeblock, result)
|
39
|
+
end
|
40
|
+
true
|
41
|
+
end
|
42
|
+
define_parser(:codeblock, CODEBLOCK_START)
|
43
|
+
|
44
|
+
|
45
|
+
FENCED_CODEBLOCK_START = /^~{3,}/
|
46
|
+
FENCED_CODEBLOCK_MATCH = /^(~{3,})\s*?\n(.*?)^\1~*\s*?\n/m
|
47
|
+
|
48
|
+
# Parse the fenced codeblock at the current location.
|
49
|
+
def parse_codeblock_fenced
|
50
|
+
if @src.check(FENCED_CODEBLOCK_MATCH)
|
51
|
+
@src.pos += @src.matched_size
|
52
|
+
@tree.children << Element.new(:codeblock, @src[2])
|
53
|
+
true
|
54
|
+
else
|
55
|
+
false
|
56
|
+
end
|
57
|
+
end
|
58
|
+
define_parser(:codeblock_fenced, FENCED_CODEBLOCK_START)
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
#--
|
4
|
+
# Copyright (C) 2009 Thomas Leitner <t_leitner@gmx.at>
|
5
|
+
#
|
6
|
+
# This file is part of kramdown.
|
7
|
+
#
|
8
|
+
# kramdown is free software: you can redistribute it and/or modify
|
9
|
+
# it under the terms of the GNU General Public License as published by
|
10
|
+
# the Free Software Foundation, either version 3 of the License, or
|
11
|
+
# (at your option) any later version.
|
12
|
+
#
|
13
|
+
# This program is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License
|
19
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
20
|
+
#++
|
21
|
+
#
|
22
|
+
|
23
|
+
module Kramdown
|
24
|
+
module Parser
|
25
|
+
class Kramdown
|
26
|
+
|
27
|
+
CODESPAN_DELIMITER = /`+/
|
28
|
+
|
29
|
+
# Parse the codespan at the current scanner location.
|
30
|
+
def parse_codespan
|
31
|
+
result = @src.scan(CODESPAN_DELIMITER)
|
32
|
+
simple = (result.length == 1)
|
33
|
+
reset_pos = @src.pos
|
34
|
+
|
35
|
+
if simple && @src.pre_match =~ /\s\Z/ && @src.match?(/\s/)
|
36
|
+
add_text(result)
|
37
|
+
return
|
38
|
+
end
|
39
|
+
|
40
|
+
text = @src.scan_until(/#{result}/)
|
41
|
+
if text
|
42
|
+
text.sub!(/#{result}\Z/, '')
|
43
|
+
if !simple
|
44
|
+
text = text[1..-1] if text[0..0] == ' '
|
45
|
+
text = text[0..-2] if text[-1..-1] == ' '
|
46
|
+
end
|
47
|
+
@tree.children << Element.new(:codespan, text)
|
48
|
+
else
|
49
|
+
@src.pos = reset_pos
|
50
|
+
add_text(result)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
define_parser(:codespan, CODESPAN_DELIMITER)
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
#--
|
4
|
+
# Copyright (C) 2009 Thomas Leitner <t_leitner@gmx.at>
|
5
|
+
#
|
6
|
+
# This file is part of kramdown.
|
7
|
+
#
|
8
|
+
# kramdown is free software: you can redistribute it and/or modify
|
9
|
+
# it under the terms of the GNU General Public License as published by
|
10
|
+
# the Free Software Foundation, either version 3 of the License, or
|
11
|
+
# (at your option) any later version.
|
12
|
+
#
|
13
|
+
# This program is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License
|
19
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
20
|
+
#++
|
21
|
+
#
|
22
|
+
|
23
|
+
module Kramdown
|
24
|
+
module Parser
|
25
|
+
class Kramdown
|
26
|
+
|
27
|
+
EMPHASIS_START = /(?:\*\*?|__?)/
|
28
|
+
|
29
|
+
# Parse the emphasis at the current location.
|
30
|
+
def parse_emphasis
|
31
|
+
result = @src.scan(EMPHASIS_START)
|
32
|
+
element = (result.length == 2 ? :strong : :em)
|
33
|
+
type = (result =~ /_/ ? '_' : '*')
|
34
|
+
reset_pos = @src.pos
|
35
|
+
|
36
|
+
if (type == '_' && @src.pre_match =~ /[[:alpha:]]\z/ && @src.check(/[[:alpha:]]/)) || @src.check(/\s/)
|
37
|
+
add_text(result)
|
38
|
+
return
|
39
|
+
end
|
40
|
+
|
41
|
+
sub_parse = lambda do |delim, elem|
|
42
|
+
el = Element.new(elem)
|
43
|
+
stop_re = /#{Regexp.escape(delim)}/
|
44
|
+
found = parse_spans(el, stop_re) do
|
45
|
+
(@src.string[@src.pos-1, 1] !~ /\s/) &&
|
46
|
+
(elem != :em || !@src.match?(/#{Regexp.escape(delim*2)}(?!#{Regexp.escape(delim)})/)) &&
|
47
|
+
(type != '_' || !@src.match?(/#{Regexp.escape(delim)}[[:alpha:]]/)) && el.children.size > 0
|
48
|
+
end
|
49
|
+
[found, el, stop_re]
|
50
|
+
end
|
51
|
+
|
52
|
+
found, el, stop_re = sub_parse.call(result, element)
|
53
|
+
if !found && element == :strong
|
54
|
+
@src.pos = reset_pos - 1
|
55
|
+
found, el, stop_re = sub_parse.call(type, :em)
|
56
|
+
end
|
57
|
+
if found
|
58
|
+
@src.scan(stop_re)
|
59
|
+
@tree.children << el
|
60
|
+
else
|
61
|
+
@src.pos = reset_pos
|
62
|
+
add_text(result)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
define_parser(:emphasis, EMPHASIS_START)
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
#--
|
4
|
+
# Copyright (C) 2009 Thomas Leitner <t_leitner@gmx.at>
|
5
|
+
#
|
6
|
+
# This file is part of kramdown.
|
7
|
+
#
|
8
|
+
# kramdown is free software: you can redistribute it and/or modify
|
9
|
+
# it under the terms of the GNU General Public License as published by
|
10
|
+
# the Free Software Foundation, either version 3 of the License, or
|
11
|
+
# (at your option) any later version.
|
12
|
+
#
|
13
|
+
# This program is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License
|
19
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
20
|
+
#++
|
21
|
+
#
|
22
|
+
|
23
|
+
module Kramdown
|
24
|
+
module Parser
|
25
|
+
class Kramdown
|
26
|
+
|
27
|
+
EOB_MARKER = /^\^\s*?\n/
|
28
|
+
|
29
|
+
# Parse the EOB marker at the current location.
|
30
|
+
def parse_eob_marker
|
31
|
+
@src.pos += @src.matched_size
|
32
|
+
@tree.children << Element.new(:eob)
|
33
|
+
true
|
34
|
+
end
|
35
|
+
define_parser(:eob_marker, EOB_MARKER)
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
#--
|
4
|
+
# Copyright (C) 2009 Thomas Leitner <t_leitner@gmx.at>
|
5
|
+
#
|
6
|
+
# This file is part of kramdown.
|
7
|
+
#
|
8
|
+
# kramdown is free software: you can redistribute it and/or modify
|
9
|
+
# it under the terms of the GNU General Public License as published by
|
10
|
+
# the Free Software Foundation, either version 3 of the License, or
|
11
|
+
# (at your option) any later version.
|
12
|
+
#
|
13
|
+
# This program is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License
|
19
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
20
|
+
#++
|
21
|
+
#
|
22
|
+
|
23
|
+
module Kramdown
|
24
|
+
module Parser
|
25
|
+
class Kramdown
|
26
|
+
|
27
|
+
ESCAPED_CHARS = /\\([\\.*_+-`()\[\]{}#!])/
|
28
|
+
|
29
|
+
# Parse the backslash-escaped character at the current location.
|
30
|
+
def parse_escaped_chars
|
31
|
+
@src.pos += @src.matched_size
|
32
|
+
add_text(@src[1])
|
33
|
+
end
|
34
|
+
define_parser(:escaped_chars, ESCAPED_CHARS)
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
#--
|
4
|
+
# Copyright (C) 2009 Thomas Leitner <t_leitner@gmx.at>
|
5
|
+
#
|
6
|
+
# This file is part of kramdown.
|
7
|
+
#
|
8
|
+
# kramdown is free software: you can redistribute it and/or modify
|
9
|
+
# it under the terms of the GNU General Public License as published by
|
10
|
+
# the Free Software Foundation, either version 3 of the License, or
|
11
|
+
# (at your option) any later version.
|
12
|
+
#
|
13
|
+
# This program is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License
|
19
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
20
|
+
#++
|
21
|
+
#
|
22
|
+
|
23
|
+
require 'kramdown/parser/kramdown/attribute_list'
|
24
|
+
|
25
|
+
module Kramdown
|
26
|
+
module Parser
|
27
|
+
class Kramdown
|
28
|
+
|
29
|
+
EXT_BLOCK_START_STR = "^#{OPT_SPACE}\\{::(%s):(:)?(#{ALD_ANY_CHARS}*)\\}\s*?\n"
|
30
|
+
EXT_BLOCK_START = /#{EXT_BLOCK_START_STR % ALD_ID_NAME}/
|
31
|
+
|
32
|
+
# Parse the extension block at the current location.
|
33
|
+
def parse_extension_block
|
34
|
+
@src.pos += @src.matched_size
|
35
|
+
|
36
|
+
ext = @src[1]
|
37
|
+
opts = {}
|
38
|
+
body = nil
|
39
|
+
parse_attribute_list(@src[3], opts)
|
40
|
+
|
41
|
+
if !@doc.extension.public_methods.map {|m| m.to_s}.include?("parse_#{ext}")
|
42
|
+
warning("No extension named '#{ext}' found - ignoring extension block")
|
43
|
+
body = :invalid
|
44
|
+
end
|
45
|
+
|
46
|
+
if !@src[2]
|
47
|
+
stop_re = /#{EXT_BLOCK_START_STR % ext}/
|
48
|
+
if result = @src.scan_until(stop_re)
|
49
|
+
parse_attribute_list(@src[3], opts)
|
50
|
+
body = result.sub!(stop_re, '') if body != :invalid
|
51
|
+
else
|
52
|
+
body = :invalid
|
53
|
+
warning("No ending line for extension block '#{ext}' found - ignoring extension block")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
@doc.extension.send("parse_#{ext}", self, opts, body) if body != :invalid
|
58
|
+
|
59
|
+
true
|
60
|
+
end
|
61
|
+
define_parser(:extension_block, EXT_BLOCK_START)
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
#--
|
4
|
+
# Copyright (C) 2009 Thomas Leitner <t_leitner@gmx.at>
|
5
|
+
#
|
6
|
+
# This file is part of kramdown.
|
7
|
+
#
|
8
|
+
# kramdown is free software: you can redistribute it and/or modify
|
9
|
+
# it under the terms of the GNU General Public License as published by
|
10
|
+
# the Free Software Foundation, either version 3 of the License, or
|
11
|
+
# (at your option) any later version.
|
12
|
+
#
|
13
|
+
# This program is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License
|
19
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
20
|
+
#++
|
21
|
+
#
|
22
|
+
|
23
|
+
require 'kramdown/parser/kramdown/attribute_list'
|
24
|
+
require 'kramdown/parser/kramdown/blank_line'
|
25
|
+
require 'kramdown/parser/kramdown/codeblock'
|
26
|
+
|
27
|
+
module Kramdown
|
28
|
+
module Parser
|
29
|
+
class Kramdown
|
30
|
+
|
31
|
+
FOOTNOTE_DEFINITION_START = /^#{OPT_SPACE}\[\^(#{ALD_ID_NAME})\]:\s*?(.*?\n(?:#{BLANK_LINE}?#{CODEBLOCK_MATCH})*)/
|
32
|
+
|
33
|
+
# Parse the foot note definition at the current location.
|
34
|
+
def parse_footnote_definition
|
35
|
+
@src.pos += @src.matched_size
|
36
|
+
|
37
|
+
el = Element.new(:footnote_def)
|
38
|
+
parse_blocks(el, @src[2].gsub(INDENT, ''))
|
39
|
+
warning("Duplicate footnote name '#{@src[1]}' - overwriting") if @doc.parse_infos[:footnotes][@src[1]]
|
40
|
+
(@doc.parse_infos[:footnotes][@src[1]] = {})[:content] = el
|
41
|
+
end
|
42
|
+
define_parser(:footnote_definition, FOOTNOTE_DEFINITION_START)
|
43
|
+
|
44
|
+
|
45
|
+
FOOTNOTE_MARKER_START = /\[\^(#{ALD_ID_NAME})\]/
|
46
|
+
|
47
|
+
# Parse the footnote marker at the current location.
|
48
|
+
def parse_footnote_marker
|
49
|
+
@src.pos += @src.matched_size
|
50
|
+
fn_def = @doc.parse_infos[:footnotes][@src[1]]
|
51
|
+
if fn_def
|
52
|
+
valid = fn_def[:marker] && fn_def[:marker].options[:stack][0..-2].zip(fn_def[:marker].options[:stack][1..-1]).all? do |par, child|
|
53
|
+
par.children.include?(child)
|
54
|
+
end
|
55
|
+
if !fn_def[:marker] || !valid
|
56
|
+
fn_def[:marker] = Element.new(:footnote, nil, :name => @src[1])
|
57
|
+
fn_def[:marker].options[:stack] = [@stack.map {|s| s.first}, @tree, fn_def[:marker]].flatten.compact
|
58
|
+
@tree.children << fn_def[:marker]
|
59
|
+
else
|
60
|
+
warning("Footnote marker '#{@src[1]}' already appeared in document, ignoring newly found marker")
|
61
|
+
add_text(@src.matched)
|
62
|
+
end
|
63
|
+
else
|
64
|
+
warning("Footnote definition for '#{@src[1]}' not found")
|
65
|
+
add_text(@src.matched)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
define_parser(:footnote_marker, FOOTNOTE_MARKER_START)
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|