maruku 0.6.0 → 0.7.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE.txt +20 -0
- data/bin/maruku +153 -152
- data/bin/marutex +2 -29
- data/data/entities.xml +261 -0
- data/docs/markdown_syntax.md +9 -21
- data/docs/math.md +14 -18
- data/lib/maruku.rb +65 -78
- data/lib/maruku/attributes.rb +109 -214
- data/lib/maruku/defaults.rb +45 -67
- data/lib/maruku/document.rb +44 -0
- data/lib/maruku/element.rb +138 -0
- data/lib/maruku/errors.rb +80 -0
- data/lib/maruku/ext/div.rb +105 -113
- data/lib/maruku/ext/fenced_code.rb +97 -0
- data/lib/maruku/ext/math.rb +22 -26
- data/lib/maruku/ext/math/elements.rb +20 -26
- data/lib/maruku/ext/math/mathml_engines/blahtex.rb +92 -104
- data/lib/maruku/ext/math/mathml_engines/itex2mml.rb +33 -26
- data/lib/maruku/ext/math/mathml_engines/none.rb +11 -19
- data/lib/maruku/ext/math/mathml_engines/ritex.rb +2 -4
- data/lib/maruku/ext/math/parsing.rb +121 -115
- data/lib/maruku/ext/math/to_html.rb +202 -187
- data/lib/maruku/ext/math/to_latex.rb +34 -21
- data/lib/maruku/helpers.rb +158 -257
- data/lib/maruku/html.rb +251 -0
- data/lib/maruku/input/charsource.rb +272 -319
- data/lib/maruku/input/extensions.rb +62 -63
- data/lib/maruku/input/html_helper.rb +233 -189
- data/lib/maruku/input/linesource.rb +90 -110
- data/lib/maruku/input/mdline.rb +131 -0
- data/lib/maruku/input/parse_block.rb +736 -613
- data/lib/maruku/input/parse_doc.rb +145 -217
- data/lib/maruku/input/parse_span.rb +740 -0
- data/lib/maruku/inspect_element.rb +60 -0
- data/lib/maruku/maruku.rb +14 -30
- data/lib/maruku/output/entity_table.rb +37 -0
- data/lib/maruku/output/s5/fancy.rb +462 -462
- data/lib/maruku/output/s5/to_s5.rb +115 -135
- data/lib/maruku/output/to_html.rb +907 -983
- data/lib/maruku/output/to_latex.rb +571 -563
- data/lib/maruku/output/to_markdown.rb +207 -162
- data/lib/maruku/output/to_s.rb +10 -52
- data/lib/maruku/string_utils.rb +129 -179
- data/lib/maruku/toc.rb +185 -196
- data/lib/maruku/version.rb +33 -38
- data/spec/block_docs/abbrev.md +776 -0
- data/{tests/unittest → spec/block_docs}/abbreviations.md +11 -20
- data/spec/block_docs/abbreviations2.md +27 -0
- data/{tests/unittest → spec/block_docs}/alt.md +2 -14
- data/{tests/unittest/pending → spec/block_docs}/amps.md +1 -13
- data/spec/block_docs/attribute_sanitize.md +22 -0
- data/{tests/unittest → spec/block_docs}/attributes/att2.md +0 -12
- data/{tests/unittest → spec/block_docs}/attributes/att3.md +2 -14
- data/{tests/unittest → spec/block_docs}/attributes/attributes.md +12 -16
- data/{tests/unittest → spec/block_docs}/attributes/circular.md +0 -12
- data/{tests/unittest → spec/block_docs}/attributes/default.md +1 -13
- data/spec/block_docs/atx_headers.md +22 -0
- data/spec/block_docs/auto_cdata.md +48 -0
- data/spec/block_docs/bad_cites.md +30 -0
- data/spec/block_docs/bad_divrefs.md +30 -0
- data/{tests/unittest → spec/block_docs}/blank.md +0 -12
- data/{tests/unittest → spec/block_docs}/blanks_in_code.md +16 -15
- data/spec/block_docs/block_quotes.md +66 -0
- data/{tests/unittest/loss.md → spec/block_docs/bug_def.md} +6 -18
- data/{tests/unittest → spec/block_docs}/bug_table.md +7 -19
- data/spec/block_docs/cites.md +37 -0
- data/{tests/unittest → spec/block_docs}/code.md +7 -14
- data/{tests/unittest → spec/block_docs}/code2.md +4 -14
- data/{tests/unittest → spec/block_docs}/code3.md +12 -16
- data/spec/block_docs/code4.md +79 -0
- data/{tests/unittest → spec/block_docs}/data_loss.md +2 -14
- data/spec/block_docs/div_without_newline.md +16 -0
- data/{tests/unittest → spec/block_docs}/divs/div1.md +0 -12
- data/{tests/unittest → spec/block_docs}/divs/div2.md +0 -12
- data/{tests/unittest → spec/block_docs}/divs/div3_nest.md +3 -15
- data/{tests/unittest → spec/block_docs}/easy.md +1 -13
- data/spec/block_docs/email.md +29 -0
- data/spec/block_docs/empty_cells.md +31 -0
- data/{tests/unittest → spec/block_docs}/encoding/iso-8859-1.md +1 -14
- data/{tests/unittest → spec/block_docs}/encoding/utf-8.md +0 -12
- data/{tests/unittest → spec/block_docs}/entities.md +33 -41
- data/{tests/unittest/notyet → spec/block_docs}/escape.md +2 -14
- data/{tests/unittest → spec/block_docs}/escaping.md +11 -22
- data/{tests/unittest → spec/block_docs}/extra_dl.md +2 -13
- data/{tests/unittest → spec/block_docs}/extra_header_id.md +14 -20
- data/{tests/unittest → spec/block_docs}/extra_table1.md +9 -21
- data/spec/block_docs/fenced_code_blocks.md +58 -0
- data/spec/block_docs/fenced_code_blocks_highlighted.md +17 -0
- data/{tests/unittest → spec/block_docs}/footnotes.md +12 -24
- data/spec/block_docs/footnotes2.md +82 -0
- data/spec/block_docs/hard.md +25 -0
- data/spec/block_docs/header_after_par.md +62 -0
- data/{tests/unittest → spec/block_docs}/headers.md +10 -18
- data/{tests/unittest → spec/block_docs}/hex_entities.md +7 -18
- data/{tests/unittest → spec/block_docs}/hrule.md +5 -12
- data/{tests/unittest → spec/block_docs}/html3.md +1 -13
- data/{tests/unittest → spec/block_docs}/html4.md +2 -14
- data/{tests/unittest → spec/block_docs}/html5.md +2 -14
- data/spec/block_docs/html_block_in_para.md +22 -0
- data/spec/block_docs/html_inline.md +25 -0
- data/spec/block_docs/html_trailing.md +31 -0
- data/spec/block_docs/ie.md +62 -0
- data/spec/block_docs/iframe.md +29 -0
- data/spec/block_docs/ignore_bad_header.md +9 -0
- data/{tests/unittest → spec/block_docs}/images.md +22 -28
- data/{tests/unittest → spec/block_docs}/images2.md +7 -17
- data/{tests/unittest → spec/block_docs}/inline_html.md +37 -67
- data/{tests/unittest → spec/block_docs}/inline_html2.md +1 -13
- data/spec/block_docs/inline_html_beginning.md +10 -0
- data/spec/block_docs/issue106.md +78 -0
- data/spec/block_docs/issue115.md +20 -0
- data/spec/block_docs/issue117.md +13 -0
- data/spec/block_docs/issue120.md +48 -0
- data/spec/block_docs/issue123.md +11 -0
- data/spec/block_docs/issue124.md +16 -0
- data/spec/block_docs/issue126.md +9 -0
- data/spec/block_docs/issue130.md +11 -0
- data/spec/block_docs/issue20.md +9 -0
- data/spec/block_docs/issue26.md +22 -0
- data/spec/block_docs/issue29.md +9 -0
- data/spec/block_docs/issue30.md +30 -0
- data/spec/block_docs/issue31.md +25 -0
- data/spec/block_docs/issue40.md +52 -0
- data/spec/block_docs/issue64.md +55 -0
- data/spec/block_docs/issue67.md +19 -0
- data/spec/block_docs/issue70.md +11 -0
- data/spec/block_docs/issue72.md +17 -0
- data/spec/block_docs/issue74.md +38 -0
- data/spec/block_docs/issue79.md +15 -0
- data/spec/block_docs/issue83.md +13 -0
- data/spec/block_docs/issue85.md +25 -0
- data/spec/block_docs/issue88.md +19 -0
- data/spec/block_docs/issue89.md +12 -0
- data/spec/block_docs/issue90.md +38 -0
- data/{tests/unittest/pending → spec/block_docs}/link.md +21 -18
- data/{tests/unittest → spec/block_docs}/links.md +33 -32
- data/spec/block_docs/links2.md +21 -0
- data/{tests/unittest → spec/block_docs}/list1.md +0 -12
- data/{tests/unittest → spec/block_docs}/list12.md +2 -14
- data/{tests/unittest → spec/block_docs}/list2.md +2 -14
- data/spec/block_docs/list_multipara.md +42 -0
- data/{tests/unittest → spec/block_docs}/lists.md +28 -29
- data/{tests/unittest → spec/block_docs}/lists10.md +2 -14
- data/spec/block_docs/lists11.md +23 -0
- data/spec/block_docs/lists12.md +43 -0
- data/spec/block_docs/lists13.md +55 -0
- data/spec/block_docs/lists14.md +61 -0
- data/spec/block_docs/lists15.md +36 -0
- data/spec/block_docs/lists6.md +88 -0
- data/spec/block_docs/lists7b.md +58 -0
- data/spec/block_docs/lists9.md +53 -0
- data/{tests/unittest → spec/block_docs}/lists_after_paragraph.md +19 -25
- data/spec/block_docs/lists_blank.md +35 -0
- data/{tests/unittest/list3.md → spec/block_docs/lists_blockquote_code.md} +2 -14
- data/{tests/unittest/list4.md → spec/block_docs/lists_need_blank_line.md} +44 -29
- data/spec/block_docs/lists_nested.md +44 -0
- data/spec/block_docs/lists_nested_blankline.md +34 -0
- data/spec/block_docs/lists_nested_deep.md +43 -0
- data/spec/block_docs/lists_ol.md +129 -0
- data/spec/block_docs/lists_ol2.md +147 -0
- data/spec/block_docs/lists_paraindent.md +42 -0
- data/spec/block_docs/lists_tab.md +54 -0
- data/spec/block_docs/loss.md +17 -0
- data/spec/block_docs/math-blahtex/equations.md +29 -0
- data/spec/block_docs/math-blahtex/inline.md +48 -0
- data/spec/block_docs/math-blahtex/math2.md +52 -0
- data/spec/block_docs/math-blahtex/table.md +25 -0
- data/spec/block_docs/math/embedded_invalid_svg.md +108 -0
- data/spec/block_docs/math/embedded_svg.md +136 -0
- data/spec/block_docs/math/equations.md +49 -0
- data/spec/block_docs/math/inline.md +46 -0
- data/spec/block_docs/math/math2.md +53 -0
- data/{tests/unittest → spec/block_docs}/math/notmath.md +0 -12
- data/spec/block_docs/math/raw_mathml.md +87 -0
- data/spec/block_docs/math/spaces_after_inline_math.md +17 -0
- data/spec/block_docs/math/table.md +25 -0
- data/{tests/unittest → spec/block_docs}/math/table2.md +11 -23
- data/{tests/unittest → spec/block_docs}/misc_sw.md +184 -121
- data/{tests/unittest → spec/block_docs}/olist.md +6 -18
- data/{tests/unittest → spec/block_docs}/one.md +0 -12
- data/{tests/unittest → spec/block_docs}/paragraph.md +0 -12
- data/{tests/unittest → spec/block_docs}/paragraph_rules/dont_merge_ref.md +4 -12
- data/{tests/unittest → spec/block_docs}/paragraph_rules/tab_is_blank.md +0 -12
- data/{tests/unittest → spec/block_docs}/paragraphs.md +1 -13
- data/{tests/unittest → spec/block_docs}/recover/recover_links.md +4 -16
- data/{tests/unittest/pending/ref.md → spec/block_docs/ref_with_period.md} +7 -16
- data/spec/block_docs/ref_with_title.md +22 -0
- data/{tests/unittest → spec/block_docs}/references/long_example.md +16 -23
- data/{tests/unittest → spec/block_docs}/references/spaces_and_numbers.md +0 -12
- data/{tests/unittest → spec/block_docs}/smartypants.md +24 -31
- data/{tests/unittest → spec/block_docs}/syntax_hl.md +13 -17
- data/{tests/unittest → spec/block_docs}/table_attributes.md +6 -20
- data/spec/block_docs/table_colspan.md +41 -0
- data/spec/block_docs/tables.md +47 -0
- data/spec/block_docs/tables2.md +74 -0
- data/{tests/unittest → spec/block_docs}/test.md +1 -13
- data/{tests/unittest/notyet → spec/block_docs}/ticks.md +1 -13
- data/spec/block_docs/toc.md +87 -0
- data/{tests/unittest/notyet → spec/block_docs}/triggering.md +14 -25
- data/{tests/unittest → spec/block_docs}/underscore_in_words.md +0 -12
- data/{tests/unittest → spec/block_docs}/wrapping.md +4 -16
- data/spec/block_docs/xml.md +33 -0
- data/spec/block_docs/xml3.md +24 -0
- data/spec/block_docs/xml_comments.md +32 -0
- data/{tests/unittest → spec/block_docs}/xml_instruction.md +9 -20
- data/spec/block_spec.rb +110 -0
- data/spec/cli_spec.rb +8 -0
- data/spec/span_spec.rb +263 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/to_html_utf8_spec.rb +13 -0
- metadata +218 -202
- data/Rakefile +0 -73
- data/bin/marudown +0 -29
- data/bin/marutest +0 -345
- data/docs/changelog.md +0 -334
- data/lib/maruku/errors_management.rb +0 -92
- data/lib/maruku/ext/math/latex_fix.rb +0 -12
- data/lib/maruku/input/parse_span_better.rb +0 -746
- data/lib/maruku/input/rubypants.rb +0 -225
- data/lib/maruku/input/type_detection.rb +0 -147
- data/lib/maruku/output/to_latex_entities.rb +0 -367
- data/lib/maruku/output/to_latex_strings.rb +0 -64
- data/lib/maruku/structures.rb +0 -167
- data/lib/maruku/structures_inspect.rb +0 -87
- data/lib/maruku/structures_iterators.rb +0 -61
- data/lib/maruku/tests/benchmark.rb +0 -82
- data/lib/maruku/tests/new_parser.rb +0 -373
- data/lib/maruku/tests/tests.rb +0 -136
- data/lib/maruku/usage/example1.rb +0 -33
- data/maruku_gem.rb +0 -33
- data/tests/bugs/code_in_links.md +0 -101
- data/tests/bugs/complex_escaping.md +0 -38
- data/tests/math/syntax.md +0 -46
- data/tests/math_usage/document.md +0 -13
- data/tests/others/abbreviations.md +0 -11
- data/tests/others/blank.md +0 -4
- data/tests/others/code.md +0 -5
- data/tests/others/code2.md +0 -8
- data/tests/others/code3.md +0 -16
- data/tests/others/email.md +0 -4
- data/tests/others/entities.md +0 -19
- data/tests/others/escaping.md +0 -16
- data/tests/others/extra_dl.md +0 -101
- data/tests/others/extra_header_id.md +0 -13
- data/tests/others/extra_table1.md +0 -40
- data/tests/others/footnotes.md +0 -17
- data/tests/others/headers.md +0 -10
- data/tests/others/hrule.md +0 -10
- data/tests/others/images.md +0 -20
- data/tests/others/inline_html.md +0 -42
- data/tests/others/links.md +0 -38
- data/tests/others/list1.md +0 -4
- data/tests/others/list2.md +0 -5
- data/tests/others/list3.md +0 -8
- data/tests/others/lists.md +0 -32
- data/tests/others/lists_after_paragraph.md +0 -44
- data/tests/others/lists_ol.md +0 -39
- data/tests/others/misc_sw.md +0 -105
- data/tests/others/one.md +0 -1
- data/tests/others/paragraphs.md +0 -13
- data/tests/others/sss06.md +0 -352
- data/tests/others/test.md +0 -4
- data/tests/s5/s5profiling.md +0 -48
- data/tests/unittest/bug_def.md +0 -28
- data/tests/unittest/email.md +0 -32
- data/tests/unittest/hang.md +0 -29
- data/tests/unittest/html2.md +0 -34
- data/tests/unittest/ie.md +0 -61
- data/tests/unittest/links2.md +0 -34
- data/tests/unittest/lists11.md +0 -28
- data/tests/unittest/lists6.md +0 -53
- data/tests/unittest/lists9.md +0 -76
- data/tests/unittest/lists_ol.md +0 -274
- data/tests/unittest/math/equations.md +0 -86
- data/tests/unittest/math/inline.md +0 -58
- data/tests/unittest/math/math2.md +0 -57
- data/tests/unittest/math/table.md +0 -37
- data/tests/unittest/notyet/header_after_par.md +0 -70
- data/tests/unittest/pending/empty_cells.md +0 -49
- data/tests/unittest/red_tests/abbrev.md +0 -1388
- data/tests/unittest/red_tests/lists7.md +0 -68
- data/tests/unittest/red_tests/lists7b.md +0 -128
- data/tests/unittest/red_tests/lists8.md +0 -76
- data/tests/unittest/red_tests/xml.md +0 -70
- data/tests/unittest/xml2.md +0 -31
- data/tests/unittest/xml3.md +0 -38
- data/tests/utf8-files/simple.md +0 -1
- data/unit_test_block.sh +0 -5
- data/unit_test_span.sh +0 -3
@@ -1,111 +1,91 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
# Returns the type of next line as a string
|
92
|
-
# breaks at first :definition
|
93
|
-
def tell_me_the_future
|
94
|
-
s = ""; num_e = 0;
|
95
|
-
for i in @lines_index..@lines.size-1
|
96
|
-
c = case @lines[i].md_type
|
97
|
-
when :text; "t"
|
98
|
-
when :empty; num_e+=1; "e"
|
99
|
-
when :definition; "d"
|
100
|
-
else "o"
|
101
|
-
end
|
102
|
-
s += c
|
103
|
-
break if c == "d" or num_e>1
|
104
|
-
end
|
105
|
-
s
|
106
|
-
end
|
107
|
-
|
108
|
-
end # linesource
|
109
|
-
|
110
|
-
end end end end # block
|
1
|
+
module MaRuKu::In::Markdown::BlockLevelParser
|
2
|
+
|
3
|
+
# This represents a source of lines that can be consumed.
|
4
|
+
#
|
5
|
+
# It is the twin of CharSource.
|
6
|
+
#
|
7
|
+
|
8
|
+
class LineSource
|
9
|
+
attr_reader :parent
|
10
|
+
|
11
|
+
def initialize(lines, parent=nil, parent_offset=nil)
|
12
|
+
raise "NIL lines? " unless lines
|
13
|
+
@lines = lines.map {|l| l.kind_of?(MaRuKu::MDLine) ? l : MaRuKu::MDLine.new(l) }
|
14
|
+
@lines_index = 0
|
15
|
+
@parent = parent
|
16
|
+
@parent_offset = parent_offset
|
17
|
+
end
|
18
|
+
|
19
|
+
def cur_line
|
20
|
+
@lines[@lines_index]
|
21
|
+
end
|
22
|
+
|
23
|
+
def next_line
|
24
|
+
@lines[@lines_index + 1]
|
25
|
+
end
|
26
|
+
|
27
|
+
def shift_line
|
28
|
+
raise "Over the rainbow" if @lines_index >= @lines.size
|
29
|
+
l = @lines[@lines_index]
|
30
|
+
@lines_index += 1
|
31
|
+
l
|
32
|
+
end
|
33
|
+
|
34
|
+
def ignore_line
|
35
|
+
raise "Over the rainbow" if @lines_index >= @lines.size
|
36
|
+
@lines_index += 1
|
37
|
+
end
|
38
|
+
|
39
|
+
def describe
|
40
|
+
s = "At line #{original_line_number(@lines_index)}\n"
|
41
|
+
|
42
|
+
context = 3 # lines
|
43
|
+
from = [@lines_index - context, 0].max
|
44
|
+
to = [@lines_index + context, @lines.size - 1].min
|
45
|
+
|
46
|
+
from.upto(to) do |i|
|
47
|
+
prefix = (i == @lines_index) ? '--> ' : ' ';
|
48
|
+
l = @lines[i]
|
49
|
+
s += "%10s %4s|%s" %
|
50
|
+
[@lines[i].md_type.to_s, prefix, l]
|
51
|
+
|
52
|
+
s += "|\n"
|
53
|
+
end
|
54
|
+
|
55
|
+
s
|
56
|
+
end
|
57
|
+
|
58
|
+
def original_line_number(index)
|
59
|
+
if @parent
|
60
|
+
index + @parent.original_line_number(@parent_offset)
|
61
|
+
else
|
62
|
+
1 + index
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def cur_index
|
67
|
+
@lines_index
|
68
|
+
end
|
69
|
+
|
70
|
+
# Returns the type of next line as a string
|
71
|
+
# breaks at first :definition
|
72
|
+
def tell_me_the_future
|
73
|
+
s = ""
|
74
|
+
num_e = 0
|
75
|
+
|
76
|
+
@lines_index.upto(@lines.size - 1) do |i|
|
77
|
+
c = case @lines[i].md_type
|
78
|
+
when :text; "t"
|
79
|
+
when :empty; num_e += 1; "e"
|
80
|
+
when :definition; "d"
|
81
|
+
else "o"
|
82
|
+
end
|
83
|
+
s << c
|
84
|
+
break if c == "d" or num_e > 1
|
85
|
+
end
|
86
|
+
s
|
87
|
+
end
|
88
|
+
|
89
|
+
end # linesource
|
90
|
+
end
|
111
91
|
|
@@ -0,0 +1,131 @@
|
|
1
|
+
# This code does the classification of lines for block-level parsing.
|
2
|
+
module MaRuKu
|
3
|
+
|
4
|
+
# Represents a single line in a Markdown source file, as produced by
|
5
|
+
# LineSource.
|
6
|
+
class MDLine < String
|
7
|
+
def md_type
|
8
|
+
@md_type ||= line_md_type
|
9
|
+
end
|
10
|
+
|
11
|
+
# Returns the number of leading spaces on this string,
|
12
|
+
# considering that a tab counts as {MaRuKu::Strings::TAB_SIZE} spaces.
|
13
|
+
#
|
14
|
+
# @param s [String]
|
15
|
+
# @return [Fixnum]
|
16
|
+
def number_of_leading_spaces
|
17
|
+
if self =~ /\A\s+/
|
18
|
+
spaces = $&
|
19
|
+
spaces.count(" ") + spaces.count("\t") * MaRuKu::Strings::TAB_SIZE
|
20
|
+
else
|
21
|
+
0
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def gsub!(*args)
|
26
|
+
# Any in-place-modification method should reset the md_type
|
27
|
+
@md_type = nil
|
28
|
+
super
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def line_md_type
|
34
|
+
# The order of evaluation is important (:text is a catch-all)
|
35
|
+
return :text if self =~ /\A[a-zA-Z]/
|
36
|
+
return :empty if self =~ /\A\s*\z/
|
37
|
+
return :footnote_text if self =~ FootnoteText
|
38
|
+
return :ref_definition if self =~ LinkRegex || self =~ IncompleteLink
|
39
|
+
return :abbreviation if self =~ Abbreviation
|
40
|
+
return :definition if self =~ Definition
|
41
|
+
# I had a bug with emails and urls at the beginning of the
|
42
|
+
# line that were mistaken for raw_html
|
43
|
+
return :text if self =~ /\A[ ]{0,3}#{EMailAddress}/
|
44
|
+
return :text if self =~ /\A[ ]{0,3}<\w+:\/\//
|
45
|
+
# raw html is like PHP Markdown Extra: at most three spaces before
|
46
|
+
return :xml_instr if self =~ /\A\s*<\?/
|
47
|
+
return :raw_html if self =~ %r{\A[ ]{0,3}</?\s*\w+}
|
48
|
+
return :raw_html if self =~ /\A[ ]{0,3}<\!\-\-/
|
49
|
+
return :header1 if self =~ /\A(=)+/
|
50
|
+
return :header2 if self =~ /\A([-\s])+\z/
|
51
|
+
return :header3 if self =~ /\A(#)+\s*\S+/
|
52
|
+
# at least three asterisks/hyphens/underscores on a line, and only whitespace
|
53
|
+
return :hrule if self =~ /\A(\s*[\*\-_]\s*){3,}\z/
|
54
|
+
return :ulist if self =~ /\A[ ]{0,3}([\*\-\+])\s+.*/
|
55
|
+
return :olist if self =~ /\A[ ]{0,3}\d+\.\s+.*/
|
56
|
+
return :code if number_of_leading_spaces >= 4
|
57
|
+
return :quote if self =~ /\A>/
|
58
|
+
return :ald if self =~ AttributeDefinitionList
|
59
|
+
return :ial if self =~ InlineAttributeList
|
60
|
+
return :text # else, it's just text
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# MacRuby has trouble with commented regexes, so just put the expanded form
|
65
|
+
# in a comment.
|
66
|
+
|
67
|
+
# $1 = id $2 = attribute list
|
68
|
+
AttributeDefinitionList = /\A\s{0,3}\{([\w\s]+)\}:\s*(.*?)\s*\z/
|
69
|
+
#
|
70
|
+
InlineAttributeList = /\A\s{0,3}\{([:#\.].*?)\}\s*\z/
|
71
|
+
# Example:
|
72
|
+
# ^:blah blah
|
73
|
+
# ^: blah blah
|
74
|
+
# ^ : blah blah
|
75
|
+
Definition = /\A[ ]{0,3}:\s*(\S.*)\z/
|
76
|
+
# %r{
|
77
|
+
# ^ # begin of line
|
78
|
+
# [ ]{0,3} # up to 3 spaces
|
79
|
+
# : # colon
|
80
|
+
# \s* # whitespace
|
81
|
+
# (\S.*) # the text = $1
|
82
|
+
# $ # end of line
|
83
|
+
# }x
|
84
|
+
|
85
|
+
# Example:
|
86
|
+
# *[HTML]: Hyper Text Markup Language
|
87
|
+
Abbreviation = /\A[ ]{0,3}\*\[([^\]]+)\]:\s*(\S.*\S)*\s*\z/
|
88
|
+
# %r{
|
89
|
+
# ^ # begin of line
|
90
|
+
# [ ]{0,3} # up to 3 spaces
|
91
|
+
# \* # one asterisk
|
92
|
+
# \[ # opening bracket
|
93
|
+
# ([^\]]+) # any non-closing bracket: id = $1
|
94
|
+
# \] # closing bracket
|
95
|
+
# : # colon
|
96
|
+
# \s* # whitespace
|
97
|
+
# (\S.*\S)* # definition=$2
|
98
|
+
# \s* # strip this whitespace
|
99
|
+
# $ # end of line
|
100
|
+
# }x
|
101
|
+
|
102
|
+
FootnoteText = /\A[ ]{0,3}\[(\^.+)\]:\s*(\S.*)?\z/
|
103
|
+
# %r{
|
104
|
+
# ^ # begin of line
|
105
|
+
# [ ]{0,3} # up to 3 spaces
|
106
|
+
# \[(\^.+)\]: # id = $1 (including '^')
|
107
|
+
# \s*(\S.*)?$ # text = $2 (not obb.)
|
108
|
+
# }x
|
109
|
+
|
110
|
+
# This regex is taken from BlueCloth sources
|
111
|
+
# Link defs are in the form: ^[id]: \n? url "optional title"
|
112
|
+
LinkRegex = /\A[ ]{0,3}\[([^\[\]]+)\]:[ ]*<?([^>\s]+)>?[ ]*(?:(?:(?:"([^"]+)")|(?:'([^']+)')|(?:\(([^\(\)]+)\)))\s*(.+)?)?/
|
113
|
+
#%r{
|
114
|
+
# ^[ ]{0,3}\[([^\[\]]+)\]: # id = $1
|
115
|
+
# [ ]*
|
116
|
+
# <?([^>\s]+)>? # url = $2
|
117
|
+
# [ ]*
|
118
|
+
# (?: # Titles are delimited by "quotes" or (parens).
|
119
|
+
# (?:(?:"([^"]+)")|(?:'([^']+)')|(?:\(([^\(\)]+)\))) # title = $3, $4, or $5
|
120
|
+
# \s*(.+)? # stuff = $6
|
121
|
+
# )? # title is optional
|
122
|
+
#}x
|
123
|
+
|
124
|
+
IncompleteLink = /\A[ ]{0,3}\[([^\[\]]+?)\]:\s*\z/
|
125
|
+
|
126
|
+
# Table syntax: http://michelf.ca/projects/php-markdown/extra/#table
|
127
|
+
# | -------------:| ------------------------------ |
|
128
|
+
TableSeparator = /\A(?>\|?\s*\:?\-+\:?\s*\|?)+?\z/
|
129
|
+
|
130
|
+
EMailAddress = /<([^:@>]+?@[^:@>]+?)>/
|
131
|
+
end
|
@@ -1,615 +1,738 @@
|
|
1
|
-
#--
|
2
|
-
# Copyright (C) 2006 Andrea Censi <andrea (at) rubyforge.org>
|
3
|
-
#
|
4
|
-
# This file is part of Maruku.
|
5
|
-
#
|
6
|
-
# Maruku is free software; you can redistribute it and/or modify
|
7
|
-
# it under the terms of the GNU General Public License as published by
|
8
|
-
# the Free Software Foundation; either version 2 of the License, or
|
9
|
-
# (at your option) any later version.
|
10
|
-
#
|
11
|
-
# Maruku is distributed in the hope that it will be useful,
|
12
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
-
# GNU General Public License for more details.
|
15
|
-
#
|
16
|
-
# You should have received a copy of the GNU General Public License
|
17
|
-
# along with Maruku; if not, write to the Free Software
|
18
|
-
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
19
|
-
#++
|
20
|
-
|
21
|
-
|
22
1
|
module MaRuKu; module In; module Markdown; module BlockLevelParser
|
23
2
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
#
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
#
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
#
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
end
|
3
|
+
include Helpers
|
4
|
+
include MaRuKu::Strings
|
5
|
+
include MaRuKu::In::Markdown::SpanLevelParser
|
6
|
+
|
7
|
+
class BlockContext < Array
|
8
|
+
def describe
|
9
|
+
n = 5
|
10
|
+
desc = size > n ? self[-n, n] : self
|
11
|
+
"Last #{n} elements: " +
|
12
|
+
desc.map {|x| "\n -" + x.inspect }.join
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# Splits the string and calls parse_lines_as_markdown
|
17
|
+
def parse_text_as_markdown(text)
|
18
|
+
lines = split_lines(text)
|
19
|
+
src = LineSource.new(lines)
|
20
|
+
parse_blocks(src)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Input is a LineSource
|
24
|
+
def parse_blocks(src)
|
25
|
+
output = BlockContext.new
|
26
|
+
|
27
|
+
# run state machine
|
28
|
+
while src.cur_line
|
29
|
+
next if check_block_extensions(src, output, src.cur_line)
|
30
|
+
|
31
|
+
md_type = src.cur_line.md_type
|
32
|
+
|
33
|
+
# Prints detected type (useful for debugging)
|
34
|
+
#puts "parse_blocks #{md_type}|#{src.cur_line}"
|
35
|
+
case md_type
|
36
|
+
when :empty
|
37
|
+
output << :empty
|
38
|
+
src.ignore_line
|
39
|
+
when :ial
|
40
|
+
m = InlineAttributeList.match src.shift_line
|
41
|
+
content = m[1] || ""
|
42
|
+
src2 = CharSource.new(content, src)
|
43
|
+
interpret_extension(src2, output)
|
44
|
+
when :ald
|
45
|
+
output << read_ald(src)
|
46
|
+
when :text
|
47
|
+
# paragraph, or table, or definition list
|
48
|
+
read_text_material(src, output)
|
49
|
+
when :header2, :hrule
|
50
|
+
# hrule
|
51
|
+
src.shift_line
|
52
|
+
output << md_hrule
|
53
|
+
when :header3
|
54
|
+
output << read_header3(src)
|
55
|
+
when :ulist, :olist
|
56
|
+
list_type = (md_type == :ulist) ? :ul : :ol
|
57
|
+
li = read_list_item(src)
|
58
|
+
# append to current list if we have one
|
59
|
+
if output.last.kind_of?(MDElement) &&
|
60
|
+
output.last.node_type == list_type then
|
61
|
+
output.last.children << li
|
62
|
+
else
|
63
|
+
output << md_el(list_type, li)
|
64
|
+
end
|
65
|
+
when :quote
|
66
|
+
output << read_quote(src)
|
67
|
+
when :code
|
68
|
+
e = read_code(src)
|
69
|
+
output << e if e
|
70
|
+
when :raw_html
|
71
|
+
# More extra hacky stuff - if there's more than just HTML, we either wrap it
|
72
|
+
# in a paragraph or break it up depending on whether it's an inline element or not
|
73
|
+
e = read_raw_html(src)
|
74
|
+
unless e.empty?
|
75
|
+
if e.first.parsed_html &&
|
76
|
+
(first_node_name = e.first.parsed_html.first_node_name) &&
|
77
|
+
HTML_INLINE_ELEMS.include?(first_node_name) &&
|
78
|
+
!%w(svg math).include?(first_node_name)
|
79
|
+
content = [e.first]
|
80
|
+
if e.size > 1
|
81
|
+
content.concat(e[1].children)
|
82
|
+
end
|
83
|
+
output << md_par(content)
|
84
|
+
else
|
85
|
+
output.concat(e)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
when :footnote_text
|
89
|
+
output << read_footnote_text(src)
|
90
|
+
when :ref_definition
|
91
|
+
if src.parent && src.cur_index == 0
|
92
|
+
read_text_material(src, output)
|
93
|
+
else
|
94
|
+
read_ref_definition(src, output)
|
95
|
+
end
|
96
|
+
when :abbreviation
|
97
|
+
output << read_abbreviation(src)
|
98
|
+
when :xml_instr
|
99
|
+
read_xml_instruction(src, output)
|
100
|
+
else # unhandled line type at this level
|
101
|
+
# Just treat it as raw text
|
102
|
+
read_text_material(src, output)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
merge_ial(output, src, output)
|
107
|
+
output.delete_if do |x|
|
108
|
+
# Strip out IAL
|
109
|
+
(x.kind_of?(MDElement) && x.node_type == :ial) ||
|
110
|
+
# get rid of empty line markers
|
111
|
+
x == :empty
|
112
|
+
end
|
113
|
+
|
114
|
+
# See for each list if we can omit the paragraphs
|
115
|
+
# TODO: do this after
|
116
|
+
output.each do |c|
|
117
|
+
# Remove paragraphs that we can get rid of
|
118
|
+
if [:ul, :ol].include?(c.node_type) && c.children.none?(&:want_my_paragraph)
|
119
|
+
c.children.each do |d|
|
120
|
+
if d.children.first && d.children.first.node_type == :paragraph
|
121
|
+
d.children = d.children.first.children + d.children[1..-1]
|
122
|
+
end
|
123
|
+
end
|
124
|
+
elsif c.node_type == :definition_list && c.children.none?(&:want_my_paragraph)
|
125
|
+
c.children.each do |definition|
|
126
|
+
definition.definitions.each do |dd|
|
127
|
+
if dd.children.first.node_type == :paragraph
|
128
|
+
dd.children = dd.children.first.children + dd.children[1..-1]
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
output
|
136
|
+
end
|
137
|
+
|
138
|
+
def read_text_material(src, output)
|
139
|
+
if src.cur_line.include?('|') && # if contains a pipe, it could be a table header
|
140
|
+
src.next_line &&
|
141
|
+
src.next_line.rstrip =~ TableSeparator
|
142
|
+
output << read_table(src)
|
143
|
+
elsif src.next_line && [:header1, :header2].include?(src.next_line.md_type)
|
144
|
+
output << read_header12(src)
|
145
|
+
elsif eventually_comes_a_def_list(src)
|
146
|
+
definition = read_definition(src)
|
147
|
+
if output.last.kind_of?(MDElement) &&
|
148
|
+
output.last.node_type == :definition_list then
|
149
|
+
output.last.children << definition
|
150
|
+
else
|
151
|
+
output << md_el(:definition_list, definition)
|
152
|
+
end
|
153
|
+
else # Start of a paragraph
|
154
|
+
output.concat read_paragraph(src)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def read_ald(src)
|
159
|
+
if (l = src.shift_line) =~ AttributeDefinitionList
|
160
|
+
id = $1
|
161
|
+
al = read_attribute_list(CharSource.new($2, src))
|
162
|
+
self.ald[id] = al;
|
163
|
+
md_ald(id, al)
|
164
|
+
else
|
165
|
+
maruku_error "Bug Bug:\n#{l.inspect}"
|
166
|
+
nil
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
# reads a header (with ----- or ========)
|
171
|
+
def read_header12(src)
|
172
|
+
line = src.shift_line.strip
|
173
|
+
al = nil
|
174
|
+
# Check if there is an IAL
|
175
|
+
if new_meta_data? and line =~ /^(.*?)\{(.*?)\}\s*$/
|
176
|
+
line = $1.strip
|
177
|
+
ial = $2
|
178
|
+
al = read_attribute_list(CharSource.new(ial, src))
|
179
|
+
end
|
180
|
+
text = parse_span line
|
181
|
+
if text.empty?
|
182
|
+
text = "{#{ial}}"
|
183
|
+
al = nil
|
184
|
+
end
|
185
|
+
level = src.cur_line.md_type == :header2 ? 2 : 1;
|
186
|
+
src.shift_line
|
187
|
+
md_header(level, text, al)
|
188
|
+
end
|
189
|
+
|
190
|
+
# reads a header like '#### header ####'
|
191
|
+
def read_header3(src)
|
192
|
+
line = src.shift_line.strip
|
193
|
+
al = nil
|
194
|
+
# Check if there is an IAL
|
195
|
+
if new_meta_data? and line =~ /^(.*?)\{(.*?)\}\s*$/
|
196
|
+
line = $1.strip
|
197
|
+
ial = $2
|
198
|
+
al = read_attribute_list(CharSource.new(ial, src))
|
199
|
+
end
|
200
|
+
level = line[/^#+/].size
|
201
|
+
if level > 6
|
202
|
+
text = parse_span line
|
203
|
+
return md_par(text, al)
|
204
|
+
end
|
205
|
+
text = parse_span line.gsub(/\A#+|#+\z/, '')
|
206
|
+
if text.empty?
|
207
|
+
text = "{#{ial}}"
|
208
|
+
al = nil
|
209
|
+
end
|
210
|
+
md_header(level, text, al)
|
211
|
+
end
|
212
|
+
|
213
|
+
def read_xml_instruction(src, output)
|
214
|
+
m = /^\s*<\?((\w+)\s*)?(.*)$/.match src.shift_line
|
215
|
+
raise "BugBug" unless m
|
216
|
+
target = m[2] || ''
|
217
|
+
code = m[3]
|
218
|
+
until code.include?('?>')
|
219
|
+
code << "\n" << src.shift_line
|
220
|
+
end
|
221
|
+
unless code =~ /\?>\s*$/
|
222
|
+
garbage = (/\?>(.*)$/.match(code))[1]
|
223
|
+
maruku_error "Trailing garbage on last line: #{garbage.inspect}:\n" +
|
224
|
+
code.gsub(/^/, '|'), src
|
225
|
+
end
|
226
|
+
code.gsub!(/\?>\s*$/, '')
|
227
|
+
|
228
|
+
if target == 'mrk' && MaRuKu::Globals[:unsafe_features]
|
229
|
+
result = safe_execute_code(self, code)
|
230
|
+
if result
|
231
|
+
if result.kind_of? String
|
232
|
+
raise "Not expected"
|
233
|
+
else
|
234
|
+
output.push(*result)
|
235
|
+
end
|
236
|
+
end
|
237
|
+
else
|
238
|
+
output << md_xml_instr(target, code)
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
def read_raw_html(src)
|
243
|
+
extra_line = nil
|
244
|
+
h = HTMLHelper.new
|
245
|
+
begin
|
246
|
+
l = src.shift_line
|
247
|
+
h.eat_this(l)
|
248
|
+
# puts "\nBLOCK:\nhtml -> #{l.inspect}"
|
249
|
+
while src.cur_line && !h.is_finished?
|
250
|
+
l = src.shift_line
|
251
|
+
# puts "html -> #{l.inspect}"
|
252
|
+
h.eat_this "\n" + l
|
253
|
+
end
|
254
|
+
rescue => e
|
255
|
+
maruku_error "Bad block-level HTML:\n#{e.inspect.gsub(/^/, '|')}\n", src
|
256
|
+
end
|
257
|
+
unless h.rest =~ /^\s*$/
|
258
|
+
extra_line = h.rest
|
259
|
+
end
|
260
|
+
raw_html = h.stuff_you_read
|
261
|
+
|
262
|
+
is_inline = HTML_INLINE_ELEMS.include?(h.first_tag)
|
263
|
+
|
264
|
+
if extra_line
|
265
|
+
remainder = is_inline ? parse_span(extra_line) : parse_text_as_markdown(extra_line)
|
266
|
+
if extra_line.start_with?(' ')
|
267
|
+
remainder[0] = ' ' + remainder[0] if remainder[0].is_a?(String)
|
268
|
+
end
|
269
|
+
is_inline ? [md_html(raw_html), md_par(remainder)] : [md_html(raw_html)] + remainder
|
270
|
+
else
|
271
|
+
[md_html(raw_html)]
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
def read_paragraph(src)
|
276
|
+
lines = [src.shift_line]
|
277
|
+
while src.cur_line
|
278
|
+
# :olist does not break
|
279
|
+
case t = src.cur_line.md_type
|
280
|
+
when :quote, :header3, :empty, :ref_definition, :ial, :xml_instr
|
281
|
+
break
|
282
|
+
end
|
283
|
+
break if src.cur_line.strip.empty?
|
284
|
+
break if src.next_line && [:header1, :header2].include?(src.next_line.md_type)
|
285
|
+
break if any_matching_block_extension?(src.cur_line)
|
286
|
+
|
287
|
+
lines << src.shift_line
|
288
|
+
end
|
289
|
+
children = parse_span(lines, src)
|
290
|
+
|
291
|
+
pick_apart_non_inline_html(children)
|
292
|
+
end
|
293
|
+
|
294
|
+
# If there are non-inline HTML tags in the paragraph, break them out into
|
295
|
+
# their own elements and make paragraphs out of everything else.
|
296
|
+
def pick_apart_non_inline_html(children)
|
297
|
+
output = []
|
298
|
+
para_children = []
|
299
|
+
|
300
|
+
children.each do |child|
|
301
|
+
if element_is_non_inline_html?(child)
|
302
|
+
unless para_children.empty?
|
303
|
+
# Fix up paragraphs before non-inline elements having an extra space
|
304
|
+
last_child = para_children.last
|
305
|
+
if last_child.is_a?(String) && !last_child.empty?
|
306
|
+
last_child.replace last_child[0..-2]
|
307
|
+
end
|
308
|
+
|
309
|
+
output << md_par(para_children)
|
310
|
+
para_children = []
|
311
|
+
end
|
312
|
+
output << child
|
313
|
+
else
|
314
|
+
para_children << child
|
315
|
+
end
|
316
|
+
end
|
317
|
+
|
318
|
+
unless para_children.empty?
|
319
|
+
output << md_par(para_children)
|
320
|
+
end
|
321
|
+
|
322
|
+
output
|
323
|
+
end
|
324
|
+
|
325
|
+
# Is the given element an HTML element whose root is not an inline element?
|
326
|
+
def element_is_non_inline_html?(elem)
|
327
|
+
if elem.is_a?(MDElement) && elem.node_type == :raw_html && elem.parsed_html
|
328
|
+
first_node_name = elem.parsed_html.first_node_name
|
329
|
+
first_node_name && !HTML_INLINE_ELEMS.include?(elem.parsed_html.first_node_name)
|
330
|
+
else
|
331
|
+
false
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
335
|
+
# Reads one list item, either ordered or unordered.
|
336
|
+
def read_list_item(src)
|
337
|
+
parent_offset = src.cur_index
|
338
|
+
|
339
|
+
item_type = src.cur_line.md_type
|
340
|
+
first = src.shift_line
|
341
|
+
|
342
|
+
indentation, ial = spaces_before_first_char(first)
|
343
|
+
al = read_attribute_list(CharSource.new(ial, src)) if ial
|
344
|
+
ial_offset = ial ? ial.length + 3 : 0
|
345
|
+
lines, want_my_paragraph = read_indented_content(src, indentation, [], item_type, ial_offset)
|
346
|
+
|
347
|
+
# in case there is a second line and this line starts a new list, format it.
|
348
|
+
if !lines.empty? && [:ulist, :olist].include?(MaRuKu::MDLine.new(lines.first).md_type)
|
349
|
+
lines.unshift ""
|
350
|
+
end
|
351
|
+
|
352
|
+
# add first line
|
353
|
+
# Strip first '*', '-', '+' from first line
|
354
|
+
first_changed = first.gsub(/([^\t]*)(\t)/) { $1 + " " * (TAB_SIZE - $1.length % TAB_SIZE) }
|
355
|
+
stripped = first_changed[indentation, first_changed.size - 1]
|
356
|
+
lines.unshift stripped
|
357
|
+
src2 = LineSource.new(lines, src, parent_offset)
|
358
|
+
children = parse_blocks(src2)
|
359
|
+
|
360
|
+
md_li(children, want_my_paragraph, al)
|
361
|
+
end
|
362
|
+
|
363
|
+
def read_abbreviation(src)
|
364
|
+
unless (l = src.shift_line) =~ Abbreviation
|
365
|
+
maruku_error "Bug: it's Andrea's fault. Tell him.\n#{l.inspect}"
|
366
|
+
end
|
367
|
+
|
368
|
+
abbr = $1
|
369
|
+
desc = $2
|
370
|
+
|
371
|
+
if !abbr || abbr.empty?
|
372
|
+
maruku_error "Bad abbrev. abbr=#{abbr.inspect} desc=#{desc.inspect}"
|
373
|
+
end
|
374
|
+
|
375
|
+
self.abbreviations[abbr] = desc
|
376
|
+
|
377
|
+
md_abbr_def(abbr, desc)
|
378
|
+
end
|
379
|
+
|
380
|
+
def read_footnote_text(src)
|
381
|
+
parent_offset = src.cur_index
|
382
|
+
|
383
|
+
first = src.shift_line
|
384
|
+
|
385
|
+
unless first =~ FootnoteText
|
386
|
+
maruku_error "Bug (it's Andrea's fault)"
|
387
|
+
end
|
388
|
+
|
389
|
+
id = $1
|
390
|
+
text = $2 || ''
|
391
|
+
|
392
|
+
indentation = 4 #first.size-text.size
|
393
|
+
|
394
|
+
# puts "id =_#{id}_; text=_#{text}_ indent=#{indentation}"
|
395
|
+
|
396
|
+
break_list = [:footnote_text, :ref_definition, :definition, :abbreviation]
|
397
|
+
item_type = :footnote_text
|
398
|
+
lines, _ = read_indented_content(src, indentation, break_list, item_type)
|
399
|
+
|
400
|
+
# add first line
|
401
|
+
lines.unshift text unless text.strip.empty?
|
402
|
+
|
403
|
+
src2 = LineSource.new(lines, src, parent_offset)
|
404
|
+
children = parse_blocks(src2)
|
405
|
+
|
406
|
+
e = md_footnote(id, children)
|
407
|
+
self.footnotes[id] = e
|
408
|
+
e
|
409
|
+
end
|
410
|
+
|
411
|
+
|
412
|
+
# This is the only ugly function in the code base.
|
413
|
+
# It is used to read list items, descriptions, footnote text
|
414
|
+
def read_indented_content(src, indentation, break_list, item_type, ial_offset=0)
|
415
|
+
lines = []
|
416
|
+
# collect all indented lines
|
417
|
+
saw_empty = false
|
418
|
+
saw_anything_after = false
|
419
|
+
break_list = Array(break_list)
|
420
|
+
len = indentation - ial_offset
|
421
|
+
|
422
|
+
while src.cur_line
|
423
|
+
num_leading_spaces = src.cur_line.number_of_leading_spaces
|
424
|
+
break if num_leading_spaces < len && ![:text, :empty, :code].include?(src.cur_line.md_type)
|
425
|
+
|
426
|
+
line = strip_indent(src.cur_line, indentation)
|
427
|
+
md_type = line.md_type
|
428
|
+
|
429
|
+
if md_type == :empty
|
430
|
+
saw_empty = true
|
431
|
+
lines << line
|
432
|
+
src.shift_line
|
433
|
+
next
|
434
|
+
end
|
435
|
+
|
436
|
+
# Unquestioningly grab anything that's deeper-indented
|
437
|
+
if md_type != :code && num_leading_spaces > len
|
438
|
+
lines << line
|
439
|
+
src.shift_line
|
440
|
+
next
|
441
|
+
end
|
442
|
+
|
443
|
+
# after a white line
|
444
|
+
if saw_empty
|
445
|
+
# we expect things to be properly aligned
|
446
|
+
break if num_leading_spaces < len
|
447
|
+
saw_anything_after = true
|
448
|
+
else
|
449
|
+
break if break_list.include?(md_type)
|
450
|
+
end
|
451
|
+
|
452
|
+
if md_type == :code && num_leading_spaces > len+6
|
453
|
+
lines << strip_indent(src.cur_line, num_leading_spaces-4)
|
454
|
+
src.shift_line
|
455
|
+
next
|
456
|
+
end
|
457
|
+
|
458
|
+
lines << line
|
459
|
+
src.shift_line
|
460
|
+
|
461
|
+
# You are only required to indent the first line of
|
462
|
+
# a child paragraph.
|
463
|
+
if md_type == :text
|
464
|
+
while src.cur_line && src.cur_line.md_type == :text
|
465
|
+
lines << strip_indent(src.shift_line, indentation)
|
466
|
+
end
|
467
|
+
end
|
468
|
+
end
|
469
|
+
|
470
|
+
# TODO fix this
|
471
|
+
want_my_paragraph = saw_anything_after ||
|
472
|
+
(saw_empty && src.cur_line && src.cur_line.md_type == item_type)
|
473
|
+
|
474
|
+
# create a new context
|
475
|
+
|
476
|
+
while lines.last && lines.last.md_type == :empty
|
477
|
+
lines.pop
|
478
|
+
end
|
479
|
+
|
480
|
+
return lines, want_my_paragraph
|
481
|
+
end
|
482
|
+
|
483
|
+
|
484
|
+
def read_quote(src)
|
485
|
+
parent_offset = src.cur_index
|
486
|
+
|
487
|
+
lines = []
|
488
|
+
# collect all indented lines
|
489
|
+
while src.cur_line && ( [:text, :quote].include?(src.cur_line.md_type) or
|
490
|
+
src.cur_line.md_type == :empty && ( src.next_line && src.next_line.md_type == :quote ) )
|
491
|
+
lines << unquote(src.shift_line)
|
492
|
+
end
|
493
|
+
|
494
|
+
src2 = LineSource.new(lines, src, parent_offset)
|
495
|
+
children = parse_blocks(src2)
|
496
|
+
md_quote(children)
|
497
|
+
end
|
498
|
+
|
499
|
+
def read_code(src)
|
500
|
+
# collect all indented lines
|
501
|
+
lines = []
|
502
|
+
while src.cur_line && [:code, :empty].include?(src.cur_line.md_type)
|
503
|
+
lines << strip_indent(src.shift_line, 4)
|
504
|
+
end
|
505
|
+
|
506
|
+
#while lines.last && (lines.last.md_type == :empty )
|
507
|
+
while lines.last && lines.last.strip.size == 0
|
508
|
+
lines.pop
|
509
|
+
end
|
510
|
+
|
511
|
+
while lines.first && lines.first.strip.size == 0
|
512
|
+
lines.shift
|
513
|
+
end
|
514
|
+
|
515
|
+
return nil if lines.empty?
|
516
|
+
|
517
|
+
source = lines.join("\n")
|
518
|
+
|
519
|
+
md_codeblock(source)
|
520
|
+
end
|
521
|
+
|
522
|
+
def read_ref_definition(src, out)
|
523
|
+
line = src.shift_line
|
524
|
+
|
525
|
+
# if link is incomplete, shift next line
|
526
|
+
if src.cur_line &&
|
527
|
+
![:footnote_text, :ref_definition, :definition, :abbreviation].include?(src.cur_line.md_type) &&
|
528
|
+
(1..3).include?(src.cur_line.number_of_leading_spaces)
|
529
|
+
line << " " << src.shift_line
|
530
|
+
end
|
531
|
+
|
532
|
+
match = LinkRegex.match(line)
|
533
|
+
unless match
|
534
|
+
maruku_error "Link does not respect format: '#{line}'" and return
|
535
|
+
end
|
536
|
+
|
537
|
+
id = match[1]
|
538
|
+
url = match[2]
|
539
|
+
title = match[3] || match[4] || match[5]
|
540
|
+
id = sanitize_ref_id(id)
|
541
|
+
|
542
|
+
hash = self.refs[id] = {
|
543
|
+
:url => url,
|
544
|
+
:title => title
|
545
|
+
}
|
546
|
+
|
547
|
+
stuff = (match[6] || '')
|
548
|
+
stuff.split.each do |couple|
|
549
|
+
k, v = couple.split('=')
|
550
|
+
v ||= ""
|
551
|
+
v = v[1..-2] if v.start_with?('"') # strip quotes
|
552
|
+
hash[k.to_sym] = v
|
553
|
+
end
|
554
|
+
|
555
|
+
out << md_ref_def(id, url, :title => title)
|
556
|
+
end
|
557
|
+
|
558
|
+
def split_cells(s, allowBlank = false)
|
559
|
+
if allowBlank
|
560
|
+
if /^[|].*[|]$/ =~ s # handle the simple and decorated table cases
|
561
|
+
s.split('|', -1)[1..-2] # allow blank cells, but only keep the inner elements of the cells
|
562
|
+
elsif /^.*[|]$/ =~ s
|
563
|
+
s.split('|', -1)[0..-2] # allow blank cells, but only keep the inner elements of the cells
|
564
|
+
else
|
565
|
+
s.split('|', -1)
|
566
|
+
end
|
567
|
+
else
|
568
|
+
s.split('|').reject(&:empty?).map(&:strip)
|
569
|
+
end
|
570
|
+
end
|
571
|
+
|
572
|
+
def read_table(src)
|
573
|
+
head = split_cells(src.shift_line).map do |s|
|
574
|
+
md_el(:head_cell, parse_span(s))
|
575
|
+
end
|
576
|
+
|
577
|
+
separator = split_cells(src.shift_line)
|
578
|
+
|
579
|
+
align = separator.map do |s|
|
580
|
+
# ex: :-------------------:
|
581
|
+
# If the separator starts and ends with a colon,
|
582
|
+
# center the cell. If it's on the right, right-align,
|
583
|
+
# otherwise left-align.
|
584
|
+
starts = s.start_with? ':'
|
585
|
+
ends = s.end_with? ':'
|
586
|
+
if s.empty? # blank
|
587
|
+
nil
|
588
|
+
elsif starts && ends
|
589
|
+
:center
|
590
|
+
elsif ends
|
591
|
+
:right
|
592
|
+
else
|
593
|
+
:left
|
594
|
+
end
|
595
|
+
end
|
596
|
+
|
597
|
+
align.pop if align[-1].nil? # trailing blank
|
598
|
+
num_columns = align.size
|
599
|
+
|
600
|
+
head.pop if head.size == num_columns + 1 && head[-1].al.size == 0 # trailing blank
|
601
|
+
|
602
|
+
if head.size != num_columns
|
603
|
+
maruku_error "Table head does not have #{num_columns} columns: \n#{head.inspect}"
|
604
|
+
tell_user "I will ignore this table."
|
605
|
+
# XXX try to recover
|
606
|
+
return md_br
|
607
|
+
end
|
608
|
+
|
609
|
+
rows = []
|
610
|
+
while src.cur_line && src.cur_line.include?('|')
|
611
|
+
row = []
|
612
|
+
colCount = 0
|
613
|
+
colspan = 1
|
614
|
+
currElem = nil
|
615
|
+
currIdx = 0
|
616
|
+
split_cells(src.shift_line, true).map do |s|
|
617
|
+
if s.empty?
|
618
|
+
# empty cells increase the colspan of the previous cell
|
619
|
+
found = false
|
620
|
+
colspan += 1
|
621
|
+
al = (currElem &&currElem.al) || AttributeList.new
|
622
|
+
if al.size > 0
|
623
|
+
elem = find_colspan(al)
|
624
|
+
if elem != nil
|
625
|
+
elem[1] = colspan.to_s
|
626
|
+
found = true
|
627
|
+
end
|
628
|
+
end
|
629
|
+
al.push(["colspan", colspan.to_s]) unless found # also handles the case of and empty attribute list
|
630
|
+
else
|
631
|
+
colspan = 1
|
632
|
+
row[currIdx] = md_el(:cell, parse_span(s))
|
633
|
+
currElem = row[currIdx]
|
634
|
+
currIdx += 1
|
635
|
+
end
|
636
|
+
end
|
637
|
+
|
638
|
+
#
|
639
|
+
# sanity check - make sure the current row has the right number of columns (including spans)
|
640
|
+
# If not, dump the table and return a break
|
641
|
+
#
|
642
|
+
num_columns = count_columns(row)
|
643
|
+
if num_columns == head.size + 1 && row[-1].al.size == 0 #trailing blank cell
|
644
|
+
row.pop
|
645
|
+
num_columns -= 1
|
646
|
+
end
|
647
|
+
if head.size != num_columns
|
648
|
+
maruku_error "Row does not have #{head.size} columns: \n#{row.inspect} - #{num_columns}"
|
649
|
+
tell_user "I will ignore this table."
|
650
|
+
# XXX need to recover
|
651
|
+
return md_br
|
652
|
+
end
|
653
|
+
rows << row
|
654
|
+
end
|
655
|
+
rows.unshift(head) # put the header row on the processed table
|
656
|
+
md_el(:table, rows, { :align => align })
|
657
|
+
end
|
658
|
+
|
659
|
+
#
|
660
|
+
# count the actual number of elements in a row taking into account colspans
|
661
|
+
#
|
662
|
+
def count_columns(row)
|
663
|
+
colCount = 0
|
664
|
+
|
665
|
+
row.each do |cell|
|
666
|
+
if cell.al && cell.al.size > 0
|
667
|
+
al = find_colspan(cell.al)
|
668
|
+
if al != nil
|
669
|
+
colCount += al[1].to_i
|
670
|
+
else
|
671
|
+
colCount += 1
|
672
|
+
end
|
673
|
+
else
|
674
|
+
colCount += 1
|
675
|
+
end
|
676
|
+
end
|
677
|
+
|
678
|
+
colCount
|
679
|
+
end
|
680
|
+
|
681
|
+
#
|
682
|
+
# Search an attribute list looking for a colspan
|
683
|
+
#
|
684
|
+
def find_colspan(al)
|
685
|
+
al.find {|alElem| alElem[0] == "colspan" }
|
686
|
+
end
|
687
|
+
|
688
|
+
# If current line is text, a definition list is coming
|
689
|
+
# if 1) text,empty,[text,empty]*,definition
|
690
|
+
def eventually_comes_a_def_list(src)
|
691
|
+
src.tell_me_the_future =~ %r{^t+e?d}x
|
692
|
+
end
|
693
|
+
|
694
|
+
def read_definition(src)
|
695
|
+
# Read one or more terms
|
696
|
+
terms = []
|
697
|
+
while src.cur_line && src.cur_line.md_type == :text
|
698
|
+
terms << md_el(:definition_term, parse_span(src.shift_line))
|
699
|
+
end
|
700
|
+
|
701
|
+
want_my_paragraph = false
|
702
|
+
|
703
|
+
raise "Chunky Bacon!" unless src.cur_line
|
704
|
+
|
705
|
+
# one optional empty
|
706
|
+
if src.cur_line.md_type == :empty
|
707
|
+
want_my_paragraph = true
|
708
|
+
src.shift_line
|
709
|
+
end
|
710
|
+
|
711
|
+
raise "Chunky Bacon!" unless src.cur_line.md_type == :definition
|
712
|
+
|
713
|
+
# Read one or more definitions
|
714
|
+
definitions = []
|
715
|
+
while src.cur_line && src.cur_line.md_type == :definition
|
716
|
+
parent_offset = src.cur_index
|
717
|
+
|
718
|
+
first = src.shift_line
|
719
|
+
first =~ Definition
|
720
|
+
first = $1
|
721
|
+
|
722
|
+
lines, w_m_p = read_indented_content(src, 4, :definition, :definition)
|
723
|
+
want_my_paragraph ||= w_m_p
|
724
|
+
|
725
|
+
lines.unshift first
|
726
|
+
|
727
|
+
src2 = LineSource.new(lines, src, parent_offset)
|
728
|
+
children = parse_blocks(src2)
|
729
|
+
definitions << md_el(:definition_data, children)
|
730
|
+
end
|
731
|
+
|
732
|
+
md_el(:definition, terms + definitions, {
|
733
|
+
:terms => terms,
|
734
|
+
:definitions => definitions,
|
735
|
+
:want_my_paragraph => want_my_paragraph
|
736
|
+
})
|
737
|
+
end
|
738
|
+
end end end end
|