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.
Files changed (263) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/MIT-LICENSE.txt +20 -0
  5. data/bin/maruku +153 -152
  6. data/bin/marutex +2 -29
  7. data/data/entities.xml +261 -0
  8. data/docs/math.md +14 -18
  9. data/lib/maruku.rb +65 -77
  10. data/lib/maruku/attributes.rb +109 -214
  11. data/lib/maruku/defaults.rb +45 -67
  12. data/lib/maruku/document.rb +43 -0
  13. data/lib/maruku/element.rb +112 -0
  14. data/lib/maruku/errors.rb +71 -0
  15. data/lib/maruku/ext/div.rb +105 -113
  16. data/lib/maruku/ext/fenced_code.rb +97 -0
  17. data/lib/maruku/ext/math.rb +22 -26
  18. data/lib/maruku/ext/math/elements.rb +20 -26
  19. data/lib/maruku/ext/math/mathml_engines/blahtex.rb +92 -104
  20. data/lib/maruku/ext/math/mathml_engines/itex2mml.rb +33 -26
  21. data/lib/maruku/ext/math/mathml_engines/none.rb +11 -19
  22. data/lib/maruku/ext/math/mathml_engines/ritex.rb +2 -4
  23. data/lib/maruku/ext/math/parsing.rb +107 -113
  24. data/lib/maruku/ext/math/to_html.rb +184 -187
  25. data/lib/maruku/ext/math/to_latex.rb +30 -21
  26. data/lib/maruku/helpers.rb +158 -257
  27. data/lib/maruku/html.rb +254 -0
  28. data/lib/maruku/input/charsource.rb +272 -319
  29. data/lib/maruku/input/extensions.rb +62 -63
  30. data/lib/maruku/input/html_helper.rb +220 -189
  31. data/lib/maruku/input/linesource.rb +90 -110
  32. data/lib/maruku/input/mdline.rb +129 -0
  33. data/lib/maruku/input/parse_block.rb +618 -612
  34. data/lib/maruku/input/parse_doc.rb +145 -215
  35. data/lib/maruku/input/parse_span.rb +658 -0
  36. data/lib/maruku/input/rubypants.rb +200 -128
  37. data/lib/maruku/inspect_element.rb +60 -0
  38. data/lib/maruku/maruku.rb +10 -31
  39. data/lib/maruku/output/entity_table.rb +33 -0
  40. data/lib/maruku/output/s5/fancy.rb +462 -462
  41. data/lib/maruku/output/s5/to_s5.rb +115 -135
  42. data/lib/maruku/output/to_html.rb +898 -983
  43. data/lib/maruku/output/to_latex.rb +561 -560
  44. data/lib/maruku/output/to_markdown.rb +207 -162
  45. data/lib/maruku/output/to_s.rb +11 -52
  46. data/lib/maruku/string_utils.rb +129 -179
  47. data/lib/maruku/toc.rb +185 -196
  48. data/lib/maruku/version.rb +33 -38
  49. data/spec/block_docs/abbrev.md +776 -0
  50. data/{tests/unittest → spec/block_docs}/abbreviations.md +11 -20
  51. data/{tests/unittest → spec/block_docs}/alt.md +2 -14
  52. data/{tests/unittest/pending → spec/block_docs}/amps.md +1 -13
  53. data/{tests/unittest → spec/block_docs}/attributes/att2.md +0 -12
  54. data/{tests/unittest → spec/block_docs}/attributes/att3.md +2 -14
  55. data/{tests/unittest → spec/block_docs}/attributes/attributes.md +12 -16
  56. data/{tests/unittest → spec/block_docs}/attributes/circular.md +0 -12
  57. data/{tests/unittest → spec/block_docs}/attributes/default.md +1 -13
  58. data/{tests/unittest → spec/block_docs}/blank.md +0 -12
  59. data/{tests/unittest → spec/block_docs}/blanks_in_code.md +16 -15
  60. data/{tests/unittest/loss.md → spec/block_docs/bug_def.md} +6 -18
  61. data/{tests/unittest → spec/block_docs}/bug_table.md +3 -15
  62. data/{tests/unittest → spec/block_docs}/code.md +7 -14
  63. data/{tests/unittest → spec/block_docs}/code2.md +4 -14
  64. data/{tests/unittest → spec/block_docs}/code3.md +12 -16
  65. data/{tests/unittest → spec/block_docs}/data_loss.md +2 -14
  66. data/{tests/unittest → spec/block_docs}/divs/div1.md +0 -12
  67. data/{tests/unittest → spec/block_docs}/divs/div2.md +0 -12
  68. data/{tests/unittest → spec/block_docs}/divs/div3_nest.md +3 -15
  69. data/{tests/unittest → spec/block_docs}/easy.md +1 -13
  70. data/spec/block_docs/email.md +29 -0
  71. data/{tests/unittest/pending → spec/block_docs}/empty_cells.md +3 -15
  72. data/{tests/unittest → spec/block_docs}/encoding/iso-8859-1.md +1 -14
  73. data/{tests/unittest → spec/block_docs}/encoding/utf-8.md +0 -12
  74. data/{tests/unittest → spec/block_docs}/entities.md +27 -29
  75. data/{tests/unittest/notyet → spec/block_docs}/escape.md +2 -14
  76. data/{tests/unittest → spec/block_docs}/escaping.md +11 -22
  77. data/{tests/unittest → spec/block_docs}/extra_dl.md +2 -13
  78. data/{tests/unittest → spec/block_docs}/extra_header_id.md +14 -20
  79. data/{tests/unittest → spec/block_docs}/extra_table1.md +3 -15
  80. data/spec/block_docs/fenced_code_blocks.md +66 -0
  81. data/spec/block_docs/fenced_code_blocks_highlighted.md +18 -0
  82. data/{tests/unittest → spec/block_docs}/footnotes.md +12 -24
  83. data/spec/block_docs/footnotes2.md +78 -0
  84. data/spec/block_docs/hard.md +25 -0
  85. data/spec/block_docs/header_after_par.md +62 -0
  86. data/{tests/unittest → spec/block_docs}/headers.md +10 -18
  87. data/{tests/unittest → spec/block_docs}/hex_entities.md +7 -18
  88. data/{tests/unittest → spec/block_docs}/hrule.md +5 -12
  89. data/{tests/unittest → spec/block_docs}/html3.md +1 -13
  90. data/{tests/unittest → spec/block_docs}/html4.md +2 -14
  91. data/{tests/unittest → spec/block_docs}/html5.md +2 -14
  92. data/spec/block_docs/html_block_in_para.md +22 -0
  93. data/spec/block_docs/html_inline.md +25 -0
  94. data/spec/block_docs/html_trailing.md +31 -0
  95. data/spec/block_docs/ie.md +62 -0
  96. data/spec/block_docs/iframe.md +29 -0
  97. data/{tests/unittest → spec/block_docs}/images.md +22 -28
  98. data/{tests/unittest → spec/block_docs}/images2.md +7 -17
  99. data/{tests/unittest → spec/block_docs}/inline_html.md +37 -67
  100. data/{tests/unittest → spec/block_docs}/inline_html2.md +1 -13
  101. data/spec/block_docs/inline_html_beginning.md +10 -0
  102. data/spec/block_docs/issue20.md +9 -0
  103. data/spec/block_docs/issue26.md +22 -0
  104. data/spec/block_docs/issue29.md +9 -0
  105. data/spec/block_docs/issue30.md +30 -0
  106. data/spec/block_docs/issue31.md +25 -0
  107. data/spec/block_docs/issue40.md +40 -0
  108. data/spec/block_docs/issue64.md +55 -0
  109. data/spec/block_docs/issue67.md +19 -0
  110. data/spec/block_docs/issue70.md +11 -0
  111. data/spec/block_docs/issue72.md +17 -0
  112. data/spec/block_docs/issue74.md +38 -0
  113. data/spec/block_docs/issue79.md +15 -0
  114. data/spec/block_docs/issue83.md +13 -0
  115. data/spec/block_docs/issue85.md +25 -0
  116. data/spec/block_docs/issue88.md +19 -0
  117. data/spec/block_docs/issue89.md +12 -0
  118. data/spec/block_docs/issue90.md +38 -0
  119. data/{tests/unittest/pending → spec/block_docs}/link.md +21 -18
  120. data/{tests/unittest → spec/block_docs}/links.md +33 -32
  121. data/spec/block_docs/links2.md +21 -0
  122. data/{tests/unittest → spec/block_docs}/list1.md +0 -12
  123. data/{tests/unittest → spec/block_docs}/list12.md +2 -14
  124. data/{tests/unittest → spec/block_docs}/list2.md +2 -14
  125. data/spec/block_docs/list_multipara.md +42 -0
  126. data/{tests/unittest → spec/block_docs}/lists.md +28 -29
  127. data/{tests/unittest → spec/block_docs}/lists10.md +2 -14
  128. data/spec/block_docs/lists11.md +23 -0
  129. data/spec/block_docs/lists12.md +43 -0
  130. data/spec/block_docs/lists13.md +55 -0
  131. data/spec/block_docs/lists14.md +61 -0
  132. data/spec/block_docs/lists15.md +36 -0
  133. data/spec/block_docs/lists6.md +88 -0
  134. data/spec/block_docs/lists7b.md +58 -0
  135. data/spec/block_docs/lists9.md +53 -0
  136. data/{tests/unittest → spec/block_docs}/lists_after_paragraph.md +19 -25
  137. data/spec/block_docs/lists_blank.md +35 -0
  138. data/{tests/unittest/list3.md → spec/block_docs/lists_blockquote_code.md} +2 -14
  139. data/{tests/unittest/list4.md → spec/block_docs/lists_need_blank_line.md} +50 -21
  140. data/spec/block_docs/lists_nested.md +44 -0
  141. data/spec/block_docs/lists_nested_blankline.md +28 -0
  142. data/spec/block_docs/lists_nested_deep.md +43 -0
  143. data/{tests/unittest → spec/block_docs}/lists_ol.md +37 -54
  144. data/spec/block_docs/lists_paraindent.md +47 -0
  145. data/spec/block_docs/lists_tab.md +54 -0
  146. data/spec/block_docs/loss.md +17 -0
  147. data/spec/block_docs/math-blahtex/equations.md +30 -0
  148. data/spec/block_docs/math-blahtex/inline.md +48 -0
  149. data/spec/block_docs/math-blahtex/math2.md +45 -0
  150. data/spec/block_docs/math-blahtex/table.md +25 -0
  151. data/spec/block_docs/math/embedded_invalid_svg.md +79 -0
  152. data/spec/block_docs/math/embedded_svg.md +97 -0
  153. data/spec/block_docs/math/equations.md +44 -0
  154. data/{tests/unittest → spec/block_docs}/math/inline.md +7 -19
  155. data/spec/block_docs/math/math2.md +45 -0
  156. data/{tests/unittest → spec/block_docs}/math/notmath.md +0 -12
  157. data/spec/block_docs/math/raw_mathml.md +87 -0
  158. data/spec/block_docs/math/table.md +25 -0
  159. data/{tests/unittest → spec/block_docs}/math/table2.md +5 -17
  160. data/{tests/unittest → spec/block_docs}/misc_sw.md +181 -118
  161. data/{tests/unittest → spec/block_docs}/olist.md +6 -18
  162. data/{tests/unittest → spec/block_docs}/one.md +0 -12
  163. data/{tests/unittest → spec/block_docs}/paragraph.md +0 -12
  164. data/{tests/unittest → spec/block_docs}/paragraph_rules/dont_merge_ref.md +4 -12
  165. data/{tests/unittest → spec/block_docs}/paragraph_rules/tab_is_blank.md +0 -12
  166. data/{tests/unittest → spec/block_docs}/paragraphs.md +1 -13
  167. data/{tests/unittest → spec/block_docs}/recover/recover_links.md +4 -16
  168. data/{tests/unittest/pending/ref.md → spec/block_docs/ref_with_period.md} +7 -16
  169. data/spec/block_docs/ref_with_title.md +22 -0
  170. data/{tests/unittest → spec/block_docs}/references/long_example.md +16 -23
  171. data/{tests/unittest → spec/block_docs}/references/spaces_and_numbers.md +0 -12
  172. data/{tests/unittest → spec/block_docs}/smartypants.md +24 -31
  173. data/{tests/unittest → spec/block_docs}/syntax_hl.md +13 -17
  174. data/{tests/unittest → spec/block_docs}/table_attributes.md +2 -14
  175. data/spec/block_docs/tables.md +58 -0
  176. data/{tests/unittest → spec/block_docs}/test.md +1 -13
  177. data/{tests/unittest/notyet → spec/block_docs}/ticks.md +1 -13
  178. data/spec/block_docs/toc.md +87 -0
  179. data/{tests/unittest/notyet → spec/block_docs}/triggering.md +14 -25
  180. data/{tests/unittest → spec/block_docs}/underscore_in_words.md +0 -12
  181. data/{tests/unittest → spec/block_docs}/wrapping.md +4 -16
  182. data/spec/block_docs/xml.md +33 -0
  183. data/{tests/unittest → spec/block_docs}/xml2.md +0 -12
  184. data/spec/block_docs/xml3.md +24 -0
  185. data/{tests/unittest → spec/block_docs}/xml_instruction.md +9 -20
  186. data/spec/block_spec.rb +110 -0
  187. data/spec/cli_spec.rb +8 -0
  188. data/spec/span_spec.rb +256 -0
  189. data/spec/spec_helper.rb +2 -0
  190. data/spec/to_html_utf8_spec.rb +13 -0
  191. metadata +205 -243
  192. metadata.gz.sig +3 -0
  193. data/Rakefile +0 -48
  194. data/bin/marudown +0 -29
  195. data/bin/marutest +0 -345
  196. data/docs/changelog.md +0 -334
  197. data/lib/maruku/errors_management.rb +0 -92
  198. data/lib/maruku/ext/math/latex_fix.rb +0 -12
  199. data/lib/maruku/input/parse_span_better.rb +0 -746
  200. data/lib/maruku/input/type_detection.rb +0 -147
  201. data/lib/maruku/output/to_latex_entities.rb +0 -367
  202. data/lib/maruku/output/to_latex_strings.rb +0 -64
  203. data/lib/maruku/structures.rb +0 -167
  204. data/lib/maruku/structures_inspect.rb +0 -87
  205. data/lib/maruku/structures_iterators.rb +0 -61
  206. data/lib/maruku/tests/benchmark.rb +0 -82
  207. data/lib/maruku/tests/new_parser.rb +0 -373
  208. data/lib/maruku/tests/tests.rb +0 -136
  209. data/lib/maruku/usage/example1.rb +0 -33
  210. data/tests/bugs/code_in_links.md +0 -101
  211. data/tests/bugs/complex_escaping.md +0 -38
  212. data/tests/math/syntax.md +0 -46
  213. data/tests/math_usage/document.md +0 -13
  214. data/tests/others/abbreviations.md +0 -11
  215. data/tests/others/blank.md +0 -4
  216. data/tests/others/code.md +0 -5
  217. data/tests/others/code2.md +0 -8
  218. data/tests/others/code3.md +0 -16
  219. data/tests/others/email.md +0 -4
  220. data/tests/others/entities.md +0 -19
  221. data/tests/others/escaping.md +0 -16
  222. data/tests/others/extra_dl.md +0 -101
  223. data/tests/others/extra_header_id.md +0 -13
  224. data/tests/others/extra_table1.md +0 -40
  225. data/tests/others/footnotes.md +0 -17
  226. data/tests/others/headers.md +0 -10
  227. data/tests/others/hrule.md +0 -10
  228. data/tests/others/images.md +0 -20
  229. data/tests/others/inline_html.md +0 -42
  230. data/tests/others/links.md +0 -38
  231. data/tests/others/list1.md +0 -4
  232. data/tests/others/list2.md +0 -5
  233. data/tests/others/list3.md +0 -8
  234. data/tests/others/lists.md +0 -32
  235. data/tests/others/lists_after_paragraph.md +0 -44
  236. data/tests/others/lists_ol.md +0 -39
  237. data/tests/others/misc_sw.md +0 -105
  238. data/tests/others/one.md +0 -1
  239. data/tests/others/paragraphs.md +0 -13
  240. data/tests/others/sss06.md +0 -352
  241. data/tests/others/test.md +0 -4
  242. data/tests/s5/s5profiling.md +0 -48
  243. data/tests/unittest/bug_def.md +0 -28
  244. data/tests/unittest/email.md +0 -32
  245. data/tests/unittest/html2.md +0 -34
  246. data/tests/unittest/ie.md +0 -61
  247. data/tests/unittest/links2.md +0 -34
  248. data/tests/unittest/lists11.md +0 -28
  249. data/tests/unittest/lists6.md +0 -53
  250. data/tests/unittest/lists9.md +0 -76
  251. data/tests/unittest/math/equations.md +0 -86
  252. data/tests/unittest/math/math2.md +0 -57
  253. data/tests/unittest/math/table.md +0 -37
  254. data/tests/unittest/notyet/header_after_par.md +0 -70
  255. data/tests/unittest/red_tests/abbrev.md +0 -1388
  256. data/tests/unittest/red_tests/lists7.md +0 -68
  257. data/tests/unittest/red_tests/lists7b.md +0 -128
  258. data/tests/unittest/red_tests/lists8.md +0 -76
  259. data/tests/unittest/red_tests/xml.md +0 -70
  260. data/tests/unittest/xml3.md +0 -38
  261. data/tests/utf8-files/simple.md +0 -1
  262. data/unit_test_block.sh +0 -5
  263. data/unit_test_span.sh +0 -3
