maruku 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/{maruku0.3 → marudown} +6 -14
- data/bin/maruku +1 -1
- data/bin/marutest +37 -9
- data/docs/TOFIX.html +22 -0
- data/docs/TOFIX.md +3 -0
- data/docs/changelog-0.2.13.html +30 -0
- data/docs/changelog-0.2.13.md +6 -0
- data/docs/changelog-0.3.html +19 -5
- data/docs/faq.html +51 -40
- data/docs/faq.md +3 -3
- data/docs/hidden_o_n_squared.md +10 -0
- data/docs/index.html +84 -396
- data/docs/markdown_syntax.html +139 -330
- data/docs/markdown_syntax.md +80 -93
- data/docs/maruku.html +84 -396
- data/docs/maruku.md +88 -158
- data/docs/proposal.html +13 -106
- data/docs/proposal.md +3 -3
- data/docs/todo.html +38 -28
- data/lib/maruku.rb +77 -11
- data/lib/maruku/attributes.rb +186 -0
- data/lib/maruku/defaults.rb +40 -0
- data/lib/maruku/errors_management.rb +55 -39
- data/lib/maruku/helpers.rb +156 -72
- data/lib/maruku/input/charsource.rb +319 -0
- data/lib/maruku/{html_helper.rb → input/html_helper.rb} +30 -9
- data/lib/maruku/input/linesource.rb +111 -0
- data/lib/maruku/input/parse_block.rb +562 -0
- data/lib/maruku/{parse_doc.rb → input/parse_doc.rb} +60 -28
- data/lib/maruku/{parse_span_better.rb → input/parse_span_better.rb} +226 -256
- data/lib/maruku/input/type_detection.rb +137 -0
- data/lib/maruku/maruku.rb +33 -0
- data/lib/maruku/{to_html.rb → output/to_html.rb} +151 -132
- data/lib/maruku/{to_latex.rb → output/to_latex.rb} +31 -35
- data/lib/maruku/{to_latex_entities.rb → output/to_latex_entities.rb} +25 -3
- data/lib/maruku/output/to_latex_strings.rb +64 -0
- data/lib/maruku/output/to_markdown.rb +164 -0
- data/lib/maruku/{to_s.rb → output/to_s.rb} +6 -0
- data/lib/maruku/string_utils.rb +12 -181
- data/lib/maruku/structures.rb +91 -67
- data/lib/maruku/structures_inspect.rb +78 -0
- data/lib/maruku/structures_iterators.rb +24 -2
- data/lib/maruku/tests/benchmark.rb +41 -9
- data/lib/maruku/tests/new_parser.rb +317 -286
- data/lib/maruku/tests/tests.rb +20 -0
- data/lib/maruku/toc.rb +64 -64
- data/lib/maruku/usage/example1.rb +33 -0
- data/lib/maruku/version.rb +8 -2
- data/tests/unittest/abbreviations.md +27 -16
- data/tests/unittest/attributes/attributes.md +89 -0
- data/tests/unittest/attributes/circular.md +51 -0
- data/tests/unittest/attributes/default.md +47 -0
- data/tests/unittest/blank.md +10 -6
- data/tests/unittest/blanks_in_code.md +26 -26
- data/tests/unittest/code.md +9 -9
- data/tests/unittest/code2.md +12 -13
- data/tests/unittest/code3.md +34 -34
- data/tests/unittest/easy.md +9 -7
- data/tests/unittest/email.md +9 -7
- data/tests/unittest/encoding/iso-8859-1.md +41 -4
- data/tests/unittest/encoding/utf-8.md +6 -5
- data/tests/unittest/entities.md +52 -80
- data/tests/unittest/escaping.md +47 -35
- data/tests/unittest/extra_dl.md +19 -29
- data/tests/unittest/extra_header_id.md +31 -24
- data/tests/unittest/extra_table1.md +14 -32
- data/tests/unittest/footnotes.md +58 -42
- data/tests/unittest/headers.md +11 -11
- data/tests/unittest/hrule.md +14 -24
- data/tests/unittest/images.md +41 -26
- data/tests/unittest/inline_html.md +104 -56
- data/tests/unittest/inline_html2.md +38 -0
- data/tests/unittest/links.md +74 -33
- data/tests/unittest/list1.md +18 -15
- data/tests/unittest/list2.md +31 -13
- data/tests/unittest/list3.md +29 -28
- data/tests/unittest/list4.md +103 -12
- data/tests/unittest/lists.md +86 -53
- data/tests/unittest/lists6.md +53 -0
- data/tests/unittest/lists7.md +31 -0
- data/tests/unittest/lists_after_paragraph.md +105 -71
- data/tests/unittest/lists_ol.md +149 -73
- data/tests/unittest/misc_sw.md +366 -326
- data/tests/unittest/notyet/escape.md +10 -10
- data/tests/unittest/notyet/header_after_par.md +20 -14
- data/tests/unittest/notyet/ticks.md +8 -35
- data/tests/unittest/notyet/triggering.md +72 -45
- data/tests/unittest/olist.md +78 -0
- data/tests/unittest/one.md +5 -3
- data/tests/unittest/paragraph.md +5 -3
- data/tests/unittest/paragraph_rules/dont_merge_ref.md +15 -9
- data/tests/unittest/paragraph_rules/tab_is_blank.md +9 -5
- data/tests/unittest/paragraphs.md +21 -26
- data/tests/unittest/recover/recover_links.md +6 -5
- data/tests/unittest/references/long_example.md +39 -30
- data/tests/unittest/references/spaces_and_numbers.md +2 -2
- data/tests/unittest/syntax_hl.md +33 -31
- data/tests/unittest/test.md +4 -6
- data/tests/unittest/wrapping.md +43 -26
- metadata +160 -139
- data/docs/markdown_extra2.html +0 -87
- data/docs/markdown_extra2.md +0 -83
- data/docs/markdown_syntax_2.html +0 -152
- data/lib/maruku/parse_block.rb +0 -564
- data/lib/maruku/parse_span.rb +0 -451
- data/lib/maruku/to_latex_strings.rb +0 -59
- data/lib/maruku/to_markdown.rb +0 -110
- data/lib/test.rb +0 -29
@@ -1,3 +1,4 @@
|
|
1
|
+
#--
|
1
2
|
# Copyright (C) 2006 Andrea Censi <andrea (at) rubyforge.org>
|
2
3
|
#
|
3
4
|
# This file is part of Maruku.
|
@@ -15,9 +16,13 @@
|
|
15
16
|
# You should have received a copy of the GNU General Public License
|
16
17
|
# along with Maruku; if not, write to the Free Software
|
17
18
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
19
|
+
#++
|
18
20
|
|
19
21
|
|
20
|
-
|
22
|
+
module MaRuKu
|
23
|
+
|
24
|
+
class MDDocument
|
25
|
+
|
21
26
|
|
22
27
|
# Render as a LaTeX fragment
|
23
28
|
def to_latex
|
@@ -28,7 +33,7 @@ class Maruku
|
|
28
33
|
def to_latex_document
|
29
34
|
header = ""
|
30
35
|
|
31
|
-
if @doc.
|
36
|
+
if @doc.attributes[:latex_use_listings]
|
32
37
|
header += "\\usepackage{listings}\n"
|
33
38
|
end
|
34
39
|
|
@@ -61,13 +66,10 @@ Created by \\href{http://maruku.rubyforge.org}{Maruku} #{self.nice_date}.
|
|
61
66
|
\\end{tiny}"
|
62
67
|
end
|
63
68
|
|
64
|
-
end
|
65
|
-
|
66
|
-
class MDElement
|
67
|
-
DEFAULT_CODE_COLOR = '#f0f0e0'
|
68
|
-
end
|
69
|
+
end end
|
69
70
|
|
70
|
-
|
71
|
+
module MaRuKu; module Out; module Latex
|
72
|
+
include Maruku::Defaults
|
71
73
|
|
72
74
|
def to_latex_hrule; "\n\\vspace{.5em} \\hrule \\vspace{.5em}\n" end
|
73
75
|
def to_latex_linebreak; "\\linebreak " end
|
@@ -77,7 +79,7 @@ class MDElement
|
|
77
79
|
end
|
78
80
|
|
79
81
|
def get_setting(name, default=nil)
|
80
|
-
self.
|
82
|
+
self.attributes[name] || @doc.attributes[name] || default
|
81
83
|
end
|
82
84
|
|
83
85
|
# \color[named]{name}
|
@@ -97,10 +99,9 @@ class MDElement
|
|
97
99
|
end
|
98
100
|
|
99
101
|
def to_latex_code;
|
100
|
-
raw_code =
|
102
|
+
raw_code = self.raw_code
|
101
103
|
|
102
|
-
if @doc.
|
103
|
-
# puts @meta.inspect
|
104
|
+
if @doc.attributes[:latex_use_listings]
|
104
105
|
s = "\\lstset{columns=fixed,frame=shadowbox}"
|
105
106
|
|
106
107
|
show_spaces = get_setting(:code_show_spaces)
|
@@ -117,7 +118,7 @@ class MDElement
|
|
117
118
|
s+= "\\lstset{basicstyle=\\ttfamily\\footnotesize}\n"
|
118
119
|
|
119
120
|
|
120
|
-
lang = self.
|
121
|
+
lang = self.attributes[:lang] || @doc.attributes[:code_lang] || '{}'
|
121
122
|
if lang
|
122
123
|
s += "\\lstset{language=#{lang}}\n"
|
123
124
|
end
|
@@ -135,14 +136,14 @@ class MDElement
|
|
135
136
|
4=>'paragraph'}
|
136
137
|
|
137
138
|
def to_latex_header
|
138
|
-
h = TexHeaders[
|
139
|
+
h = TexHeaders[self.level] || 'paragraph'
|
139
140
|
|
140
141
|
title = children_to_latex
|
141
142
|
if number = section_number
|
142
143
|
title = number + title
|
143
144
|
end
|
144
145
|
|
145
|
-
if id =
|
146
|
+
if id = self.attributes[:id]
|
146
147
|
# drop '#' at the beginning
|
147
148
|
if id[0,1] == '#' then id = [1,id.size] end
|
148
149
|
%{\\hypertarget{%s}{}\\%s*{{%s}}\\label{%s}\n\n} % [ id, h, title, id ]
|
@@ -153,7 +154,7 @@ class MDElement
|
|
153
154
|
|
154
155
|
|
155
156
|
def to_latex_ul;
|
156
|
-
if
|
157
|
+
if self.attributes[:toc]
|
157
158
|
@doc.toc.to_latex
|
158
159
|
else
|
159
160
|
wrap_as_environment('itemize')
|
@@ -171,7 +172,6 @@ class MDElement
|
|
171
172
|
|
172
173
|
def to_latex_strong; wrap_as_span('\bf') end
|
173
174
|
def to_latex_emphasis; wrap_as_span('\em') end
|
174
|
-
# def to_html_header; wrap_as_element "h#{@meta[:level]}" end
|
175
175
|
|
176
176
|
def wrap_as_span(c)
|
177
177
|
"{#{c} #{children_to_latex}}"
|
@@ -192,7 +192,7 @@ class MDElement
|
|
192
192
|
end
|
193
193
|
|
194
194
|
def to_latex_inline_code;
|
195
|
-
source = self.
|
195
|
+
source = self.raw_code
|
196
196
|
|
197
197
|
# Convert to printable latex chars
|
198
198
|
s = latex_escape(source)
|
@@ -204,12 +204,12 @@ class MDElement
|
|
204
204
|
end
|
205
205
|
|
206
206
|
def to_latex_immediate_link
|
207
|
-
url =
|
207
|
+
url = self.url
|
208
208
|
return "\\href{#{url}}{#{url.to_latex}}"
|
209
209
|
end
|
210
210
|
|
211
211
|
def to_latex_link
|
212
|
-
if id =
|
212
|
+
if id = self.ref_id
|
213
213
|
# if empty, use text
|
214
214
|
if id.size == 0
|
215
215
|
id = children.to_s.downcase
|
@@ -231,7 +231,7 @@ class MDElement
|
|
231
231
|
end
|
232
232
|
end
|
233
233
|
else
|
234
|
-
url =
|
234
|
+
url = self.url
|
235
235
|
|
236
236
|
if url[0,1] == '#'
|
237
237
|
url = url[1,url.size]
|
@@ -243,13 +243,13 @@ class MDElement
|
|
243
243
|
end
|
244
244
|
|
245
245
|
def to_latex_email_address
|
246
|
-
email =
|
246
|
+
email = self.email
|
247
247
|
"\\href{mailto:#{email}}{#{latex_escape(email)}}"
|
248
248
|
end
|
249
249
|
|
250
250
|
|
251
251
|
def to_latex_table
|
252
|
-
align =
|
252
|
+
align = self.align
|
253
253
|
num_columns = align.size
|
254
254
|
|
255
255
|
head = @children.slice(0, num_columns)
|
@@ -287,7 +287,7 @@ class MDElement
|
|
287
287
|
|
288
288
|
|
289
289
|
def to_latex_footnote_reference
|
290
|
-
id =
|
290
|
+
id = self.footnote_id
|
291
291
|
f = @doc.footnotes[id]
|
292
292
|
if f
|
293
293
|
"\\footnote{#{f.children_to_latex.strip}} "
|
@@ -309,8 +309,8 @@ class MDElement
|
|
309
309
|
end
|
310
310
|
|
311
311
|
def to_latex_definition
|
312
|
-
terms =
|
313
|
-
definitions =
|
312
|
+
terms = self.terms
|
313
|
+
definitions = self.definitions
|
314
314
|
|
315
315
|
s = ""
|
316
316
|
terms.each do |t|
|
@@ -325,12 +325,12 @@ class MDElement
|
|
325
325
|
end
|
326
326
|
|
327
327
|
|
328
|
-
def
|
328
|
+
def to_latex_abbr
|
329
329
|
children_to_latex
|
330
330
|
end
|
331
331
|
|
332
332
|
def to_latex_image
|
333
|
-
id =
|
333
|
+
id = self.ref_id
|
334
334
|
ref = @doc.refs[id]
|
335
335
|
if not ref
|
336
336
|
$stderr.puts "Could not find id = '#{id}'"
|
@@ -341,12 +341,8 @@ class MDElement
|
|
341
341
|
end
|
342
342
|
|
343
343
|
end
|
344
|
-
end
|
345
344
|
|
346
345
|
|
347
|
-
# Some utilities
|
348
|
-
class MDElement
|
349
|
-
|
350
346
|
# Convert each child to html
|
351
347
|
def children_to_latex
|
352
348
|
array_to_latex(@children)
|
@@ -359,7 +355,8 @@ class MDElement
|
|
359
355
|
"to_latex_#{c.node_type}" : "to_latex"
|
360
356
|
|
361
357
|
if not c.respond_to?(method)
|
362
|
-
|
358
|
+
# raise "Object does not answer to #{method}: #{c.class} #{c.inspect[0,100]}"
|
359
|
+
next
|
363
360
|
end
|
364
361
|
|
365
362
|
h = c.send(method)
|
@@ -377,5 +374,4 @@ class MDElement
|
|
377
374
|
e.join(join_char)
|
378
375
|
end
|
379
376
|
|
380
|
-
end
|
381
|
-
|
377
|
+
end end end # MaRuKu::Out::Latex
|
@@ -1,10 +1,32 @@
|
|
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
|
+
|
1
22
|
require 'rexml/document'
|
2
23
|
|
3
|
-
|
24
|
+
module MaRuKu; module Out; module Latex
|
25
|
+
|
4
26
|
include REXML
|
5
27
|
|
6
28
|
def to_latex_entity
|
7
|
-
entity_name =
|
29
|
+
entity_name = self.entity_name
|
8
30
|
|
9
31
|
MDElement.init_tables
|
10
32
|
|
@@ -297,5 +319,5 @@ class MDElement
|
|
297
319
|
<char num='255' name='yuml' convertTo='\\@DOUBLEQUOTy' />
|
298
320
|
</chars>"
|
299
321
|
|
300
|
-
end
|
322
|
+
end end end
|
301
323
|
|
@@ -0,0 +1,64 @@
|
|
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
|
+
class String
|
24
|
+
|
25
|
+
# These are TeX's special characters
|
26
|
+
LATEX_ADD_SLASH = [ ?{, ?}, ?$, ?&, ?#, ?_, ?%]
|
27
|
+
|
28
|
+
# These, we transform to {\tt \char<ascii code>}
|
29
|
+
LATEX_TO_CHARCODE = [ ?^, ?~, ?>,?<]
|
30
|
+
|
31
|
+
def escape_to_latex(s)
|
32
|
+
s2 = ""
|
33
|
+
s.each_byte do |b|
|
34
|
+
if LATEX_TO_CHARCODE.include? b
|
35
|
+
s2 += "{\\tt \\char#{b}}"
|
36
|
+
elsif LATEX_ADD_SLASH.include? b
|
37
|
+
s2 << ?\\ << b
|
38
|
+
elsif b == ?\\
|
39
|
+
# there is no backslash in cmr10 fonts
|
40
|
+
s2 += "$\\backslash$"
|
41
|
+
else
|
42
|
+
s2 << b
|
43
|
+
end
|
44
|
+
end
|
45
|
+
s2
|
46
|
+
end
|
47
|
+
|
48
|
+
# escapes special characters
|
49
|
+
def to_latex
|
50
|
+
s = escape_to_latex(self)
|
51
|
+
OtherGoodies.each do |k, v|
|
52
|
+
s.gsub!(k, v)
|
53
|
+
end
|
54
|
+
s
|
55
|
+
end
|
56
|
+
|
57
|
+
# other things that are good on the eyes
|
58
|
+
OtherGoodies = {
|
59
|
+
/(\s)LaTeX/ => '\1\\LaTeX\\xspace ', # XXX not if already \LaTeX
|
60
|
+
# 'HTML' => '\\textsc{html}\\xspace ',
|
61
|
+
# 'PDF' => '\\textsc{pdf}\\xspace '
|
62
|
+
}
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,164 @@
|
|
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
|
+
# XXX: markdown escaping
|
24
|
+
def to_md(c=nil)
|
25
|
+
to_s
|
26
|
+
end
|
27
|
+
|
28
|
+
# " andrea censi " => [" andrea ", "censi "]
|
29
|
+
def mysplit
|
30
|
+
split.map{|x| x+" "}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
module MaRuKu; module Out; module Markdown
|
36
|
+
|
37
|
+
DefaultLineLength = 40
|
38
|
+
|
39
|
+
def to_md(context={})
|
40
|
+
children_to_md(context)
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_md_paragraph(context)
|
44
|
+
line_length = context[:line_length] || DefaultLineLength
|
45
|
+
wrap(@children, line_length, context)+"\n"
|
46
|
+
end
|
47
|
+
|
48
|
+
def to_md_li_span(context)
|
49
|
+
len = (context[:line_length] || DefaultLineLength) - 2
|
50
|
+
s = add_tabs(wrap(@children, len-2, context), 1, ' ')
|
51
|
+
s[0] = ?*
|
52
|
+
s + "\n"
|
53
|
+
end
|
54
|
+
|
55
|
+
def to_md_abbr_def(context)
|
56
|
+
"*[#{self.abbr}]: #{self.text}\n"
|
57
|
+
end
|
58
|
+
|
59
|
+
def to_md_ol(context)
|
60
|
+
len = (context[:line_length] || DefaultLineLength) - 2
|
61
|
+
md = ""
|
62
|
+
self.children.each_with_index do |li, i|
|
63
|
+
s = add_tabs(w=wrap(li.children, len-2, context), 1, ' ')+"\n"
|
64
|
+
s[0,4] = "#{i+1}. "[0,4]
|
65
|
+
# puts w.inspect
|
66
|
+
md += s
|
67
|
+
end
|
68
|
+
md + "\n"
|
69
|
+
end
|
70
|
+
|
71
|
+
def to_md_ul(context)
|
72
|
+
len = (context[:line_length] || DefaultLineLength) - 2
|
73
|
+
md = ""
|
74
|
+
self.children.each_with_index do |li, i|
|
75
|
+
w = wrap(li.children, len-2, context)
|
76
|
+
# puts "W: "+ w.inspect
|
77
|
+
s = add_indent(w)
|
78
|
+
# puts "S: " +s.inspect
|
79
|
+
s[0,1] = "-"
|
80
|
+
md += s
|
81
|
+
end
|
82
|
+
md + "\n"
|
83
|
+
end
|
84
|
+
|
85
|
+
def add_indent(s,char=" ")
|
86
|
+
t = s.split("\n").map{|x| char+x }.join("\n")
|
87
|
+
s << ?\n if t[-1] == ?\n
|
88
|
+
s
|
89
|
+
end
|
90
|
+
|
91
|
+
# Convert each child to html
|
92
|
+
def children_to_md(context)
|
93
|
+
array_to_md(@children, context)
|
94
|
+
end
|
95
|
+
|
96
|
+
def wrap(array, line_length, context)
|
97
|
+
out = ""
|
98
|
+
line = ""
|
99
|
+
array.each do |c|
|
100
|
+
if c.kind_of?(MDElement) && c.node_type == :linebreak
|
101
|
+
out << line.strip << " \n"; line="";
|
102
|
+
next
|
103
|
+
end
|
104
|
+
|
105
|
+
pieces =
|
106
|
+
if c.kind_of? String
|
107
|
+
c.to_md.mysplit
|
108
|
+
else
|
109
|
+
[c.to_md(context)].flatten
|
110
|
+
end
|
111
|
+
|
112
|
+
# puts "Pieces: #{pieces.inspect}"
|
113
|
+
pieces.each do |p|
|
114
|
+
if p.size + line.size > line_length
|
115
|
+
out << line.strip << "\n";
|
116
|
+
line = ""
|
117
|
+
end
|
118
|
+
line << p
|
119
|
+
end
|
120
|
+
end
|
121
|
+
out << line.strip << "\n" if line.size > 0
|
122
|
+
out << ?\n if not out[-1] == ?\n
|
123
|
+
out
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
def array_to_md(array, context, join_char='')
|
128
|
+
e = []
|
129
|
+
array.each do |c|
|
130
|
+
method = c.kind_of?(MDElement) ?
|
131
|
+
"to_md_#{c.node_type}" : "to_md"
|
132
|
+
|
133
|
+
if not c.respond_to?(method)
|
134
|
+
#raise "Object does not answer to #{method}: #{c.class} #{c.inspect[0,100]}"
|
135
|
+
# tell_user "Using default for #{c.node_type}"
|
136
|
+
method = 'to_md'
|
137
|
+
end
|
138
|
+
|
139
|
+
# puts "#{c.inspect} created with method #{method}"
|
140
|
+
h = c.send(method, context)
|
141
|
+
|
142
|
+
if h.nil?
|
143
|
+
raise "Nil md for #{c.inspect} created with method #{method}"
|
144
|
+
end
|
145
|
+
|
146
|
+
if h.kind_of?Array
|
147
|
+
e = e + h
|
148
|
+
else
|
149
|
+
e << h
|
150
|
+
end
|
151
|
+
end
|
152
|
+
e.join(join_char)
|
153
|
+
end
|
154
|
+
|
155
|
+
end end end
|
156
|
+
|
157
|
+
module MaRuKu; class MDDocument
|
158
|
+
alias old_md to_md
|
159
|
+
def to_md(context={})
|
160
|
+
s = old_md(context)
|
161
|
+
# puts s
|
162
|
+
s
|
163
|
+
end
|
164
|
+
end end
|