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,138 +1,118 @@
|
|
1
|
-
|
2
|
-
module MaRuKu
|
1
|
+
require 'maruku/output/to_html'
|
3
2
|
|
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
|
-
<div id='header'> #{slide_header}</div>
|
68
|
-
<div id='footer'>
|
69
|
-
<h1>#{slide_footer}</h1>
|
70
|
-
<h2>#{slide_subfooter}</h2>
|
71
|
-
</div>
|
72
|
-
<div class='topleft'> #{slide_topleft}</div>
|
73
|
-
<div class='topright'> #{slide_topright}</div>
|
74
|
-
<div class='bottomleft'> #{slide_bottomleft}</div>
|
75
|
-
<div class='bottomright'> #{slide_bottomright}</div>
|
76
|
-
</div>
|
3
|
+
module MaRuKu
|
4
|
+
class MDDocument
|
5
|
+
def s5_theme
|
6
|
+
xtext(self.attributes[:slide_theme] || "default")
|
7
|
+
end
|
8
|
+
|
9
|
+
# Render as an HTML fragment (no head, just the content of BODY). (returns a string)
|
10
|
+
def to_s5(context={})
|
11
|
+
content_only = context[:content_only] != false
|
12
|
+
print_slides = context[:print_slides]
|
13
|
+
|
14
|
+
if content_only
|
15
|
+
body = xelem('div', doc)
|
16
|
+
else
|
17
|
+
html = xelem('html')
|
18
|
+
html['xmlns'] = 'http://www.w3.org/1999/xhtml'
|
19
|
+
html['xmlns:svg'] = "http://www.w3.org/2000/svg"
|
20
|
+
html['xml:lang'] = self.attributes[:lang] || 'en'
|
21
|
+
|
22
|
+
head = xelem('head')
|
23
|
+
html << head
|
24
|
+
|
25
|
+
me = xelem('meta')
|
26
|
+
me['http-equiv'] = 'Content-type'
|
27
|
+
me['content'] = 'text/html;charset=utf-8'
|
28
|
+
head << me
|
29
|
+
|
30
|
+
# Create title element
|
31
|
+
doc_title = self.attributes[:title] || self.attributes[:subject] || ""
|
32
|
+
begin
|
33
|
+
title_content = MaRuKu::HTMLFragment.new(doc_title).to_html
|
34
|
+
rescue
|
35
|
+
title_content = xtext(doc_title)
|
36
|
+
end
|
37
|
+
title = xelem('title') << title_content
|
38
|
+
head << title
|
39
|
+
|
40
|
+
body = xelem('body')
|
41
|
+
html << body
|
42
|
+
end
|
43
|
+
|
44
|
+
slide_header = self.attributes[:slide_header]
|
45
|
+
slide_footer = self.attributes[:slide_footer]
|
46
|
+
slide_subfooter = self.attributes[:slide_subfooter]
|
47
|
+
slide_topleft = self.attributes[:slide_topleft]
|
48
|
+
slide_topright = self.attributes[:slide_topright]
|
49
|
+
slide_bottomleft = self.attributes[:slide_bottomleft]
|
50
|
+
slide_bottomright = self.attributes[:slide_bottomright]
|
51
|
+
|
52
|
+
dummy_layout_slide = "
|
53
|
+
<div class='layout'>
|
54
|
+
<div id='controls'> </div>
|
55
|
+
<div id='currentSlide'> </div>
|
56
|
+
<div id='header'> #{slide_header}</div>
|
57
|
+
<div id='footer'>
|
58
|
+
<h1>#{slide_footer}</h1>
|
59
|
+
<h2>#{slide_subfooter}</h2>
|
60
|
+
</div>
|
61
|
+
<div class='topleft'> #{slide_topleft}</div>
|
62
|
+
<div class='topright'> #{slide_topright}</div>
|
63
|
+
<div class='bottomleft'> #{slide_bottomleft}</div>
|
64
|
+
<div class='bottomright'> #{slide_bottomright}</div>
|
65
|
+
</div>
|
77
66
|
"
|
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
|
-
# containing code.
|
130
|
-
html.write(xml,indent,transitive=true,ie_hack);
|
131
|
-
Xhtml11_mathml2_svg11 + xml
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
end
|
136
|
-
|
137
|
-
|
67
|
+
body << dummy_layout_slide
|
68
|
+
|
69
|
+
presentation = xelem('div')
|
70
|
+
presentation['class'] = 'presentation'
|
71
|
+
body << presentation
|
72
|
+
|
73
|
+
first_slide = "
|
74
|
+
<div class='slide'>
|
75
|
+
<h1> #{self.attributes[:title] ||context[:title]}</h1>
|
76
|
+
<h2> #{self.attributes[:subtitle] ||context[:subtitle]}</h2>
|
77
|
+
<h3> #{self.attributes[:author] ||context[:author]}</h3>
|
78
|
+
<h4> #{self.attributes[:company] ||context[:company]}</h4>
|
79
|
+
</div>
|
80
|
+
"
|
81
|
+
presentation << first_slide
|
82
|
+
|
83
|
+
slide_num = 0
|
84
|
+
self.toc.section_children.each do |slide|
|
85
|
+
slide_num += 1
|
86
|
+
@doc.attributes[:doc_prefix] = "s#{slide_num}"
|
87
|
+
|
88
|
+
div = xelem('div')
|
89
|
+
presentation << div
|
90
|
+
div['class'] = 'slide'
|
91
|
+
|
92
|
+
h1 = xelem('h1')
|
93
|
+
puts "Slide #{slide_num}: #{slide.header_element.children_to_html.join}" if print_slides
|
94
|
+
slide.header_element.children_to_html.inject(h1, &:<<)
|
95
|
+
div << h1
|
96
|
+
|
97
|
+
array_to_html(slide.immediate_children).inject(div, &:<<)
|
98
|
+
|
99
|
+
# render footnotes
|
100
|
+
unless @doc.footnotes_order.empty?
|
101
|
+
div << render_footnotes
|
102
|
+
@doc.footnotes_order = []
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
if content_only
|
107
|
+
xml = body.to_html
|
108
|
+
else
|
109
|
+
head << S5_external
|
110
|
+
|
111
|
+
add_css_to(head)
|
112
|
+
|
113
|
+
xml = html.to_html
|
114
|
+
Xhtml11_mathml2_svg11 + xml
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
138
118
|
end
|
@@ -1,991 +1,915 @@
|
|
1
|
-
|
2
|
-
|
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
|
-
require 'rexml/document'
|
22
|
-
|
23
|
-
begin
|
24
|
-
require 'rexml/formatters/pretty'
|
25
|
-
require 'rexml/formatters/default'
|
26
|
-
$rexml_new_version = true
|
27
|
-
rescue LoadError
|
28
|
-
$rexml_new_version = false
|
29
|
-
end
|
1
|
+
require 'maruku/string_utils'
|
2
|
+
require 'cgi'
|
30
3
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
4
|
+
# This module groups all functions related to HTML export.
|
5
|
+
module MaRuKu::Out::HTML
|
6
|
+
|
7
|
+
# Escape text for use in HTML (content or attributes) by running it through
|
8
|
+
# standard XML escaping (quotes and angle brackets and ampersands)
|
9
|
+
def self.escapeHTML(text)
|
10
|
+
CGI.escapeHTML(text)
|
11
|
+
# TODO: When we drop Rubies < 1.9.3, re-add .gsub(/[^[:print:]\n\r\t]/, '') to
|
12
|
+
# get rid of non-printable control characters.
|
13
|
+
end
|
14
|
+
|
15
|
+
# A simple class to represent an HTML element for output.
|
16
|
+
class HTMLElement
|
17
|
+
attr_accessor :name
|
18
|
+
attr_accessor :attributes
|
19
|
+
attr_accessor :children
|
20
|
+
|
21
|
+
def initialize(name, attr={}, children=[])
|
22
|
+
self.name = name
|
23
|
+
self.attributes = attr || {}
|
24
|
+
self.children = Array(children)
|
25
|
+
children << yield if block_given?
|
26
|
+
end
|
38
27
|
|
28
|
+
def <<(child)
|
29
|
+
children << child if children
|
30
|
+
self
|
31
|
+
end
|
39
32
|
|
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
|
-
xml
|
81
|
-
end
|
82
|
-
|
83
|
-
# Render to a complete HTML document (returns a string)
|
84
|
-
def to_html_document(context={})
|
85
|
-
indent = context[:indent] || -1
|
86
|
-
ie_hack = context[:ie_hack] ||true
|
87
|
-
doc = to_html_document_tree
|
88
|
-
xml = ""
|
89
|
-
|
90
|
-
# REXML Bug? if indent!=-1 whitespace is not respected for 'pre' elements
|
91
|
-
# containing code.
|
92
|
-
doc.write(xml,indent,transitive=true,ie_hack);
|
93
|
-
|
94
|
-
Xhtml11_mathml2_svg11 + xml
|
95
|
-
end
|
96
|
-
|
97
|
-
|
98
|
-
Xhtml10strict =
|
99
|
-
"<?xml version='1.0' encoding='utf-8'?>
|
100
|
-
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
|
101
|
-
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>\n"
|
102
|
-
|
103
|
-
Xhtml11strict_mathml2 = '<?xml version="1.0" encoding="utf-8"?>
|
104
|
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN"
|
105
|
-
"http://www.w3.org/TR/MathML2/dtd/xhtml-math11-f.dtd" [
|
106
|
-
<!ENTITY mathml "http://www.w3.org/1998/Math/MathML">
|
107
|
-
]>
|
108
|
-
'
|
33
|
+
def [](key)
|
34
|
+
attributes[key.to_s]
|
35
|
+
end
|
36
|
+
|
37
|
+
def []=(key, value)
|
38
|
+
attributes[key.to_s] = value
|
39
|
+
end
|
40
|
+
|
41
|
+
def add_class(class_name)
|
42
|
+
attributes['class'] = ((attributes['class']||'').split(' ') + [class_name]).join(' ')
|
43
|
+
end
|
44
|
+
|
45
|
+
# These elements have no children and should be rendered with a self-closing tag.
|
46
|
+
# It's not an exhaustive list, but they cover everything we use.
|
47
|
+
SELF_CLOSING = Set.new %w[br hr img link meta]
|
48
|
+
|
49
|
+
def to_html
|
50
|
+
m = "<#{name}"
|
51
|
+
attributes.each do |k, v|
|
52
|
+
m << " #{k.to_s}=\"#{v.to_s}\""
|
53
|
+
end
|
54
|
+
|
55
|
+
if SELF_CLOSING.include? name
|
56
|
+
m << " />"
|
57
|
+
else
|
58
|
+
content = children.map(&:to_s)
|
59
|
+
m << ">" << content.join('') << "</#{name}>"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
alias :to_str :to_html
|
64
|
+
alias :to_s :to_html
|
65
|
+
end
|
66
|
+
|
67
|
+
# Render as an HTML fragment (no head, just the content of BODY). (returns a string)
|
68
|
+
def to_html(context={})
|
69
|
+
output = ""
|
70
|
+
children_to_html.each do |e|
|
71
|
+
output << e.to_s
|
72
|
+
end
|
109
73
|
|
110
|
-
|
111
|
-
|
74
|
+
# render footnotes
|
75
|
+
unless @doc.footnotes_order.empty?
|
76
|
+
output << render_footnotes
|
77
|
+
end
|
78
|
+
|
79
|
+
output
|
80
|
+
end
|
81
|
+
|
82
|
+
Xhtml11_mathml2_svg11 =
|
83
|
+
'<?xml version="1.0" encoding="utf-8"?>
|
112
84
|
<!DOCTYPE html PUBLIC
|
113
85
|
"-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"
|
114
86
|
"http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">
|
115
87
|
'
|
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
|
-
Attribute: css
|
179
|
-
Scope: document
|
180
|
-
Output: HTML
|
181
|
-
Summary: Activates CSS stylesheets for HTML.
|
182
|
-
|
183
|
-
`css` should be a space-separated list of urls.
|
184
|
-
|
185
|
-
Example:
|
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
|
-
Attribute: html_use_syntax
|
515
|
-
Scope: global, document, element
|
516
|
-
Output: HTML
|
517
|
-
Summary: Enables the use of the `syntax` package.
|
518
|
-
Related: lang, code_lang
|
519
|
-
Default: <?mrk md_code(Globals[:html_use_syntax].to_s) ?>
|
520
|
-
|
521
|
-
If true, the `syntax` package is used. It supports the `ruby` and `xml`
|
522
|
-
languages. Remember to set the `lang` attribute of the code block.
|
523
|
-
|
524
|
-
Examples:
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
and
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
produces:
|
535
|
-
|
536
|
-
|
537
|
-
{:lang=ruby html_use_syntax=true}
|
538
|
-
|
539
|
-
and
|
540
|
-
|
541
|
-
|
542
|
-
{:lang=html html_use_syntax=true}
|
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
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
Text.new('&%s;' % [entity_name], false, nil, true)
|
945
|
-
end
|
946
|
-
end
|
947
|
-
|
948
|
-
def to_html_xml_instr
|
949
|
-
target = self.target || ''
|
950
|
-
code = self.code || ''
|
951
|
-
REXML::Instruction.new(target, code)
|
952
|
-
end
|
953
|
-
|
954
|
-
# Convert each child to html
|
955
|
-
def children_to_html
|
956
|
-
array_to_html(@children)
|
957
|
-
end
|
958
|
-
|
959
|
-
def array_to_html(array)
|
960
|
-
e = []
|
961
|
-
array.each do |c|
|
962
|
-
method = c.kind_of?(MDElement) ?
|
963
|
-
"to_html_#{c.node_type}" : "to_html"
|
964
|
-
|
965
|
-
if not c.respond_to?(method)
|
966
|
-
#raise "Object does not answer to #{method}: #{c.class} #{c.inspect}"
|
967
|
-
next
|
968
|
-
end
|
969
|
-
|
970
|
-
h = c.send(method)
|
971
|
-
|
972
|
-
if h.nil?
|
973
|
-
raise "Nil html created by method #{method}:\n#{h.inspect}\n"+
|
974
|
-
" for object #{c.inspect[0,300]}"
|
975
|
-
end
|
976
|
-
|
977
|
-
if h.kind_of?Array
|
978
|
-
e = e + h #h.each do |hh| e << hh end
|
979
|
-
else
|
980
|
-
e << h
|
981
|
-
end
|
982
|
-
end
|
983
|
-
e
|
984
|
-
end
|
985
|
-
|
986
|
-
def to_html_ref_definition; [] end
|
987
|
-
def to_latex_ref_definition; [] end
|
988
|
-
|
989
|
-
end # HTML
|
990
|
-
end # out
|
991
|
-
end # MaRuKu
|
88
|
+
|
89
|
+
# Render to a complete HTML document (returns a string)
|
90
|
+
def to_html_document(context={})
|
91
|
+
doc = to_html_document_tree
|
92
|
+
|
93
|
+
xml = doc.to_s
|
94
|
+
Xhtml11_mathml2_svg11 + xml
|
95
|
+
end
|
96
|
+
|
97
|
+
# Helper to create a text node
|
98
|
+
def xtext(text)
|
99
|
+
MaRuKu::Out::HTML.escapeHTML(text)
|
100
|
+
end
|
101
|
+
|
102
|
+
# Helper to create an element
|
103
|
+
def xelem(type)
|
104
|
+
HTMLElement.new(type)
|
105
|
+
end
|
106
|
+
|
107
|
+
def xml_newline
|
108
|
+
"\n"
|
109
|
+
end
|
110
|
+
|
111
|
+
#=begin maruku_doc
|
112
|
+
# Attribute: title
|
113
|
+
# Scope: document
|
114
|
+
#
|
115
|
+
# Sets the title of the document.
|
116
|
+
# If a title is not specified, the first header will be used.
|
117
|
+
#
|
118
|
+
# These should be equivalent:
|
119
|
+
#
|
120
|
+
# Title: my document
|
121
|
+
#
|
122
|
+
# Content
|
123
|
+
#
|
124
|
+
# and
|
125
|
+
#
|
126
|
+
# my document
|
127
|
+
# ===========
|
128
|
+
#
|
129
|
+
# Content
|
130
|
+
#
|
131
|
+
# In both cases, the title is set to "my document".
|
132
|
+
#=end
|
133
|
+
|
134
|
+
#=begin maruku_doc
|
135
|
+
# Attribute: doc_prefix
|
136
|
+
# Scope: document
|
137
|
+
#
|
138
|
+
# String to disambiguate footnote links.
|
139
|
+
#=end
|
140
|
+
|
141
|
+
|
142
|
+
#=begin maruku_doc
|
143
|
+
# Attribute: subject
|
144
|
+
# Scope: document
|
145
|
+
|
146
|
+
# Synonym for `title`.
|
147
|
+
#=end
|
148
|
+
|
149
|
+
#=begin maruku_doc
|
150
|
+
# Attribute: css
|
151
|
+
# Scope: document
|
152
|
+
# Output: HTML
|
153
|
+
# Summary: Activates CSS stylesheets for HTML.
|
154
|
+
#
|
155
|
+
# `css` should be a space-separated list of urls.
|
156
|
+
#
|
157
|
+
# Example:
|
158
|
+
#
|
159
|
+
# CSS: style.css math.css
|
160
|
+
#
|
161
|
+
#=end
|
162
|
+
|
163
|
+
# Render to a complete HTML document (returns an HTMLElement document tree)
|
164
|
+
def to_html_document_tree
|
165
|
+
root = xelem('html')
|
166
|
+
root['xmlns'] = 'http://www.w3.org/1999/xhtml'
|
167
|
+
root['xmlns:svg'] = "http://www.w3.org/2000/svg"
|
168
|
+
root['xml:lang'] = self.attributes[:lang] || 'en'
|
169
|
+
|
170
|
+
root << xml_newline
|
171
|
+
head = xelem('head')
|
172
|
+
root << head
|
173
|
+
|
174
|
+
#<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
|
175
|
+
me = xelem('meta')
|
176
|
+
me['http-equiv'] = 'Content-type'
|
177
|
+
me['content'] = 'application/xhtml+xml;charset=utf-8'
|
178
|
+
head << me
|
179
|
+
|
180
|
+
%w(description keywords author revised).each do |m|
|
181
|
+
if value = self.attributes[m.to_sym]
|
182
|
+
meta = xelem('meta')
|
183
|
+
meta['name'] = m
|
184
|
+
meta['content'] = value.to_s
|
185
|
+
head << meta
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
self.attributes.each do |k,v|
|
190
|
+
if k.to_s =~ /\Ameta-(.*)\z/
|
191
|
+
meta = xelem('meta')
|
192
|
+
meta['name'] = $1
|
193
|
+
meta['content'] = v.to_s
|
194
|
+
head << meta
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
# Create title element
|
199
|
+
doc_title = self.attributes[:title] || self.attributes[:subject] || ""
|
200
|
+
begin
|
201
|
+
title_content = MaRuKu::HTMLFragment.new(doc_title).to_html
|
202
|
+
rescue
|
203
|
+
title_content = xtext(doc_title)
|
204
|
+
end
|
205
|
+
title = xelem('title') << title_content
|
206
|
+
head << title
|
207
|
+
add_css_to(head)
|
208
|
+
|
209
|
+
root << xml_newline
|
210
|
+
|
211
|
+
body = xelem('body')
|
212
|
+
|
213
|
+
children_to_html.each do |e|
|
214
|
+
body << e.to_s
|
215
|
+
end
|
216
|
+
|
217
|
+
# render footnotes
|
218
|
+
unless @doc.footnotes_order.empty?
|
219
|
+
body << render_footnotes
|
220
|
+
end
|
221
|
+
|
222
|
+
# When we are rendering a whole document, we add a signature
|
223
|
+
# at the bottom.
|
224
|
+
if get_setting(:maruku_signature)
|
225
|
+
body << maruku_html_signature
|
226
|
+
end
|
227
|
+
|
228
|
+
root << body
|
229
|
+
end
|
230
|
+
|
231
|
+
def add_css_to(head)
|
232
|
+
if css_list = self.attributes[:css]
|
233
|
+
css_list.split.each do |css|
|
234
|
+
# <link type="text/css" rel="stylesheet" href="..." />
|
235
|
+
link = xelem('link')
|
236
|
+
link['type'] = 'text/css'
|
237
|
+
link['rel'] = 'stylesheet'
|
238
|
+
link['href'] = css
|
239
|
+
head << link << xml_newline
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
# returns "st","nd","rd" or "th" as appropriate
|
245
|
+
def day_suffix(day)
|
246
|
+
s = {
|
247
|
+
1 => 'st',
|
248
|
+
2 => 'nd',
|
249
|
+
3 => 'rd',
|
250
|
+
21 => 'st',
|
251
|
+
22 => 'nd',
|
252
|
+
23 => 'rd',
|
253
|
+
31 => 'st'
|
254
|
+
}
|
255
|
+
s[day] || 'th';
|
256
|
+
end
|
257
|
+
|
258
|
+
# formats a nice date
|
259
|
+
def nice_date
|
260
|
+
Time.now.strftime(" at %H:%M on %A, %B %d") +
|
261
|
+
day_suffix(t.day) +
|
262
|
+
t.strftime(", %Y")
|
263
|
+
end
|
264
|
+
|
265
|
+
def maruku_html_signature
|
266
|
+
div = xelem('div')
|
267
|
+
div['class'] = 'maruku_signature'
|
268
|
+
div << xelem('hr')
|
269
|
+
span = xelem('span')
|
270
|
+
span['style'] = 'font-size: small; font-style: italic'
|
271
|
+
div << span << xtext('Created by ')
|
272
|
+
a = xelem('a')
|
273
|
+
a['href'] = MaRuKu::MARUKU_URL
|
274
|
+
a['title'] = 'Maruku: a Markdown-superset interpreter for Ruby'
|
275
|
+
a << xtext('Maruku')
|
276
|
+
span << xtext(nice_date + ".")
|
277
|
+
div
|
278
|
+
end
|
279
|
+
|
280
|
+
def render_footnotes
|
281
|
+
div = xelem('div')
|
282
|
+
div['class'] = 'footnotes'
|
283
|
+
div << xelem('hr')
|
284
|
+
ol = xelem('ol')
|
285
|
+
|
286
|
+
@doc.footnotes_order.each_with_index do |fid, i|
|
287
|
+
num = i + 1
|
288
|
+
if f = self.footnotes[fid]
|
289
|
+
li = f.wrap_as_element('li')
|
290
|
+
li['id'] = "#{get_setting(:doc_prefix)}fn:#{num}"
|
291
|
+
|
292
|
+
a = xelem('a')
|
293
|
+
a['href'] = "\##{get_setting(:doc_prefix)}fnref:#{num}"
|
294
|
+
a['rev'] = 'footnote'
|
295
|
+
a << xtext([8617].pack('U*'))
|
296
|
+
|
297
|
+
last = nil
|
298
|
+
li.children.reverse_each do |child|
|
299
|
+
if child.is_a?(HTMLElement)
|
300
|
+
last = child
|
301
|
+
break
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
if last && last.name == "p"
|
306
|
+
last << xtext(' ') << a
|
307
|
+
else
|
308
|
+
li.children << a
|
309
|
+
end
|
310
|
+
ol << li
|
311
|
+
else
|
312
|
+
maruku_error "Could not find footnote id '#{fid}' among [#{self.footnotes.keys.inspect}]."
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
316
|
+
div << ol
|
317
|
+
end
|
318
|
+
|
319
|
+
def to_html_hrule
|
320
|
+
xelem('hr')
|
321
|
+
end
|
322
|
+
|
323
|
+
def to_html_linebreak
|
324
|
+
xelem('br')
|
325
|
+
end
|
326
|
+
|
327
|
+
# renders children as html and wraps into an element of given name
|
328
|
+
#
|
329
|
+
# Sets 'id' if meta is set
|
330
|
+
def wrap_as_element(name, attributes={})
|
331
|
+
html_element name, children_to_html, attributes
|
332
|
+
end
|
333
|
+
|
334
|
+
#=begin maruku_doc
|
335
|
+
# Attribute: id
|
336
|
+
# Scope: element
|
337
|
+
# Output: LaTeX, HTML
|
338
|
+
#
|
339
|
+
# It is copied as a standard HTML attribute.
|
340
|
+
#
|
341
|
+
# Moreover, it used as a label name for hyperlinks in both HTML and
|
342
|
+
# in PDF.
|
343
|
+
#=end
|
344
|
+
|
345
|
+
#=begin maruku_doc
|
346
|
+
# Attribute: class
|
347
|
+
# Scope: element
|
348
|
+
# Output: HTML
|
349
|
+
#
|
350
|
+
# It is copied as a standard HTML attribute.
|
351
|
+
#=end
|
352
|
+
|
353
|
+
#=begin maruku_doc
|
354
|
+
# Attribute: style
|
355
|
+
# Scope: element
|
356
|
+
# Output: HTML
|
357
|
+
#
|
358
|
+
# It is copied as a standard HTML attribute.
|
359
|
+
#=end
|
360
|
+
|
361
|
+
HTML4Attributes = {}
|
362
|
+
|
363
|
+
coreattrs = [:id, :class, :style, :title, :accesskey, :contenteditable, :dir,
|
364
|
+
:draggable, :spellcheck, :tabindex]
|
365
|
+
i18n = [:lang, :'xml:lang']
|
366
|
+
events = [:onclick, :ondblclick, :onmousedown, :onmouseup, :onmouseover,
|
367
|
+
:onmousemove, :onmouseout,
|
368
|
+
:onkeypress, :onkeydown, :onkeyup]
|
369
|
+
common_attrs = coreattrs + i18n + events
|
370
|
+
cells = [:align, :char, :charoff, :valign]
|
371
|
+
|
372
|
+
# Each row maps a list of tags to the list of attributes beyond the common_attributes
|
373
|
+
# that are valid on those elements
|
374
|
+
[
|
375
|
+
['body', [:onload, :onunload]],
|
376
|
+
['a', [:charset, :type, :name, :rel, :rev, :accesskey, :shape, :coords, :tabindex,
|
377
|
+
:onfocus,:onblur]],
|
378
|
+
['img', [:longdesc, :name, :height, :width, :alt]],
|
379
|
+
['ol', [:reversed, :start]],
|
380
|
+
['li', [:value]],
|
381
|
+
['table', [:summary, :width, :frame, :rules, :border, :cellspacing, :cellpadding]],
|
382
|
+
[%w(q blockquote), [:cite]],
|
383
|
+
[%w(ins del), [:cite, :datetime]],
|
384
|
+
[%w(colgroup col), [:span, :width] + cells],
|
385
|
+
[%w(thead tbody tfoot), cells],
|
386
|
+
[%w(td td th), [:abbr, :axis, :headers, :scope, :rowspan, :colspan] + cells],
|
387
|
+
[%w(em code strong hr span dl dd dt address div p pre caption ul h1 h2 h3 h4 h5 h6), []]
|
388
|
+
].each do |elements, attributes|
|
389
|
+
[*elements].each do |element|
|
390
|
+
HTML4Attributes[element] = common_attrs + attributes
|
391
|
+
end
|
392
|
+
end
|
393
|
+
|
394
|
+
# Pretty much the same as the HTMLElement constructor except it
|
395
|
+
# copies standard attributes out of the Maruku Element's attributes hash.
|
396
|
+
def html_element(name, content="", attributes={})
|
397
|
+
attributes = content if attributes.empty? && content.is_a?(Hash)
|
398
|
+
|
399
|
+
Array(HTML4Attributes[name]).each do |att|
|
400
|
+
if v = @attributes[att]
|
401
|
+
attributes[att.to_s] = MaRuKu::Out::HTML.escapeHTML(v.to_s)
|
402
|
+
end
|
403
|
+
end
|
404
|
+
|
405
|
+
content = yield if block_given?
|
406
|
+
|
407
|
+
HTMLElement.new(name, attributes, content)
|
408
|
+
end
|
409
|
+
|
410
|
+
def to_html_ul
|
411
|
+
if @attributes[:toc]
|
412
|
+
# render toc
|
413
|
+
@doc.toc.to_html
|
414
|
+
else
|
415
|
+
add_ws wrap_as_element('ul')
|
416
|
+
end
|
417
|
+
end
|
418
|
+
|
419
|
+
def to_html_paragraph
|
420
|
+
add_ws wrap_as_element('p')
|
421
|
+
end
|
422
|
+
|
423
|
+
def to_html_ol
|
424
|
+
add_ws wrap_as_element('ol')
|
425
|
+
end
|
426
|
+
|
427
|
+
def to_html_li
|
428
|
+
add_ws wrap_as_element('li')
|
429
|
+
end
|
430
|
+
|
431
|
+
def to_html_quote
|
432
|
+
add_ws wrap_as_element('blockquote')
|
433
|
+
end
|
434
|
+
|
435
|
+
def to_html_strong
|
436
|
+
wrap_as_element('strong')
|
437
|
+
end
|
438
|
+
|
439
|
+
def to_html_emphasis
|
440
|
+
wrap_as_element('em')
|
441
|
+
end
|
442
|
+
|
443
|
+
#=begin maruku_doc
|
444
|
+
# Attribute: use_numbered_headers
|
445
|
+
# Scope: document
|
446
|
+
# Summary: Activates the numbering of headers.
|
447
|
+
#
|
448
|
+
# If `true`, section headers will be numbered.
|
449
|
+
#
|
450
|
+
# In LaTeX export, the numbering of headers is managed
|
451
|
+
# by Maruku, to have the same results in both HTML and LaTeX.
|
452
|
+
#=end
|
453
|
+
|
454
|
+
# nil if not applicable, else string
|
455
|
+
def section_number
|
456
|
+
return nil unless get_setting(:use_numbered_headers)
|
457
|
+
|
458
|
+
n = Array(@attributes[:section_number])
|
459
|
+
return nil if n.empty?
|
460
|
+
|
461
|
+
n.join('.') + ". "
|
462
|
+
end
|
463
|
+
|
464
|
+
# nil if not applicable, else SPAN element
|
465
|
+
def render_section_number
|
466
|
+
return nil unless section_number && !section_number.empty?
|
467
|
+
|
468
|
+
# if we are bound to a section, add section number
|
469
|
+
span = xelem('span')
|
470
|
+
span['class'] = 'maruku_section_number'
|
471
|
+
span << xtext(section_number)
|
472
|
+
end
|
473
|
+
|
474
|
+
def to_html_header
|
475
|
+
element_name = "h#{self.level}"
|
476
|
+
h = wrap_as_element element_name
|
477
|
+
|
478
|
+
if span = render_section_number
|
479
|
+
h.children.unshift(span)
|
480
|
+
end
|
481
|
+
|
482
|
+
add_ws h
|
483
|
+
end
|
484
|
+
|
485
|
+
#=begin maruku_doc
|
486
|
+
# Attribute: html_use_syntax
|
487
|
+
# Scope: global, document, element
|
488
|
+
# Output: HTML
|
489
|
+
# Summary: Enables the use of the `syntax` package.
|
490
|
+
# Related: lang, code_lang
|
491
|
+
# Default: <?mrk md_code(Globals[:html_use_syntax].to_s) ?>
|
492
|
+
#
|
493
|
+
# If true, the `syntax` package is used. It supports the `ruby` and `xml`
|
494
|
+
# languages. Remember to set the `lang` attribute of the code block.
|
495
|
+
#
|
496
|
+
# Examples:
|
497
|
+
#
|
498
|
+
# require 'maruku'
|
499
|
+
# {:lang=ruby html_use_syntax=true}
|
500
|
+
#
|
501
|
+
# and
|
502
|
+
#
|
503
|
+
# <div style="text-align:center">Div</div>
|
504
|
+
# {:lang=html html_use_syntax=true}
|
505
|
+
#
|
506
|
+
# produces:
|
507
|
+
#
|
508
|
+
# require 'maruku'
|
509
|
+
# {:lang=ruby html_use_syntax=true}
|
510
|
+
#
|
511
|
+
# and
|
512
|
+
#
|
513
|
+
# <div style="text-align:center">Div</div>
|
514
|
+
# {:lang=html html_use_syntax=true}
|
515
|
+
#
|
516
|
+
#=end
|
517
|
+
|
518
|
+
$syntax_loaded = false
|
519
|
+
def to_html_code
|
520
|
+
source = self.raw_code
|
521
|
+
|
522
|
+
code_lang = self.lang || self.attributes[:lang] || @doc.attributes[:code_lang]
|
523
|
+
|
524
|
+
code_lang = 'xml' if code_lang == 'html'
|
525
|
+
code_lang = 'css21' if code_lang == 'css'
|
526
|
+
|
527
|
+
use_syntax = get_setting :html_use_syntax
|
528
|
+
|
529
|
+
element =
|
530
|
+
if use_syntax && code_lang
|
531
|
+
begin
|
532
|
+
unless $syntax_loaded
|
533
|
+
require 'rubygems'
|
534
|
+
require 'syntax'
|
535
|
+
require 'syntax/convertors/html'
|
536
|
+
$syntax_loaded = true
|
537
|
+
end
|
538
|
+
convertor = Syntax::Convertors::HTML.for_syntax code_lang
|
539
|
+
|
540
|
+
# eliminate trailing newlines otherwise Syntax crashes
|
541
|
+
source = source.sub(/\n*\z/, '')
|
542
|
+
|
543
|
+
html = convertor.convert(source)
|
544
|
+
|
545
|
+
html.gsub!(/\'|'/,''') # IE bug
|
546
|
+
|
547
|
+
d = MaRuKu::HTMLFragment.new(html)
|
548
|
+
highlighted = d.to_html.sub(/\A<pre>(.*)<\/pre>\z/m, '\1')
|
549
|
+
code = HTMLElement.new('code', { :class => code_lang }, highlighted)
|
550
|
+
|
551
|
+
pre = xelem('pre')
|
552
|
+
# add a class here, too, for compatibility with existing implementations
|
553
|
+
pre['class'] = code_lang
|
554
|
+
pre << code
|
555
|
+
pre
|
556
|
+
rescue LoadError => e
|
557
|
+
maruku_error "Could not load package 'syntax'.\n" +
|
558
|
+
"Please install it, for example using 'gem install syntax'."
|
559
|
+
to_html_code_using_pre(source, code_lang)
|
560
|
+
rescue => e
|
561
|
+
maruku_error "Error while using the syntax library for code:\n#{source.inspect}" +
|
562
|
+
"Lang is #{code_lang} object is: \n" +
|
563
|
+
self.inspect +
|
564
|
+
"\nException: #{e.class}: #{e.message}"
|
565
|
+
|
566
|
+
tell_user("Using normal PRE because the syntax library did not work.")
|
567
|
+
to_html_code_using_pre(source, code_lang)
|
568
|
+
end
|
569
|
+
else
|
570
|
+
to_html_code_using_pre(source, code_lang)
|
571
|
+
end
|
572
|
+
|
573
|
+
color = get_setting(:code_background_color)
|
574
|
+
if color != MaRuKu::Globals[:code_background_color]
|
575
|
+
element['style'] = "background-color: #{color};"
|
576
|
+
end
|
577
|
+
|
578
|
+
add_ws element
|
579
|
+
end
|
580
|
+
|
581
|
+
#=begin maruku_doc
|
582
|
+
# Attribute: code_background_color
|
583
|
+
# Scope: global, document, element
|
584
|
+
# Summary: Background color for code blocks.
|
585
|
+
#
|
586
|
+
# The format is either a named color (`green`, `red`) or a CSS color
|
587
|
+
# of the form `#ff00ff`.
|
588
|
+
#
|
589
|
+
# * for **HTML output**, the value is put straight in the `background-color` CSS
|
590
|
+
# property of the block.
|
591
|
+
#
|
592
|
+
# * for **LaTeX output**, if it is a named color, it must be a color accepted
|
593
|
+
# by the LaTeX `color` packages. If it is of the form `#ff00ff`, Maruku
|
594
|
+
# defines a color using the `\color[rgb]{r,g,b}` macro.
|
595
|
+
#
|
596
|
+
# For example, for `#0000ff`, the macro is called as: `\color[rgb]{0,0,1}`.
|
597
|
+
#=end
|
598
|
+
|
599
|
+
|
600
|
+
def to_html_code_using_pre(source, code_lang=nil)
|
601
|
+
code = xelem('code')
|
602
|
+
pre = xelem('pre')
|
603
|
+
pre << code
|
604
|
+
|
605
|
+
if get_setting(:code_show_spaces)
|
606
|
+
# 187 = raquo
|
607
|
+
# 160 = nbsp
|
608
|
+
# 172 = not
|
609
|
+
source = source.gsub(/\t/,'»' + ' ' * 3).gsub(/ /,'¬')
|
610
|
+
end
|
611
|
+
|
612
|
+
code << xtext(source)
|
613
|
+
|
614
|
+
code_lang ||= self.attributes[:lang]
|
615
|
+
if code_lang
|
616
|
+
pre['class'] = code['class'] = code_lang
|
617
|
+
end
|
618
|
+
|
619
|
+
pre
|
620
|
+
end
|
621
|
+
|
622
|
+
def to_html_inline_code
|
623
|
+
code_attrs = {}
|
624
|
+
source = xtext(self.raw_code)
|
625
|
+
|
626
|
+
color = get_setting(:code_background_color)
|
627
|
+
if color != MaRuKu::Globals[:code_background_color]
|
628
|
+
code_attrs['style'] = "background-color: #{color};" + (code_attrs['style'] || "")
|
629
|
+
end
|
630
|
+
|
631
|
+
html_element('code', source, code_attrs)
|
632
|
+
end
|
633
|
+
|
634
|
+
def add_class_to(el, cl)
|
635
|
+
el['class'] =
|
636
|
+
if already = el['class']
|
637
|
+
already + " " + cl
|
638
|
+
else
|
639
|
+
cl
|
640
|
+
end
|
641
|
+
end
|
642
|
+
|
643
|
+
def to_html_immediate_link
|
644
|
+
text = self.url.gsub(/^mailto:/, '') # don't show mailto
|
645
|
+
html_element('a', text, 'href' => self.url)
|
646
|
+
end
|
647
|
+
|
648
|
+
def to_html_link
|
649
|
+
a = {}
|
650
|
+
id = self.ref_id || children_to_s
|
651
|
+
|
652
|
+
if ref = @doc.refs[sanitize_ref_id(id)] || @doc.refs[sanitize_ref_id(children_to_s)]
|
653
|
+
a['href'] = ref[:url] if ref[:url]
|
654
|
+
a['title'] = ref[:title] if ref[:title]
|
655
|
+
else
|
656
|
+
maruku_error "Could not find ref_id = #{id.inspect} for #{self.inspect}\n" +
|
657
|
+
"Available refs are #{@doc.refs.keys.inspect}"
|
658
|
+
tell_user "Not creating a link for ref_id = #{id.inspect}.\n"
|
659
|
+
if (self.ref_id)
|
660
|
+
return "[#{children_to_s}][#{id}]"
|
661
|
+
else
|
662
|
+
return "[#{children_to_s}]"
|
663
|
+
end
|
664
|
+
end
|
665
|
+
|
666
|
+
wrap_as_element('a', a)
|
667
|
+
end
|
668
|
+
|
669
|
+
def to_html_im_link
|
670
|
+
if self.url
|
671
|
+
a = {}
|
672
|
+
a['href'] = self.url
|
673
|
+
a['title'] = self.title if self.title
|
674
|
+
wrap_as_element('a', a)
|
675
|
+
else
|
676
|
+
maruku_error "Could not find url in #{self.inspect}"
|
677
|
+
tell_user "Not creating a link for ref_id = #{id.inspect}."
|
678
|
+
wrap_as_element('span')
|
679
|
+
end
|
680
|
+
end
|
681
|
+
|
682
|
+
def add_ws(e)
|
683
|
+
[xml_newline, e, xml_newline]
|
684
|
+
end
|
685
|
+
|
686
|
+
##### Email address
|
687
|
+
|
688
|
+
def obfuscate(s)
|
689
|
+
s.bytes.inject('') do |res, char|
|
690
|
+
res << "&#%03d;" % char
|
691
|
+
end
|
692
|
+
end
|
693
|
+
|
694
|
+
def to_html_email_address
|
695
|
+
obfuscated = obfuscate(self.email)
|
696
|
+
html_element('a', obfuscated, :href => "mailto:#{obfuscated}")
|
697
|
+
end
|
698
|
+
|
699
|
+
##### Images
|
700
|
+
|
701
|
+
def to_html_image
|
702
|
+
a = {}
|
703
|
+
id = self.ref_id
|
704
|
+
if ref = @doc.refs[sanitize_ref_id(id)] || @doc.refs[sanitize_ref_id(children_to_s)]
|
705
|
+
a['src'] = ref[:url].to_s
|
706
|
+
a['alt'] = children_to_s
|
707
|
+
a['title'] = ref[:title].to_s if ref[:title]
|
708
|
+
html_element('img', nil, a)
|
709
|
+
else
|
710
|
+
maruku_error "Could not find id = #{id.inspect} for\n #{self.inspect}"
|
711
|
+
tell_user "Could not create image with ref_id = #{id.inspect};" +
|
712
|
+
" Using SPAN element as replacement."
|
713
|
+
wrap_as_element('span')
|
714
|
+
end
|
715
|
+
end
|
716
|
+
|
717
|
+
def to_html_im_image
|
718
|
+
if self.url
|
719
|
+
attrs = {}
|
720
|
+
attrs['src'] = self.url.to_s
|
721
|
+
attrs['alt'] = children_to_s
|
722
|
+
attrs['title'] = self.title.to_s if self.title
|
723
|
+
html_element('img', nil, attrs)
|
724
|
+
else
|
725
|
+
maruku_error "Image with no url: #{self.inspect}"
|
726
|
+
tell_user "Could not create image without a source URL;" +
|
727
|
+
" Using SPAN element as replacement."
|
728
|
+
wrap_as_element('span')
|
729
|
+
end
|
730
|
+
end
|
731
|
+
|
732
|
+
#=begin maruku_doc
|
733
|
+
# Attribute: filter_html
|
734
|
+
# Scope: document
|
735
|
+
#
|
736
|
+
# If true, raw HTML is discarded from the output.
|
737
|
+
#
|
738
|
+
#=end
|
739
|
+
|
740
|
+
def to_html_raw_html
|
741
|
+
return [] if get_setting(:filter_html)
|
742
|
+
return parsed_html.to_html if parsed_html
|
743
|
+
|
744
|
+
# If there's no parsed HTML
|
745
|
+
raw_html = self.raw_html
|
746
|
+
|
747
|
+
# Creates red box with offending HTML
|
748
|
+
tell_user "Wrapping bad html in a PRE with class 'markdown-html-error'\n" +
|
749
|
+
raw_html.gsub(/^/, '|')
|
750
|
+
pre = xelem('pre')
|
751
|
+
pre['style'] = 'border: solid 3px red; background-color: pink'
|
752
|
+
pre['class'] = 'markdown-html-error'
|
753
|
+
pre << xtext("Maruku could not parse this XML/HTML: \n#{raw_html}")
|
754
|
+
end
|
755
|
+
|
756
|
+
def to_html_abbr
|
757
|
+
abbr = xelem('abbr')
|
758
|
+
abbr << xtext(children[0])
|
759
|
+
abbr['title'] = self.title if self.title
|
760
|
+
abbr
|
761
|
+
end
|
762
|
+
|
763
|
+
def to_html_footnote_reference
|
764
|
+
id = self.footnote_id
|
765
|
+
|
766
|
+
# save the order of used footnotes
|
767
|
+
order = @doc.footnotes_order
|
768
|
+
|
769
|
+
# footnote has already been used
|
770
|
+
return [] if order.include?(id)
|
771
|
+
|
772
|
+
return [] unless @doc.footnotes[id]
|
773
|
+
|
774
|
+
# take next number
|
775
|
+
order << id
|
776
|
+
|
777
|
+
num = order.index(id) + 1
|
778
|
+
|
779
|
+
sup = xelem('sup')
|
780
|
+
sup['id'] = "#{get_setting(:doc_prefix)}fnref:#{num}"
|
781
|
+
a = xelem('a')
|
782
|
+
a << xtext(num.to_s)
|
783
|
+
a['href'] = "\##{get_setting(:doc_prefix)}fn:#{num}"
|
784
|
+
a['rel'] = 'footnote'
|
785
|
+
sup << a
|
786
|
+
end
|
787
|
+
|
788
|
+
## Definition lists ###
|
789
|
+
def to_html_definition_list
|
790
|
+
add_ws wrap_as_element('dl')
|
791
|
+
end
|
792
|
+
|
793
|
+
def to_html_definition
|
794
|
+
children_to_html
|
795
|
+
end
|
796
|
+
|
797
|
+
def to_html_definition_term
|
798
|
+
add_ws wrap_as_element('dt')
|
799
|
+
end
|
800
|
+
|
801
|
+
def to_html_definition_data
|
802
|
+
add_ws wrap_as_element('dd')
|
803
|
+
end
|
804
|
+
|
805
|
+
def to_html_table
|
806
|
+
num_columns = self.align.size
|
807
|
+
|
808
|
+
# The table data is passed as a multi-dimensional array
|
809
|
+
# we just need to split the head from the body
|
810
|
+
head, *rows = @children
|
811
|
+
|
812
|
+
table = html_element('table')
|
813
|
+
thead = xelem('thead')
|
814
|
+
tr = xelem('tr')
|
815
|
+
array_to_html(head).inject(tr, &:<<)
|
816
|
+
thead << tr
|
817
|
+
table << thead
|
818
|
+
|
819
|
+
tbody = xelem('tbody')
|
820
|
+
rows.each do |row|
|
821
|
+
tr = xelem('tr')
|
822
|
+
array_to_html(row).each_with_index do |x, i|
|
823
|
+
x['style'] ="text-align: #{self.align[i].to_s};"
|
824
|
+
tr << x
|
825
|
+
end
|
826
|
+
|
827
|
+
tbody << tr << xml_newline
|
828
|
+
end
|
829
|
+
|
830
|
+
table << tbody
|
831
|
+
end
|
832
|
+
|
833
|
+
def to_html_head_cell
|
834
|
+
wrap_as_element('th')
|
835
|
+
end
|
836
|
+
|
837
|
+
def to_html_cell
|
838
|
+
if @attributes[:scope]
|
839
|
+
wrap_as_element('th')
|
840
|
+
else
|
841
|
+
wrap_as_element('td')
|
842
|
+
end
|
843
|
+
end
|
844
|
+
|
845
|
+
def to_html_entity
|
846
|
+
entity_name = self.entity_name
|
847
|
+
|
848
|
+
if entity = MaRuKu::Out::EntityTable.instance.entity(entity_name)
|
849
|
+
entity_name = entity.html_num
|
850
|
+
end
|
851
|
+
|
852
|
+
if entity_name.kind_of? Integer
|
853
|
+
# Convert numeric entities to unicode characters
|
854
|
+
xtext([entity_name].pack('U*'))
|
855
|
+
else
|
856
|
+
"&#{entity_name};"
|
857
|
+
end
|
858
|
+
end
|
859
|
+
|
860
|
+
def to_html_xml_instr
|
861
|
+
target = self.target || ''
|
862
|
+
code = self.code || ''
|
863
|
+
|
864
|
+
# A blank target is invalid XML. Just create a text node?
|
865
|
+
if target.empty?
|
866
|
+
xtext("<?#{code}?>")
|
867
|
+
else
|
868
|
+
"<?#{target} #{code}?>"
|
869
|
+
end
|
870
|
+
end
|
871
|
+
|
872
|
+
# Convert each child to html
|
873
|
+
def children_to_html
|
874
|
+
array_to_html(@children)
|
875
|
+
end
|
876
|
+
|
877
|
+
def array_to_html(array)
|
878
|
+
e = []
|
879
|
+
array.each do |c|
|
880
|
+
if c.kind_of?(String)
|
881
|
+
e << xtext(c)
|
882
|
+
else
|
883
|
+
if c.kind_of?(HTMLElement)
|
884
|
+
e << c
|
885
|
+
next
|
886
|
+
end
|
887
|
+
|
888
|
+
method = c.kind_of?(MaRuKu::MDElement) ? "to_html_#{c.node_type}" : "to_html"
|
889
|
+
next unless c.respond_to?(method)
|
890
|
+
|
891
|
+
h = c.send(method)
|
892
|
+
|
893
|
+
unless h
|
894
|
+
raise "Nil html created by method #{method}:\n#{h.inspect}\n" +
|
895
|
+
" for object #{c.inspect[0,300]}"
|
896
|
+
end
|
897
|
+
|
898
|
+
if h.kind_of? Array
|
899
|
+
e.concat h
|
900
|
+
else
|
901
|
+
e << h
|
902
|
+
end
|
903
|
+
end
|
904
|
+
end
|
905
|
+
e
|
906
|
+
end
|
907
|
+
|
908
|
+
def to_html_ref_definition
|
909
|
+
[]
|
910
|
+
end
|
911
|
+
|
912
|
+
def to_latex_ref_definition
|
913
|
+
[]
|
914
|
+
end
|
915
|
+
end
|