@@ -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
- At the moment, **these features are experimental**, are probably
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] = 'ritex'
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 itex2mml using the instructions at:
132
+ Install itextomml with
145
133
 
146
- > <http://golem.ph.utexas.edu/~distler/blog/itex2MML.html>
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/~distler/blog/archives/001111.html>
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://www.instiki.org
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
 
@@ -1,83 +1,74 @@
1
1
  #--
2
- # Copyright (C) 2006 Andrea Censi <andrea (at) rubyforge.org>
2
+ # Copyright (c) 2006 Andrea Censi
3
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
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
- module In
27
- module Markdown
28
- module SpanLevelParser; end
29
- module BlockLevelParser; end
30
- end
31
- # more to come?
32
- end
33
-
34
- module Out
35
- # Functions for exporting to MarkDown.
36
- module Markdown; end
37
- # Functions for exporting to HTML.
38
- module HTML; end
39
- # Functions for exporting to Latex
40
- module Latex; end
41
- end
42
-
43
- # These are strings utilities.
44
- module Strings; end
45
-
46
- module Helpers; end
47
-
48
- module Errors; end
49
-
50
- class MDElement
51
- include REXML
52
- include MaRuKu
53
- include Out::Markdown
54
- include Out::HTML
55
- include Out::Latex
56
- include Strings
57
- include Helpers
58
- include Errors
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/structures'
78
- require 'maruku/structures_inspect'
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/type_detection'
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/parse_span_better'
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/attributes'
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
-
@@ -1,227 +1,122 @@
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
- #++
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
- class String
23
- def quote_if_needed
24
- if /[\s\'\"]/.match self
25
- inspect
26
- else
27
- self
28
- end
29
- end
30
- end
31
-
32
- module MaRuKu;
33
- MagicChar = ':'
34
-
35
- class AttributeList < Array
36
-
37
- # An attribute list becomes
38
- # {#id .cl key="val" ref}
39
- # [ [:id, 'id'], [:class, 'id'], ['key', 'val'], [ :ref, 'ref' ]]
22
+ def quote_if_needed(str)
23
+ (str =~ /[\s'"]/) ? str.inspect : str
24
+ end
25
+ end
40
26
 
41
- private :push
42
-
43
- def push_key_val(key, val);
44
- raise "Bad #{key.inspect}=#{val.inspect}" if not key and val
45
- push [key, val]
46
- end
47
- def push_ref(ref_id);
48
-
49
- raise "Bad :ref #{ref_id.inspect}" if not ref_id
50
- push [:ref, ref_id+""]
27
+ module In::Markdown::SpanLevelParser
28
+ def md_al(s = [])
29
+ AttributeList.new(s)
30
+ end
51
31
 
52
- # p "Now ", self ########################################
53
- end
54
- def push_class(val);
55
- raise "Bad :id #{val.inspect}" if not val
56
- push [:class, val]
57
- end
58
- def push_id(val);
59
- raise "Bad :id #{val.inspect}" if not val
60
- push [:id, val]
61
- end
62
-
63
- def to_s
64
- map do |k,v|
65
- case k
66
- when :id; "#" + v.quote_if_needed
67
- when :class; "." + v.quote_if_needed
68
- when :ref; v.quote_if_needed
69
- else k.quote_if_needed + "=" + v.quote_if_needed
70
- end
71
- end . join(' ')
72
- end
73
- alias to_md to_s
74
- end
75
-
76
- end
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
- module MaRuKu; module In; module Markdown; module SpanLevelParser
79
-
80
- def unit_tests_for_attribute_lists
81
- [
82
- [ "", [], "Empty lists are allowed" ],
83
- [ "=", :throw, "Bad char to begin a list with." ],
84
- [ "a =b", :throw, "No whitespace before `=`." ],
85
- [ "a= b", :throw, "No whitespace after `=`." ],
38
+ al = AttributeList.new
39
+ loop do
40
+ src.consume_whitespace
41
+ break if break_on_chars.include? src.cur_char
86
42
 
87
- [ "a b", [[:ref, 'a'],[:ref, 'b']], "More than one ref" ],
88
- [ "a b c", [[:ref, 'a'],[:ref, 'b'],[:ref, 'c']], "More than one ref" ],
89
- [ "hello notfound", [[:ref, 'hello'],[:ref, 'notfound']]],
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
- [ "'a'", [[:ref, 'a']], "Quoted value." ],
92
- [ '"a"' ],
74
+ if src.cur_char != '=' && key.length > 0
75
+ al << [:ref, key]
76
+ next
77
+ end
93
78
 
94
- [ "a=b", [['a','b']], "Simple key/val" ],
95
- [ "'a'=b" ],
96
- [ "'a'='b'" ],
97
- [ "a='b'" ],
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
- [ 'a="b\'"', [['a',"b\'"]], "Key/val with quotes" ],
100
- [ 'a=b\''],
101
- [ 'a="\\\'b\'"', [['a',"\'b\'"]], "Key/val with quotes" ],
102
-
103
- ['"', :throw, "Unclosed quotes"],
104
- ["'"],
105
- ["'a "],
106
- ['"a '],
107
-
108
- [ "#a", [[:id, 'a']], "Simple ID" ],
109
- [ "#'a'" ],
110
- [ '#"a"' ],
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
- [ "#", :throw, "Unfinished '#'." ],
113
- [ ".", :throw, "Unfinished '.'." ],
114
- [ "# a", :throw, "No white-space after '#'." ],
115
- [ ". a", :throw, "No white-space after '.' ." ],
116
-
117
- [ "a=b c=d", [['a','b'],['c','d']], "Tabbing" ],
118
- [ " \ta=b \tc='d' "],
119
- [ "\t a=b\t c='d'\t\t"],
120
-
121
- [ ".\"a'", :throw, "Mixing quotes is bad." ],
122
-
123
- ].map { |s, expected, comment|
124
- @expected = (expected ||= @expected)
125
- @comment = (comment ||= (last=@comment) )
126
- (comment == last && (comment += (@count+=1).to_s)) || @count = 1
127
- expected = [md_ial(expected)] if expected.kind_of? Array
128
- ["{#{MagicChar}#{s}}", expected, "Attributes: #{comment}"]
129
- }
130
- end
131
-
132
- def md_al(s=[]); AttributeList.new(s) end
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
- # returns nil or an AttributeList
135
- def read_attribute_list(src, con, break_on_chars)
136
-
137
- separators = break_on_chars + [?=,?\ ,?\t]
138
- escaped = Maruku::EscapedCharInQuotes
139
-
140
- al = AttributeList.new
141
- while true
142
- src.consume_whitespace
143
- break if break_on_chars.include? src.cur_char
144
-
145
- case src.cur_char
146
- when nil
147
- maruku_error "Attribute list terminated by EOF:\n "+
148
- "#{al.inspect}" , src, con
149
- tell_user "I try to continue and return partial attribute list:\n"+
150
- al.inspect
151
- break
152
- when ?= # error
153
- maruku_error "In attribute lists, cannot start identifier with `=`."
154
- tell_user "I try to continue"
155
- src.ignore_char
156
- when ?# # id definition
157
- src.ignore_char
158
- if id = read_quoted_or_unquoted(src, con, escaped, separators)
159
- al.push_id id
160
- else
161
- maruku_error 'Could not read `id` attribute.', src, con
162
- tell_user 'Trying to ignore bad `id` attribute.'
163
- end
164
- when ?. # class definition
165
- src.ignore_char
166
- if klass = read_quoted_or_unquoted(src, con, escaped, separators)
167
- al.push_class klass
168
- else
169
- maruku_error 'Could not read `class` attribute.', src, con
170
- tell_user 'Trying to ignore bad `class` attribute.'
171
- end
172
- else
173
- if key = read_quoted_or_unquoted(src, con, escaped, separators)
174
- if src.cur_char == ?=
175
- src.ignore_char # skip the =
176
- if val = read_quoted_or_unquoted(src, con, escaped, separators)
177
- al.push_key_val(key, val)
178
- else
179
- maruku_error "Could not read value for key #{key.inspect}.",
180
- src, con
181
- tell_user "Ignoring key #{key.inspect}."
182
- end
183
- else
184
- al.push_ref key
185
- end
186
- else
187
- maruku_error 'Could not read key or reference.'
188
- end
189
- end # case
190
- end # while true
191
- al
192
- end
193
-
194
-
195
- # We need a helper
196
- def is_ial(e); e.kind_of? MDElement and e.node_type == :ial end
111
+ unless Globals[:debug_keep_ials]
112
+ elements.delete_if {|x| ial?(x) && x != elements.first}
113
+ end
114
+ end
197
115
 
198
- def merge_ial(elements, src, con)
116
+ private
199
117
 
200
- # Apply each IAL to the element before
201
- elements.each_with_index do |e, i|
202
- if is_ial(e) && i>= 1 then
203
- before = elements[i-1]
204
- after = elements[i+1]
205
- if before.kind_of? MDElement
206
- before.al = e.ial
207
- elsif after.kind_of? MDElement
208
- after.al = e.ial
209
- else
210
- maruku_error "It is not clear to me what element this IAL {:#{e.ial.to_md}} \n"+
211
- "is referring to. The element before is a #{before.class.to_s}, \n"+
212
- "the element after is a #{after.class.to_s}.\n"+
213
- "\n before: #{before.inspect}"+
214
- "\n after: #{after.inspect}",
215
- src, con
216
- # xxx dire se c'è empty vicino
217
- end
218
- end
219
- end
220
-
221
- if not Globals[:debug_keep_ials]
222
- elements.delete_if {|x| is_ial(x) unless x == elements.first}
223
- end
224
- end
225
-
226
- end end end end
227
- #module MaRuKu; module In; module Markdown; module SpanLevelParser
118
+ def ial?(e)
119
+ e.is_a?(MDElement) && e.node_type == :ial
120
+ end
121
+ end
122
+ end