maruku 0.6.1 → 0.7.0.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -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/math.md +14 -18
- data/lib/maruku.rb +65 -77
- data/lib/maruku/attributes.rb +109 -214
- data/lib/maruku/defaults.rb +45 -67
- data/lib/maruku/document.rb +43 -0
- data/lib/maruku/element.rb +112 -0
- data/lib/maruku/errors.rb +71 -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 +107 -113
- data/lib/maruku/ext/math/to_html.rb +184 -187
- data/lib/maruku/ext/math/to_latex.rb +30 -21
- data/lib/maruku/helpers.rb +158 -257
- data/lib/maruku/html.rb +254 -0
- data/lib/maruku/input/charsource.rb +272 -319
- data/lib/maruku/input/extensions.rb +62 -63
- data/lib/maruku/input/html_helper.rb +220 -189
- data/lib/maruku/input/linesource.rb +90 -110
- data/lib/maruku/input/mdline.rb +129 -0
- data/lib/maruku/input/parse_block.rb +618 -612
- data/lib/maruku/input/parse_doc.rb +145 -215
- data/lib/maruku/input/parse_span.rb +658 -0
- data/lib/maruku/input/rubypants.rb +200 -128
- data/lib/maruku/inspect_element.rb +60 -0
- data/lib/maruku/maruku.rb +10 -31
- data/lib/maruku/output/entity_table.rb +33 -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 +898 -983
- data/lib/maruku/output/to_latex.rb +561 -560
- data/lib/maruku/output/to_markdown.rb +207 -162
- data/lib/maruku/output/to_s.rb +11 -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/{tests/unittest → spec/block_docs}/alt.md +2 -14
- data/{tests/unittest/pending → spec/block_docs}/amps.md +1 -13
- 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/{tests/unittest → spec/block_docs}/blank.md +0 -12
- data/{tests/unittest → spec/block_docs}/blanks_in_code.md +16 -15
- data/{tests/unittest/loss.md → spec/block_docs/bug_def.md} +6 -18
- data/{tests/unittest → spec/block_docs}/bug_table.md +3 -15
- 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/{tests/unittest → spec/block_docs}/data_loss.md +2 -14
- 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/{tests/unittest/pending → spec/block_docs}/empty_cells.md +3 -15
- 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 +27 -29
- 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 +3 -15
- data/spec/block_docs/fenced_code_blocks.md +66 -0
- data/spec/block_docs/fenced_code_blocks_highlighted.md +18 -0
- data/{tests/unittest → spec/block_docs}/footnotes.md +12 -24
- data/spec/block_docs/footnotes2.md +78 -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/{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/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 +40 -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} +50 -21
- data/spec/block_docs/lists_nested.md +44 -0
- data/spec/block_docs/lists_nested_blankline.md +28 -0
- data/spec/block_docs/lists_nested_deep.md +43 -0
- data/{tests/unittest → spec/block_docs}/lists_ol.md +37 -54
- data/spec/block_docs/lists_paraindent.md +47 -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 +30 -0
- data/spec/block_docs/math-blahtex/inline.md +48 -0
- data/spec/block_docs/math-blahtex/math2.md +45 -0
- data/spec/block_docs/math-blahtex/table.md +25 -0
- data/spec/block_docs/math/embedded_invalid_svg.md +79 -0
- data/spec/block_docs/math/embedded_svg.md +97 -0
- data/spec/block_docs/math/equations.md +44 -0
- data/{tests/unittest → spec/block_docs}/math/inline.md +7 -19
- data/spec/block_docs/math/math2.md +45 -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/table.md +25 -0
- data/{tests/unittest → spec/block_docs}/math/table2.md +5 -17
- data/{tests/unittest → spec/block_docs}/misc_sw.md +181 -118
- 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 +2 -14
- data/spec/block_docs/tables.md +58 -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/{tests/unittest → spec/block_docs}/xml2.md +0 -12
- data/spec/block_docs/xml3.md +24 -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 +256 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/to_html_utf8_spec.rb +13 -0
- metadata +205 -243
- metadata.gz.sig +3 -0
- data/Rakefile +0 -48
- 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/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/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/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/math/equations.md +0 -86
- 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/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/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
data/docs/math.md
CHANGED
@@ -9,11 +9,7 @@ Math support in Maruku
|
|
9
9
|
|
10
10
|
This document describes Maruku's support of inline LaTeX-style math.
|
11
11
|
|
12
|
-
|
13
|
-
buggy and the syntax and implementation are bound to change in
|
14
|
-
the near future.
|
15
|
-
|
16
|
-
Also, there are many subtleties of which one must care for
|
12
|
+
There are many subtleties of which one must care for
|
17
13
|
correctly serving the XHTML+MathML document to browsers.
|
18
14
|
In fact, *this documentation is __not__ enough to get you started*,
|
19
15
|
unless you feel very adventurous.
|
@@ -118,7 +114,7 @@ You have to enable the math extension like this:
|
|
118
114
|
|
119
115
|
Use the following to choose the engine:
|
120
116
|
|
121
|
-
MaRuKu::Globals[:html_math_engine] = '
|
117
|
+
MaRuKu::Globals[:html_math_engine] = 'itex2mml'
|
122
118
|
MaRuKu::Globals[:html_png_engine] = 'blahtex'
|
123
119
|
|
124
120
|
Available MathML engines are 'none', 'itex2mml', 'blahtex'.
|
@@ -129,21 +125,13 @@ External libraries needed
|
|
129
125
|
|
130
126
|
To output MathML or PNGs, it is needed to install one of the following libraries
|
131
127
|
|
132
|
-
### Using `ritex` ### {#using_ritex}
|
133
|
-
|
134
|
-
Install with
|
135
|
-
|
136
|
-
$ gem install ritex
|
137
|
-
|
138
|
-
ritex's abilities are very limited, but it is the easiest to install.
|
139
|
-
|
140
128
|
### Using `itex2mml` ### {#using_itex2mml}
|
141
129
|
|
142
130
|
itex2mml supports much more LaTeX commands/environments than ritex.
|
143
131
|
|
144
|
-
Install
|
132
|
+
Install itextomml with
|
145
133
|
|
146
|
-
|
134
|
+
$ gem install itextomml
|
147
135
|
|
148
136
|
This is a summary of the available LaTeX commands:
|
149
137
|
|
@@ -152,10 +140,18 @@ This is a summary of the available LaTeX commands:
|
|
152
140
|
Moreover, [Jacques Distler] is integrating Maruku+itex2mml+[Instiki].
|
153
141
|
You can find more information here:
|
154
142
|
|
155
|
-
> <http://golem.ph.utexas.edu
|
143
|
+
> <http://golem.ph.utexas.edu/wiki/instiki/show/HomePage>
|
156
144
|
|
157
145
|
[Jacques Distler]: http://golem.ph.utexas.edu/~distler
|
158
|
-
[instiki]: http://
|
146
|
+
[instiki]: http://golem.ph.utexas.edu/wiki/instiki/show/HomePage
|
147
|
+
|
148
|
+
### Using `ritex` ### {#using_ritex}
|
149
|
+
|
150
|
+
Install with
|
151
|
+
|
152
|
+
$ gem install ritex
|
153
|
+
|
154
|
+
ritex's abilities are very limited, but it is the easiest to install since, unlike `itextomml`, it is a pure-ruby implementation.
|
159
155
|
|
160
156
|
### Using `blahtex` ### {#using_blahtex}
|
161
157
|
|
data/lib/maruku.rb
CHANGED
@@ -1,83 +1,74 @@
|
|
1
1
|
#--
|
2
|
-
#
|
2
|
+
# Copyright (c) 2006 Andrea Censi
|
3
3
|
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
19
22
|
#++
|
20
23
|
|
21
|
-
require 'rexml/document'
|
22
|
-
|
23
|
-
# :include:MaRuKu.txt
|
24
24
|
module MaRuKu
|
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
|
-
end
|
60
|
-
|
61
|
-
|
62
|
-
class MDDocument < MDElement
|
63
|
-
include In::Markdown
|
64
|
-
include In::Markdown::SpanLevelParser
|
65
|
-
include In::Markdown::BlockLevelParser
|
66
|
-
end
|
25
|
+
module In
|
26
|
+
module Markdown
|
27
|
+
module SpanLevelParser; end
|
28
|
+
module BlockLevelParser; end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
module Out
|
33
|
+
module Markdown; end
|
34
|
+
module HTML; end
|
35
|
+
module Latex; end
|
36
|
+
end
|
37
|
+
|
38
|
+
module Strings; end
|
39
|
+
|
40
|
+
module Helpers; end
|
41
|
+
|
42
|
+
module Errors; end
|
43
|
+
|
44
|
+
class MDElement
|
45
|
+
include MaRuKu
|
46
|
+
include Out::Markdown
|
47
|
+
include Out::HTML
|
48
|
+
include Out::Latex
|
49
|
+
include Strings
|
50
|
+
include Helpers
|
51
|
+
include Errors
|
52
|
+
end
|
53
|
+
|
54
|
+
class MDDocument < MDElement
|
55
|
+
include In::Markdown
|
56
|
+
include In::Markdown::SpanLevelParser
|
57
|
+
include In::Markdown::BlockLevelParser
|
58
|
+
end
|
67
59
|
end
|
68
60
|
|
69
|
-
# This is the public interface
|
70
61
|
class Maruku < MaRuKu::MDDocument; end
|
71
62
|
|
72
63
|
|
73
|
-
|
74
|
-
require 'rexml/document'
|
75
|
-
|
76
64
|
# Structures definition
|
77
|
-
require 'maruku/
|
78
|
-
require 'maruku/
|
65
|
+
require 'maruku/attributes'
|
66
|
+
require 'maruku/element'
|
67
|
+
require 'maruku/document'
|
68
|
+
require 'maruku/inspect_element'
|
79
69
|
|
80
70
|
require 'maruku/defaults'
|
71
|
+
|
81
72
|
# Less typing
|
82
73
|
require 'maruku/helpers'
|
83
74
|
|
@@ -87,7 +78,7 @@ require 'maruku/input/parse_doc'
|
|
87
78
|
# Ugly things kept in a closet
|
88
79
|
require 'maruku/string_utils'
|
89
80
|
require 'maruku/input/linesource'
|
90
|
-
require 'maruku/input/
|
81
|
+
require 'maruku/input/mdline'
|
91
82
|
|
92
83
|
# A class for reading and sanitizing inline HTML
|
93
84
|
require 'maruku/input/html_helper'
|
@@ -97,34 +88,32 @@ require 'maruku/input/parse_block'
|
|
97
88
|
|
98
89
|
# Code for parsing Markdown span-level elements
|
99
90
|
require 'maruku/input/charsource'
|
100
|
-
require 'maruku/input/
|
91
|
+
require 'maruku/input/parse_span'
|
101
92
|
require 'maruku/input/rubypants'
|
102
93
|
|
103
94
|
require 'maruku/input/extensions'
|
104
95
|
|
105
|
-
require 'maruku/
|
106
|
-
|
107
|
-
require 'maruku/structures_iterators'
|
108
|
-
|
109
|
-
require 'maruku/errors_management'
|
96
|
+
require 'maruku/errors'
|
110
97
|
|
111
98
|
# Code for creating a table of contents
|
112
99
|
require 'maruku/toc'
|
113
100
|
|
114
101
|
# Support for div Markdown extension
|
115
102
|
require 'maruku/ext/div'
|
103
|
+
# Support for fenced codeblocks extension
|
104
|
+
require 'maruku/ext/fenced_code'
|
116
105
|
|
117
106
|
# Version and URL
|
118
107
|
require 'maruku/version'
|
119
108
|
|
109
|
+
# Entity conversion for HTML and LaTeX
|
110
|
+
require 'maruku/output/entity_table'
|
120
111
|
|
121
112
|
# Exporting to html
|
122
113
|
require 'maruku/output/to_html'
|
123
114
|
|
124
115
|
# Exporting to latex
|
125
116
|
require 'maruku/output/to_latex'
|
126
|
-
require 'maruku/output/to_latex_strings'
|
127
|
-
require 'maruku/output/to_latex_entities'
|
128
117
|
|
129
118
|
# Pretty print
|
130
119
|
require 'maruku/output/to_markdown'
|
@@ -138,4 +127,3 @@ require 'maruku/output/to_s'
|
|
138
127
|
|
139
128
|
# class Maruku is the global interface
|
140
129
|
require 'maruku/maruku'
|
141
|
-
|
data/lib/maruku/attributes.rb
CHANGED
@@ -1,227 +1,122 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
#
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
#++
|
1
|
+
module MaRuKu
|
2
|
+
# This represents a list of attributes specified in the Markdown document
|
3
|
+
# that apply to a Markdown-generated tag.
|
4
|
+
# What was `{#id .class key="val" ref}` in the Markdown
|
5
|
+
# is parsed into `[[:id, 'id'], [:class, 'class'], ['key', 'val'], [:ref, 'ref']]`.
|
6
|
+
class AttributeList < Array
|
7
|
+
def to_s
|
8
|
+
map do |k, v|
|
9
|
+
value = quote_if_needed(v)
|
10
|
+
case k
|
11
|
+
when :id; "#" + value
|
12
|
+
when :class; "." + value
|
13
|
+
when :ref; value
|
14
|
+
else quote_if_needed(k) + "=" + value
|
15
|
+
end
|
16
|
+
end.join(' ')
|
17
|
+
end
|
18
|
+
alias to_md to_s
|
20
19
|
|
20
|
+
private
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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' ]]
|
22
|
+
def quote_if_needed(str)
|
23
|
+
(str =~ /[\s'"]/) ? str.inspect : str
|
24
|
+
end
|
25
|
+
end
|
40
26
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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+""]
|
27
|
+
module In::Markdown::SpanLevelParser
|
28
|
+
def md_al(s = [])
|
29
|
+
AttributeList.new(s)
|
30
|
+
end
|
51
31
|
|
52
|
-
#
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
32
|
+
# @return [AttributeList, nil]
|
33
|
+
def read_attribute_list(src, con=nil, break_on_chars=nil)
|
34
|
+
break_on_chars = Array(break_on_chars)
|
35
|
+
separators = break_on_chars + ['=', ' ', "\t"]
|
36
|
+
escaped = Maruku::EscapedCharInQuotes
|
77
37
|
|
78
|
-
|
79
|
-
|
80
|
-
|
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 `=`." ],
|
38
|
+
al = AttributeList.new
|
39
|
+
loop do
|
40
|
+
src.consume_whitespace
|
41
|
+
break if break_on_chars.include? src.cur_char
|
86
42
|
|
87
|
-
|
88
|
-
|
89
|
-
|
43
|
+
case src.cur_char
|
44
|
+
when ':'
|
45
|
+
src.ignore_char
|
46
|
+
when nil
|
47
|
+
break # we're done here.
|
48
|
+
when '=' # error
|
49
|
+
src.ignore_char
|
50
|
+
maruku_error "In attribute lists, cannot start identifier with `=`."
|
51
|
+
tell_user "Ignoring and continuing."
|
52
|
+
when '#' # id definition
|
53
|
+
src.ignore_char
|
54
|
+
if id = read_quoted_or_unquoted(src, con, escaped, separators)
|
55
|
+
al << [:id, id]
|
56
|
+
else
|
57
|
+
maruku_error 'Could not read `id` attribute.', src, con
|
58
|
+
tell_user 'Ignoring bad `id` attribute.'
|
59
|
+
end
|
60
|
+
when '.' # class definition
|
61
|
+
src.ignore_char
|
62
|
+
if klass = read_quoted_or_unquoted(src, con, escaped, separators)
|
63
|
+
al << [:class, klass]
|
64
|
+
else
|
65
|
+
maruku_error 'Could not read `class` attribute.', src, con
|
66
|
+
tell_user 'Ignoring bad `class` attribute.'
|
67
|
+
end
|
68
|
+
else
|
69
|
+
unless key = read_quoted_or_unquoted(src, con, escaped, separators)
|
70
|
+
maruku_error 'Could not read key or reference.'
|
71
|
+
next
|
72
|
+
end
|
90
73
|
|
91
|
-
|
92
|
-
|
74
|
+
if src.cur_char != '=' && key.length > 0
|
75
|
+
al << [:ref, key]
|
76
|
+
next
|
77
|
+
end
|
93
78
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
79
|
+
src.ignore_char # skip the =
|
80
|
+
if val = read_quoted_or_unquoted(src, con, escaped, separators)
|
81
|
+
al << [key, val]
|
82
|
+
else
|
83
|
+
maruku_error "Could not read value for key #{key.inspect}.", src, con
|
84
|
+
tell_user "Ignoring key #{key.inspect}"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
al
|
89
|
+
end
|
98
90
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
['"', :throw, "Unclosed quotes"],
|
104
|
-
["'"],
|
105
|
-
["'a "],
|
106
|
-
['"a '],
|
107
|
-
|
108
|
-
[ "#a", [[:id, 'a']], "Simple ID" ],
|
109
|
-
[ "#'a'" ],
|
110
|
-
[ '#"a"' ],
|
91
|
+
def merge_ial(elements, src, con)
|
92
|
+
# Apply each IAL to the element before
|
93
|
+
(elements + [nil]).each_cons(3) do |before, e, after|
|
94
|
+
next unless ial?(e)
|
111
95
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
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
|
96
|
+
if before.kind_of? MDElement
|
97
|
+
before.al = e.ial
|
98
|
+
elsif after.kind_of? MDElement
|
99
|
+
after.al = e.ial
|
100
|
+
else
|
101
|
+
maruku_error <<ERR, src, con
|
102
|
+
It's unclear which element the attribute list {:#{e.ial.to_s}}
|
103
|
+
is referring to. The element before is a #{before.class},
|
104
|
+
the element after is a #{after.class}.
|
105
|
+
before: #{before.inspect}
|
106
|
+
after: #{after.inspect}
|
107
|
+
ERR
|
108
|
+
end
|
109
|
+
end
|
133
110
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
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
|
111
|
+
unless Globals[:debug_keep_ials]
|
112
|
+
elements.delete_if {|x| ial?(x) && x != elements.first}
|
113
|
+
end
|
114
|
+
end
|
197
115
|
|
198
|
-
|
116
|
+
private
|
199
117
|
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
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
|
118
|
+
def ial?(e)
|
119
|
+
e.is_a?(MDElement) && e.node_type == :ial
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|