remi-maruku 0.5.9
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +73 -0
- data/bin/marudown +29 -0
- data/bin/maruku +176 -0
- data/bin/marutest +338 -0
- data/bin/marutex +31 -0
- data/docs/changelog.md +334 -0
- data/docs/div_syntax.md +36 -0
- data/docs/entity_test.md +23 -0
- data/docs/markdown_syntax.md +899 -0
- data/docs/maruku.md +346 -0
- data/docs/math.md +194 -0
- data/docs/other_stuff.md +51 -0
- data/docs/proposal.md +309 -0
- data/lib/maruku.rb +141 -0
- data/lib/maruku/attributes.rb +227 -0
- data/lib/maruku/defaults.rb +70 -0
- data/lib/maruku/errors_management.rb +92 -0
- data/lib/maruku/ext/div.rb +100 -0
- data/lib/maruku/ext/math.rb +41 -0
- data/lib/maruku/ext/math/elements.rb +27 -0
- data/lib/maruku/ext/math/latex_fix.rb +11 -0
- data/lib/maruku/ext/math/mathml_engines/blahtex.rb +104 -0
- data/lib/maruku/ext/math/mathml_engines/itex2mml.rb +29 -0
- data/lib/maruku/ext/math/mathml_engines/none.rb +20 -0
- data/lib/maruku/ext/math/mathml_engines/ritex.rb +24 -0
- data/lib/maruku/ext/math/parsing.rb +105 -0
- data/lib/maruku/ext/math/to_html.rb +170 -0
- data/lib/maruku/ext/math/to_latex.rb +22 -0
- data/lib/maruku/helpers.rb +260 -0
- data/lib/maruku/input/charsource.rb +326 -0
- data/lib/maruku/input/extensions.rb +69 -0
- data/lib/maruku/input/html_helper.rb +189 -0
- data/lib/maruku/input/linesource.rb +111 -0
- data/lib/maruku/input/parse_block.rb +613 -0
- data/lib/maruku/input/parse_doc.rb +227 -0
- data/lib/maruku/input/parse_span_better.rb +732 -0
- data/lib/maruku/input/rubypants.rb +225 -0
- data/lib/maruku/input/type_detection.rb +144 -0
- data/lib/maruku/input_textile2/t2_parser.rb +163 -0
- data/lib/maruku/maruku.rb +33 -0
- data/lib/maruku/output/s5/fancy.rb +756 -0
- data/lib/maruku/output/s5/to_s5.rb +125 -0
- data/lib/maruku/output/to_html.rb +971 -0
- data/lib/maruku/output/to_latex.rb +563 -0
- data/lib/maruku/output/to_latex_entities.rb +367 -0
- data/lib/maruku/output/to_latex_strings.rb +64 -0
- data/lib/maruku/output/to_markdown.rb +164 -0
- data/lib/maruku/output/to_s.rb +53 -0
- data/lib/maruku/string_utils.rb +191 -0
- data/lib/maruku/structures.rb +165 -0
- data/lib/maruku/structures_inspect.rb +87 -0
- data/lib/maruku/structures_iterators.rb +61 -0
- data/lib/maruku/tests/benchmark.rb +82 -0
- data/lib/maruku/tests/new_parser.rb +370 -0
- data/lib/maruku/tests/tests.rb +136 -0
- data/lib/maruku/textile2.rb +1 -0
- data/lib/maruku/toc.rb +199 -0
- data/lib/maruku/usage/example1.rb +33 -0
- data/lib/maruku/version.rb +40 -0
- data/tests/bugs/code_in_links.md +16 -0
- data/tests/bugs/complex_escaping.md +4 -0
- data/tests/math/syntax.md +46 -0
- data/tests/math_usage/document.md +13 -0
- data/tests/others/abbreviations.md +11 -0
- data/tests/others/blank.md +4 -0
- data/tests/others/code.md +5 -0
- data/tests/others/code2.md +8 -0
- data/tests/others/code3.md +16 -0
- data/tests/others/email.md +4 -0
- data/tests/others/entities.md +19 -0
- data/tests/others/escaping.md +16 -0
- data/tests/others/extra_dl.md +101 -0
- data/tests/others/extra_header_id.md +13 -0
- data/tests/others/extra_table1.md +40 -0
- data/tests/others/footnotes.md +17 -0
- data/tests/others/headers.md +10 -0
- data/tests/others/hrule.md +10 -0
- data/tests/others/images.md +20 -0
- data/tests/others/inline_html.md +42 -0
- data/tests/others/links.md +38 -0
- data/tests/others/list1.md +4 -0
- data/tests/others/list2.md +5 -0
- data/tests/others/list3.md +8 -0
- data/tests/others/lists.md +32 -0
- data/tests/others/lists_after_paragraph.md +44 -0
- data/tests/others/lists_ol.md +39 -0
- data/tests/others/misc_sw.md +105 -0
- data/tests/others/one.md +1 -0
- data/tests/others/paragraphs.md +13 -0
- data/tests/others/sss06.md +352 -0
- data/tests/others/test.md +4 -0
- data/tests/s5/s5profiling.md +48 -0
- data/tests/unittest/abbreviations.md +72 -0
- data/tests/unittest/alt.md +30 -0
- data/tests/unittest/attributes/att2.md +34 -0
- data/tests/unittest/attributes/att3.md +45 -0
- data/tests/unittest/attributes/attributes.md +82 -0
- data/tests/unittest/attributes/circular.md +43 -0
- data/tests/unittest/attributes/default.md +38 -0
- data/tests/unittest/blank.md +39 -0
- data/tests/unittest/blanks_in_code.md +106 -0
- data/tests/unittest/bug_def.md +29 -0
- data/tests/unittest/bug_table.md +67 -0
- data/tests/unittest/code.md +53 -0
- data/tests/unittest/code2.md +46 -0
- data/tests/unittest/code3.md +102 -0
- data/tests/unittest/data_loss.md +42 -0
- data/tests/unittest/divs/div1.md +204 -0
- data/tests/unittest/divs/div2.md +34 -0
- data/tests/unittest/divs/div3_nest.md +62 -0
- data/tests/unittest/easy.md +28 -0
- data/tests/unittest/email.md +33 -0
- data/tests/unittest/encoding/iso-8859-1.md +38 -0
- data/tests/unittest/encoding/utf-8.md +33 -0
- data/tests/unittest/entities.md +124 -0
- data/tests/unittest/escaping.md +89 -0
- data/tests/unittest/extra_dl.md +72 -0
- data/tests/unittest/extra_header_id.md +86 -0
- data/tests/unittest/extra_table1.md +55 -0
- data/tests/unittest/footnotes.md +126 -0
- data/tests/unittest/headers.md +54 -0
- data/tests/unittest/hex_entities.md +50 -0
- data/tests/unittest/hrule.md +60 -0
- data/tests/unittest/html2.md +38 -0
- data/tests/unittest/html3.md +47 -0
- data/tests/unittest/html4.md +42 -0
- data/tests/unittest/html5.md +38 -0
- data/tests/unittest/ie.md +82 -0
- data/tests/unittest/images.md +114 -0
- data/tests/unittest/images2.md +46 -0
- data/tests/unittest/inline_html.md +260 -0
- data/tests/unittest/inline_html2.md +36 -0
- data/tests/unittest/links.md +197 -0
- data/tests/unittest/list1.md +66 -0
- data/tests/unittest/list2.md +76 -0
- data/tests/unittest/list3.md +88 -0
- data/tests/unittest/list4.md +116 -0
- data/tests/unittest/lists.md +241 -0
- data/tests/unittest/lists11.md +31 -0
- data/tests/unittest/lists6.md +54 -0
- data/tests/unittest/lists7.md +79 -0
- data/tests/unittest/lists7b.md +136 -0
- data/tests/unittest/lists8.md +83 -0
- data/tests/unittest/lists9.md +85 -0
- data/tests/unittest/lists_after_paragraph.md +268 -0
- data/tests/unittest/lists_ol.md +324 -0
- data/tests/unittest/loss.md +29 -0
- data/tests/unittest/math/equations.md +69 -0
- data/tests/unittest/math/inline.md +66 -0
- data/tests/unittest/math/math2.md +110 -0
- data/tests/unittest/math/notmath.md +40 -0
- data/tests/unittest/math/table.md +43 -0
- data/tests/unittest/math/table2.md +60 -0
- data/tests/unittest/misc_sw.md +615 -0
- data/tests/unittest/notyet/escape.md +36 -0
- data/tests/unittest/notyet/header_after_par.md +81 -0
- data/tests/unittest/notyet/ticks.md +31 -0
- data/tests/unittest/notyet/triggering.md +206 -0
- data/tests/unittest/olist.md +64 -0
- data/tests/unittest/one.md +28 -0
- data/tests/unittest/paragraph.md +29 -0
- data/tests/unittest/paragraph_rules/dont_merge_ref.md +57 -0
- data/tests/unittest/paragraph_rules/tab_is_blank.md +39 -0
- data/tests/unittest/paragraphs.md +66 -0
- data/tests/unittest/pending/amps.md +29 -0
- data/tests/unittest/pending/empty_cells.md +53 -0
- data/tests/unittest/pending/link.md +103 -0
- data/tests/unittest/recover/recover_links.md +28 -0
- data/tests/unittest/references/long_example.md +88 -0
- data/tests/unittest/references/spaces_and_numbers.md +28 -0
- data/tests/unittest/smartypants.md +171 -0
- data/tests/unittest/syntax_hl.md +80 -0
- data/tests/unittest/table_attributes.md +52 -0
- data/tests/unittest/test.md +32 -0
- data/tests/unittest/wrapping.md +88 -0
- data/tests/unittest/xml.md +54 -0
- data/tests/unittest/xml2.md +34 -0
- data/tests/unittest/xml3.md +44 -0
- data/tests/unittest/xml_instruction.md +72 -0
- data/tests/utf8-files/simple.md +1 -0
- data/unit_test_block.sh +5 -0
- data/unit_test_span.sh +2 -0
- metadata +243 -0
@@ -0,0 +1,227 @@
|
|
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
|
+
class String
|
23
|
+
def quote_if_needed
|
24
|
+
if /[\s\'\"]/.match self
|
25
|
+
inspect
|
26
|
+
else
|
27
|
+
self
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
module MaRuKu;
|
33
|
+
MagicChar = ':'
|
34
|
+
|
35
|
+
class AttributeList < Array
|
36
|
+
|
37
|
+
# An attribute list becomes
|
38
|
+
# {#id .cl key="val" ref}
|
39
|
+
# [ [:id, 'id'], [:class, 'id'], ['key', 'val'], [ :ref, 'ref' ]]
|
40
|
+
|
41
|
+
private :push
|
42
|
+
|
43
|
+
def push_key_val(key, val);
|
44
|
+
raise "Bad #{key.inspect}=#{val.inspect}" if not key and val
|
45
|
+
push [key, val]
|
46
|
+
end
|
47
|
+
def push_ref(ref_id);
|
48
|
+
|
49
|
+
raise "Bad :ref #{ref_id.inspect}" if not ref_id
|
50
|
+
push [:ref, ref_id+""]
|
51
|
+
|
52
|
+
# p "Now ", self ########################################
|
53
|
+
end
|
54
|
+
def push_class(val);
|
55
|
+
raise "Bad :id #{val.inspect}" if not val
|
56
|
+
push [:class, val]
|
57
|
+
end
|
58
|
+
def push_id(val);
|
59
|
+
raise "Bad :id #{val.inspect}" if not val
|
60
|
+
push [:id, val]
|
61
|
+
end
|
62
|
+
|
63
|
+
def to_s
|
64
|
+
map do |k,v|
|
65
|
+
case k
|
66
|
+
when :id; "#" + v.quote_if_needed
|
67
|
+
when :class; "." + v.quote_if_needed
|
68
|
+
when :ref; v.quote_if_needed
|
69
|
+
else k.quote_if_needed + "=" + v.quote_if_needed
|
70
|
+
end
|
71
|
+
end . join(' ')
|
72
|
+
end
|
73
|
+
alias to_md to_s
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
module MaRuKu; module In; module Markdown; module SpanLevelParser
|
79
|
+
|
80
|
+
def unit_tests_for_attribute_lists
|
81
|
+
[
|
82
|
+
[ "", [], "Empty lists are allowed" ],
|
83
|
+
[ "=", :throw, "Bad char to begin a list with." ],
|
84
|
+
[ "a =b", :throw, "No whitespace before `=`." ],
|
85
|
+
[ "a= b", :throw, "No whitespace after `=`." ],
|
86
|
+
|
87
|
+
[ "a b", [[:ref, 'a'],[:ref, 'b']], "More than one ref" ],
|
88
|
+
[ "a b c", [[:ref, 'a'],[:ref, 'b'],[:ref, 'c']], "More than one ref" ],
|
89
|
+
[ "hello notfound", [[:ref, 'hello'],[:ref, 'notfound']]],
|
90
|
+
|
91
|
+
[ "'a'", [[:ref, 'a']], "Quoted value." ],
|
92
|
+
[ '"a"' ],
|
93
|
+
|
94
|
+
[ "a=b", [['a','b']], "Simple key/val" ],
|
95
|
+
[ "'a'=b" ],
|
96
|
+
[ "'a'='b'" ],
|
97
|
+
[ "a='b'" ],
|
98
|
+
|
99
|
+
[ 'a="b\'"', [['a',"b\'"]], "Key/val with quotes" ],
|
100
|
+
[ 'a=b\''],
|
101
|
+
[ 'a="\\\'b\'"', [['a',"\'b\'"]], "Key/val with quotes" ],
|
102
|
+
|
103
|
+
['"', :throw, "Unclosed quotes"],
|
104
|
+
["'"],
|
105
|
+
["'a "],
|
106
|
+
['"a '],
|
107
|
+
|
108
|
+
[ "#a", [[:id, 'a']], "Simple ID" ],
|
109
|
+
[ "#'a'" ],
|
110
|
+
[ '#"a"' ],
|
111
|
+
|
112
|
+
[ "#", :throw, "Unfinished '#'." ],
|
113
|
+
[ ".", :throw, "Unfinished '.'." ],
|
114
|
+
[ "# a", :throw, "No white-space after '#'." ],
|
115
|
+
[ ". a", :throw, "No white-space after '.' ." ],
|
116
|
+
|
117
|
+
[ "a=b c=d", [['a','b'],['c','d']], "Tabbing" ],
|
118
|
+
[ " \ta=b \tc='d' "],
|
119
|
+
[ "\t a=b\t c='d'\t\t"],
|
120
|
+
|
121
|
+
[ ".\"a'", :throw, "Mixing quotes is bad." ],
|
122
|
+
|
123
|
+
].map { |s, expected, comment|
|
124
|
+
@expected = (expected ||= @expected)
|
125
|
+
@comment = (comment ||= (last=@comment) )
|
126
|
+
(comment == last && (comment += (@count+=1).to_s)) || @count = 1
|
127
|
+
expected = [md_ial(expected)] if expected.kind_of? Array
|
128
|
+
["{#{MagicChar}#{s}}", expected, "Attributes: #{comment}"]
|
129
|
+
}
|
130
|
+
end
|
131
|
+
|
132
|
+
def md_al(s=[]); AttributeList.new(s) end
|
133
|
+
|
134
|
+
# returns nil or an AttributeList
|
135
|
+
def read_attribute_list(src, con, break_on_chars)
|
136
|
+
|
137
|
+
separators = break_on_chars + [?=,?\ ,?\t]
|
138
|
+
escaped = Maruku::EscapedCharInQuotes
|
139
|
+
|
140
|
+
al = AttributeList.new
|
141
|
+
while true
|
142
|
+
src.consume_whitespace
|
143
|
+
break if break_on_chars.include? src.cur_char
|
144
|
+
|
145
|
+
case src.cur_char
|
146
|
+
when nil
|
147
|
+
maruku_error "Attribute list terminated by EOF:\n "+
|
148
|
+
"#{al.inspect}" , src, con
|
149
|
+
tell_user "I try to continue and return partial attribute list:\n"+
|
150
|
+
al.inspect
|
151
|
+
break
|
152
|
+
when ?= # error
|
153
|
+
maruku_error "In attribute lists, cannot start identifier with `=`."
|
154
|
+
tell_user "I try to continue"
|
155
|
+
src.ignore_char
|
156
|
+
when ?# # id definition
|
157
|
+
src.ignore_char
|
158
|
+
if id = read_quoted_or_unquoted(src, con, escaped, separators)
|
159
|
+
al.push_id id
|
160
|
+
else
|
161
|
+
maruku_error 'Could not read `id` attribute.', src, con
|
162
|
+
tell_user 'Trying to ignore bad `id` attribute.'
|
163
|
+
end
|
164
|
+
when ?. # class definition
|
165
|
+
src.ignore_char
|
166
|
+
if klass = read_quoted_or_unquoted(src, con, escaped, separators)
|
167
|
+
al.push_class klass
|
168
|
+
else
|
169
|
+
maruku_error 'Could not read `class` attribute.', src, con
|
170
|
+
tell_user 'Trying to ignore bad `class` attribute.'
|
171
|
+
end
|
172
|
+
else
|
173
|
+
if key = read_quoted_or_unquoted(src, con, escaped, separators)
|
174
|
+
if src.cur_char == ?=
|
175
|
+
src.ignore_char # skip the =
|
176
|
+
if val = read_quoted_or_unquoted(src, con, escaped, separators)
|
177
|
+
al.push_key_val(key, val)
|
178
|
+
else
|
179
|
+
maruku_error "Could not read value for key #{key.inspect}.",
|
180
|
+
src, con
|
181
|
+
tell_user "Ignoring key #{key.inspect}."
|
182
|
+
end
|
183
|
+
else
|
184
|
+
al.push_ref key
|
185
|
+
end
|
186
|
+
else
|
187
|
+
maruku_error 'Could not read key or reference.'
|
188
|
+
end
|
189
|
+
end # case
|
190
|
+
end # while true
|
191
|
+
al
|
192
|
+
end
|
193
|
+
|
194
|
+
|
195
|
+
# We need a helper
|
196
|
+
def is_ial(e); e.kind_of? MDElement and e.node_type == :ial end
|
197
|
+
|
198
|
+
def merge_ial(elements, src, con)
|
199
|
+
|
200
|
+
# Apply each IAL to the element before
|
201
|
+
elements.each_with_index do |e, i|
|
202
|
+
if is_ial(e) && i>= 1 then
|
203
|
+
before = elements[i-1]
|
204
|
+
after = elements[i+1]
|
205
|
+
if before.kind_of? MDElement
|
206
|
+
before.al = e.ial
|
207
|
+
elsif after.kind_of? MDElement
|
208
|
+
after.al = e.ial
|
209
|
+
else
|
210
|
+
maruku_error "It is not clear to me what element this IAL {:#{e.ial.to_md}} \n"+
|
211
|
+
"is referring to. The element before is a #{before.class.to_s}, \n"+
|
212
|
+
"the element after is a #{after.class.to_s}.\n"+
|
213
|
+
"\n before: #{before.inspect}"+
|
214
|
+
"\n after: #{after.inspect}",
|
215
|
+
src, con
|
216
|
+
# xxx dire se c'è empty vicino
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
if not Globals[:debug_keep_ials]
|
222
|
+
elements.delete_if {|x| is_ial(x) unless x == elements.first}
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
end end end end
|
227
|
+
#module MaRuKu; module In; module Markdown; module SpanLevelParser
|
@@ -0,0 +1,70 @@
|
|
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
|
+
module MaRuKu
|
23
|
+
|
24
|
+
Globals = {
|
25
|
+
:unsafe_features => false,
|
26
|
+
:on_error => :warning,
|
27
|
+
|
28
|
+
|
29
|
+
:use_numbered_headers => false,
|
30
|
+
|
31
|
+
:maruku_signature => false,
|
32
|
+
:code_background_color => '#fef',
|
33
|
+
:code_show_spaces => false,
|
34
|
+
|
35
|
+
:filter_html => false,
|
36
|
+
|
37
|
+
:html_math_output_mathml => true, # also set :html_math_engine
|
38
|
+
:html_math_engine => 'none', #ritex, itex2mml
|
39
|
+
|
40
|
+
:html_math_output_png => false,
|
41
|
+
:html_png_engine => 'none',
|
42
|
+
:html_png_dir => 'pngs',
|
43
|
+
:html_png_url => 'pngs/',
|
44
|
+
:html_png_resolution => 200,
|
45
|
+
|
46
|
+
:html_use_syntax => false,
|
47
|
+
|
48
|
+
:latex_use_listings => false,
|
49
|
+
:latex_cjk => false,
|
50
|
+
|
51
|
+
:debug_keep_ials => false,
|
52
|
+
:doc_prefix => ''
|
53
|
+
}
|
54
|
+
|
55
|
+
class MDElement
|
56
|
+
def get_setting(sym)
|
57
|
+
if self.attributes.has_key?(sym) then
|
58
|
+
return self.attributes[sym]
|
59
|
+
elsif self.doc && self.doc.attributes.has_key?(sym) then
|
60
|
+
return self.doc.attributes[sym]
|
61
|
+
elsif MaRuKu::Globals.has_key?(sym)
|
62
|
+
return MaRuKu::Globals[sym]
|
63
|
+
else
|
64
|
+
$stderr.puts "Bug: no default for #{sym.inspect}"
|
65
|
+
nil
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,92 @@
|
|
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
|
+
|
23
|
+
#m Any method that detects formatting error calls the
|
24
|
+
#m maruku_error() method.
|
25
|
+
#m if @meta[:on_error] ==
|
26
|
+
#m
|
27
|
+
#m - :warning write on the standard err (or @error_stream if defined),
|
28
|
+
#m then do your best.
|
29
|
+
#m - :ignore be shy and try to continue
|
30
|
+
#m - :raise raises a MarukuException
|
31
|
+
#m
|
32
|
+
#m default is :raise
|
33
|
+
|
34
|
+
module MaRuKu
|
35
|
+
|
36
|
+
class Exception < RuntimeError
|
37
|
+
end
|
38
|
+
|
39
|
+
module Errors
|
40
|
+
|
41
|
+
def maruku_error(s,src=nil,con=nil)
|
42
|
+
policy = get_setting(:on_error)
|
43
|
+
|
44
|
+
case policy
|
45
|
+
when :ignore
|
46
|
+
when :raise
|
47
|
+
raise_error create_frame(describe_error(s,src,con))
|
48
|
+
when :warning
|
49
|
+
tell_user create_frame(describe_error(s,src,con))
|
50
|
+
else
|
51
|
+
raise "BugBug: policy = #{policy.inspect}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def maruku_recover(s,src=nil,con=nil)
|
56
|
+
tell_user create_frame(describe_error(s,src,con))
|
57
|
+
end
|
58
|
+
|
59
|
+
alias error maruku_error
|
60
|
+
|
61
|
+
def raise_error(s)
|
62
|
+
raise MaRuKu::Exception, s, caller
|
63
|
+
end
|
64
|
+
|
65
|
+
def tell_user(s)
|
66
|
+
error_stream = self.attributes[:error_stream] || $stderr
|
67
|
+
error_stream << s
|
68
|
+
end
|
69
|
+
|
70
|
+
def create_frame(s)
|
71
|
+
n = 75
|
72
|
+
"\n" +
|
73
|
+
" "+"_"*n + "\n"+
|
74
|
+
"| Maruku tells you:\n" +
|
75
|
+
"+" + ("-"*n) +"\n"+
|
76
|
+
add_tabs(s,1,'| ') + "\n" +
|
77
|
+
"+" + ("-"*n) + "\n" +
|
78
|
+
add_tabs(caller[0, 5].join("\n"),1,'!') + "\n" +
|
79
|
+
"\\" + ("_"*n) + "\n"
|
80
|
+
end
|
81
|
+
|
82
|
+
def describe_error(s,src,con)
|
83
|
+
t = s
|
84
|
+
src && (t += "\n#{src.describe}\n")
|
85
|
+
con && (t += "\n#{con.describe}\n")
|
86
|
+
t
|
87
|
+
end
|
88
|
+
|
89
|
+
end # Errors
|
90
|
+
end # MaRuKu
|
91
|
+
|
92
|
+
|
@@ -0,0 +1,100 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
OpenDiv = /^[ ]{0,3}\+\-\-+\s*([^\s-]*)\s*\-*\s*$/
|
4
|
+
CloseDiv = /^[ ]{0,3}\=\-\-+\s*([^\s-]*)\s*\-*\s*$/
|
5
|
+
StartPipe = /^[ ]{0,3}\|(.*)$/ # $1 is rest of line
|
6
|
+
DecorativeClosing = OpenDiv
|
7
|
+
|
8
|
+
MaRuKu::In::Markdown::register_block_extension(
|
9
|
+
:regexp => OpenDiv,
|
10
|
+
:handler => lambda { |doc, src, context|
|
11
|
+
# return false if not doc.is_math_enabled?
|
12
|
+
first = src.shift_line
|
13
|
+
first =~ OpenDiv
|
14
|
+
ial_at_beginning = $1
|
15
|
+
ial_at_end = nil
|
16
|
+
|
17
|
+
lines = []
|
18
|
+
# if second line starts with "|"
|
19
|
+
if src.cur_line =~ StartPipe
|
20
|
+
# then we read until no more "|"
|
21
|
+
while src.cur_line && (src.cur_line =~ StartPipe)
|
22
|
+
content = $1
|
23
|
+
lines.push content
|
24
|
+
src.shift_line
|
25
|
+
end
|
26
|
+
if src.cur_line =~ DecorativeClosing
|
27
|
+
ial_at_end = $1
|
28
|
+
src.shift_line
|
29
|
+
end
|
30
|
+
else
|
31
|
+
# else we read until CloseDiv
|
32
|
+
divs_open = 1
|
33
|
+
while src.cur_line && (divs_open>0)
|
34
|
+
if src.cur_line =~ CloseDiv
|
35
|
+
divs_open -= 1
|
36
|
+
if divs_open == 0
|
37
|
+
ial_at_end = $1
|
38
|
+
src.shift_line
|
39
|
+
break
|
40
|
+
else
|
41
|
+
lines.push src.shift_line
|
42
|
+
end
|
43
|
+
else
|
44
|
+
if src.cur_line =~ OpenDiv
|
45
|
+
divs_open += 1
|
46
|
+
end
|
47
|
+
lines.push src.shift_line
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
if divs_open > 0
|
52
|
+
e = "At end of input, I still have #{divs_open} DIVs open."
|
53
|
+
doc.maruku_error(e, src, context)
|
54
|
+
return true
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
ial_at_beginning = nil unless
|
59
|
+
(ial_at_beginning&&ial_at_beginning.size > 0)
|
60
|
+
ial_at_end = nil unless (ial_at_end && ial_at_end.size > 0)
|
61
|
+
|
62
|
+
if ial_at_beginning && ial_at_end
|
63
|
+
e = "Found two conflicting IALs: #{ial_at_beginning.inspect} and #{ial_at_end.inspect}"
|
64
|
+
doc.maruku_error(e, src, context)
|
65
|
+
end
|
66
|
+
|
67
|
+
al_string = ial_at_beginning || ial_at_end
|
68
|
+
al = nil
|
69
|
+
|
70
|
+
if al_string =~ /^\{(.*)\}$/
|
71
|
+
inside = $1
|
72
|
+
cs = MaRuKu::In::Markdown::SpanLevelParser::CharSource
|
73
|
+
al = al_string &&
|
74
|
+
doc.read_attribute_list(cs.new(inside), its_context=nil, break_on=[nil])
|
75
|
+
end
|
76
|
+
|
77
|
+
src = MaRuKu::In::Markdown::BlockLevelParser::LineSource.new(lines)
|
78
|
+
children = doc.parse_blocks(src)
|
79
|
+
|
80
|
+
context.push doc.md_div(children, al)
|
81
|
+
true
|
82
|
+
})
|
83
|
+
|
84
|
+
|
85
|
+
module MaRuKu; class MDElement
|
86
|
+
|
87
|
+
def md_div(children, a=nil)
|
88
|
+
self.md_el(:div, children, meta={}, a)
|
89
|
+
end
|
90
|
+
|
91
|
+
end end
|
92
|
+
|
93
|
+
|
94
|
+
module MaRuKu; module Out; module HTML
|
95
|
+
|
96
|
+
def to_html_div
|
97
|
+
add_ws wrap_as_element('div')
|
98
|
+
end
|
99
|
+
|
100
|
+
end end end
|