maruku 0.6.1 → 0.7.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,147 +0,0 @@
1
- #--
2
- # Copyright (C) 2006 Andrea Censi <andrea (at) rubyforge.org>
3
- #
4
- # This file is part of Maruku.
5
- #
6
- # Maruku is free software; you can redistribute it and/or modify
7
- # it under the terms of the GNU General Public License as published by
8
- # the Free Software Foundation; either version 2 of the License, or
9
- # (at your option) any later version.
10
- #
11
- # Maruku is distributed in the hope that it will be useful,
12
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- # GNU General Public License for more details.
15
- #
16
- # You should have received a copy of the GNU General Public License
17
- # along with Maruku; if not, write to the Free Software
18
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
- #++
20
-
21
- class String
22
- include MaRuKu::Strings
23
- def md_type()
24
- @md_type ||= line_md_type(self)
25
- end
26
- end
27
-
28
- class NilClass
29
- def md_type() nil end
30
-
31
- end
32
-
33
- # This code does the classification of lines for block-level parsing.
34
- module MaRuKu; module Strings
35
-
36
- def line_md_type(l)
37
- # The order of evaluation is important (:text is a catch-all)
38
- return :text if l =~ /^[a-zA-Z]/
39
- return :code if number_of_leading_spaces(l)>=4
40
- return :empty if l =~ /^\s*$/
41
- return :footnote_text if l =~ FootnoteText
42
- return :ref_definition if l =~ LinkRegex or l=~ IncompleteLink
43
- return :abbreviation if l =~ Abbreviation
44
- return :definition if l =~ Definition
45
- # I had a bug with emails and urls at the beginning of the
46
- # line that were mistaken for raw_html
47
- return :text if l=~ /^[ ]{0,3}#{EMailAddress}/
48
- return :text if l=~ /^[ ]{0,3}<http:/
49
- # raw html is like PHP Markdown Extra: at most three spaces before
50
- return :xml_instr if l =~ %r{^\s*<\?}
51
- return :raw_html if l =~ %r{^[ ]?[ ]?[ ]?</?\s*\w+}
52
- return :raw_html if l =~ %r{^[ ]?[ ]?[ ]?<\!\-\-}
53
- # Something is wrong with how we parse lists! :-(
54
- #return :ulist if l =~ /^[ ]{0,3}([\*\-\+])\s+.*\w+/
55
- #return :olist if l =~ /^[ ]{0,3}\d+\..*\w+/
56
- return :ulist if l =~ /^[ ]{0,1}([\*\-\+])\s+.*\w+/
57
- return :olist if l =~ /^[ ]{0,1}\d+\..*\w+/
58
- return :header1 if l =~ /^(=)+/
59
- return :header2 if l =~ /^([-\s])+$/
60
- return :header3 if l =~ /^(#)+\s*\S+/
61
- # at least three asterisks on a line, and only whitespace
62
- return :hrule if l =~ /^(\s*\*\s*){3,1000}$/
63
- return :hrule if l =~ /^(\s*-\s*){3,1000}$/ # or hyphens
64
- return :hrule if l =~ /^(\s*_\s*){3,1000}$/ # or underscores
65
- return :quote if l =~ /^>/
66
- return :metadata if l =~ /^@/
67
- # if @@new_meta_data?
68
- return :ald if l =~ AttributeDefinitionList
69
- return :ial if l =~ InlineAttributeList
70
- # end
71
- # return :equation_end if l =~ EquationEnd
72
- return :text # else, it's just text
73
- end
74
-
75
-
76
- # $1 = id $2 = attribute list
77
- AttributeDefinitionList = /^\s{0,3}\{([\w\d\s]+)\}:\s*(.*)\s*$/
78
- #
79
- InlineAttributeList = /^\s{0,3}\{([:#\.].*)\}\s*$/
80
- # Example:
81
- # ^:blah blah
82
- # ^: blah blah
83
- # ^ : blah blah
84
- Definition = %r{
85
- ^ # begin of line
86
- [ ]{0,3} # up to 3 spaces
87
- : # colon
88
- \s* # whitespace
89
- (\S.*) # the text = $1
90
- $ # end of line
91
- }x
92
-
93
- # Example:
94
- # *[HTML]: Hyper Text Markup Language
95
- Abbreviation = %r{
96
- ^ # begin of line
97
- [ ]{0,3} # up to 3 spaces
98
- \* # one asterisk
99
- \[ # opening bracket
100
- ([^\]]+) # any non-closing bracket: id = $1
101
- \] # closing bracket
102
- : # colon
103
- \s* # whitespace
104
- (\S.*\S)* # definition=$2
105
- \s* # strip this whitespace
106
- $ # end of line
107
- }x
108
-
109
- FootnoteText = %r{
110
- ^ # begin of line
111
- [ ]{0,3} # up to 3 spaces
112
- \[(\^.+)\]: # id = $1 (including '^')
113
- \s*(\S.*)?$ # text = $2 (not obb.)
114
- }x
115
-
116
- # This regex is taken from BlueCloth sources
117
- # Link defs are in the form: ^[id]: \n? url "optional title"
118
- LinkRegex = %r{
119
- ^[ ]{0,3}\[([^\[\]]+)\]: # id = $1
120
- [ ]*
121
- <?([^>\s]+)>? # url = $2
122
- [ ]*
123
- (?:# Titles are delimited by "quotes" or (parens).
124
- ["(']
125
- (.+?) # title = $3
126
- [")'] # Matching ) or "
127
- \s*(.+)? # stuff = $4
128
- )? # title is optional
129
- }x
130
-
131
- IncompleteLink = %r{^[ ]{0,3}\[([^\[\]]+)\]:\s*$}
132
-
133
- HeaderWithId = /^(.*)\{\#([\w_-]+)\}\s*$/
134
-
135
- HeaderWithAttributes = /^(.*)\{(.*)\}\s*$/
136
-
137
-
138
- # if contains a pipe, it could be a table header
139
- MightBeTableHeader = %r{\|}
140
- # -------------:
141
- Sep = /\s*(\:)?\s*-+\s*(\:)?\s*/
142
- # | -------------:| ------------------------------ |
143
- TableSeparator = %r{^(\|?#{Sep}\|?)+\s*$}
144
-
145
-
146
- EMailAddress = /<([^:]+@[^:]+)>/
147
- end end
@@ -1,367 +0,0 @@
1
- #--
2
- # Copyright (C) 2006 Andrea Censi <andrea (at) rubyforge.org>
3
- #
4
- # This file is part of Maruku.
5
- #
6
- # Maruku is free software; you can redistribute it and/or modify
7
- # it under the terms of the GNU General Public License as published by
8
- # the Free Software Foundation; either version 2 of the License, or
9
- # (at your option) any later version.
10
- #
11
- # Maruku is distributed in the hope that it will be useful,
12
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- # GNU General Public License for more details.
15
- #
16
- # You should have received a copy of the GNU General Public License
17
- # along with Maruku; if not, write to the Free Software
18
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
- #++
20
-
21
-
22
- require 'rexml/document'
23
-
24
- module MaRuKu; module Out; module Latex
25
-
26
- include REXML
27
-
28
- def to_latex_entity
29
- MaRuKu::Out::Latex.need_entity_table
30
-
31
- entity_name = self.entity_name
32
-
33
- entity = ENTITY_TABLE[entity_name]
34
- if not entity
35
- maruku_error "I don't know how to translate entity '#{entity_name}' "+
36
- "to LaTeX."
37
- return ""
38
- end
39
- replace = entity.latex_string
40
-
41
- entity.latex_packages.each do |p|
42
- @doc.latex_require_package p
43
- end
44
-
45
- # if replace =~ /^\\/
46
- # replace = replace + " "
47
- # end
48
-
49
- if replace
50
- return replace + "{}"
51
- else
52
- tell_user "Cannot translate entity #{entity_name.inspect} to LaTeX."
53
- return entity_name
54
- end
55
- end
56
-
57
- class LatexEntity
58
- safe_attr_accessor :html_num, Fixnum
59
- safe_attr_accessor :html_entity, String
60
- safe_attr_accessor :latex_string, String
61
- safe_attr_accessor :latex_packages, Array
62
- end
63
-
64
- def Latex.need_entity_table
65
- Latex.init_entity_table if ENTITY_TABLE.empty?
66
- end
67
-
68
- # create hash @@entity_to_latex
69
- def Latex.init_entity_table
70
- # $stderr.write "Creating entity table.."
71
- # $stderr.flush
72
- doc = Document.new XML_TABLE
73
- doc.elements.each("//char") do |c|
74
- num = c.attributes['num'].to_i
75
- name = c.attributes['name']
76
- package = c.attributes['package']
77
-
78
- convert = c.attributes['convertTo']
79
- convert.gsub!(/@DOUBLEQUOT/,'"')
80
- convert.gsub!(/@QUOT/,"'")
81
- convert.gsub!(/@GT/,">")
82
- convert.gsub!(/@LT/,"<")
83
- convert.gsub!(/@AMP/,"&")
84
- convert.freeze
85
-
86
- e = LatexEntity.new
87
- e.html_num = num
88
- e.html_entity = name
89
- e.latex_string = convert
90
- e.latex_packages = package ? package.split : []
91
-
92
- ENTITY_TABLE[num] = e
93
- ENTITY_TABLE[name] = e
94
- end
95
- # $stderr.puts "..done."
96
- end
97
-
98
- ENTITY_TABLE = {}
99
-
100
- # The following is a conversion chart for html elements, courtesy of
101
- # text2html
102
-
103
- XML_TABLE ="
104
- <chars>
105
- <char num='913' name='Alpha' convertTo='$A$' />
106
- <char num='914' name='Beta' convertTo='$B$' />
107
- <char num='915' name='Gamma' convertTo='$\\Gamma$' />
108
- <char num='916' name='Delta' convertTo='$\\Delta$' />
109
- <char num='917' name='Epsilon' convertTo='$E$' />
110
- <char num='918' name='Zeta' convertTo='$Z$' />
111
- <char num='919' name='Eta' convertTo='$H$' />
112
- <char num='920' name='Theta' convertTo='$\\Theta$' />
113
- <char num='921' name='Iota' convertTo='$I$' />
114
- <char num='922' name='Kappa' convertTo='$K$' />
115
- <char num='923' name='Lambda' convertTo='$\\Lambda$' />
116
- <char num='924' name='Mu' convertTo='$M$' />
117
- <char num='925' name='Nu' convertTo='$N$' />
118
- <char num='926' name='Xi' convertTo='$\\Xi$' />
119
- <char num='927' name='Omicron' convertTo='$O$' />
120
- <char num='928' name='Pi' convertTo='$\\Pi$' />
121
- <char num='929' name='Rho' convertTo='$P$' />
122
- <char num='931' name='Sigma' convertTo='$\\Sigma$' />
123
- <char num='932' name='Tau' convertTo='$T$' />
124
- <char num='933' name='Upsilon' convertTo='$Y$' />
125
- <char num='934' name='Phi' convertTo='$\\Phi$' />
126
- <char num='935' name='Chi' convertTo='$X$' />
127
- <char num='936' name='Psi' convertTo='$\\Psi$' />
128
- <char num='937' name='Omega' convertTo='$\\Omega$' />
129
- <char num='945' name='alpha' convertTo='$\\alpha$' />
130
- <char num='946' name='beta' convertTo='$\\beta$' />
131
- <char num='947' name='gamma' convertTo='$\\gamma$' />
132
- <char num='948' name='delta' convertTo='$\\delta$' />
133
- <char num='949' name='epsilon' convertTo='$\\epsilon$' />
134
- <char num='950' name='zeta' convertTo='$\\zeta$' />
135
- <char num='951' name='eta' convertTo='$\\eta$' />
136
- <char num='952' name='theta' convertTo='$\\theta$' />
137
- <char num='953' name='iota' convertTo='$\\iota$' />
138
- <char num='954' name='kappa' convertTo='$\\kappa$' />
139
- <char num='955' name='lambda' convertTo='$\\lambda$' />
140
- <char num='956' name='mu' convertTo='$\\mu$' />
141
-
142
- <char num='957' name='nu' convertTo='$\\nu$' />
143
- <char num='958' name='xi' convertTo='$\\xi$' />
144
- <char num='959' name='omicron' convertTo='$o$' />
145
- <char num='960' name='pi' convertTo='$\\pi$' />
146
- <char num='961' name='rho' convertTo='$\\rho$' />
147
- <char num='963' name='sigma' convertTo='$\\sigma$' />
148
- <char num='964' name='tau' convertTo='$\\tau$' />
149
- <char num='965' name='upsilon' convertTo='$\\upsilon$' />
150
- <char num='966' name='phi' convertTo='$\\phi$' />
151
-
152
- <char num='967' name='chi' convertTo='$\\chi$' />
153
- <char num='968' name='psi' convertTo='$\\psi$' />
154
- <char num='969' name='omega' convertTo='$\\omega$' />
155
- <char num='962' name='sigmaf' convertTo='$\\varsigma$' />
156
- <char num='977' name='thetasym' convertTo='$\\vartheta$' />
157
- <char num='982' name='piv' convertTo='$\\varpi$' />
158
- <char num='8230' name='hellip' convertTo='\\ldots' />
159
- <char num='8242' name='prime' convertTo='$\\prime$' />
160
- <char num='8254' name='oline' convertTo='-' />
161
-
162
- <char num='8260' name='frasl' convertTo='/' />
163
- <char num='8472' name='weierp' convertTo='$\\wp$' />
164
- <char num='8465' name='image' convertTo='$\\Im$' />
165
- <char num='8476' name='real' convertTo='$\\Re$' />
166
- <char num='8501' name='alefsym' convertTo='$\\aleph$' />
167
- <char num='8226' name='bull' convertTo='$\\bullet$' />
168
- <char num='8482' name='trade' convertTo='$^{\\rm TM}$' /> <!-- \texttrademark -->
169
- <char num='8592' name='larr' convertTo='$\\leftarrow$' />
170
-
171
- <char num='8594' name='rarr' convertTo='$\\rightarrow$' />
172
- <char num='8593' name='uarr' convertTo='$\\uparrow$' />
173
- <char num='8595' name='darr' convertTo='$\\downarrow$' />
174
- <char num='8596' name='harr' convertTo='$\\leftrightarrow$' />
175
- <char num='8629' name='crarr' convertTo='$\\hookleftarrow$' />
176
- <char num='8657' name='uArr' convertTo='$\\Uparrow$' />
177
- <char num='8659' name='dArr' convertTo='$\\Downarrow$' />
178
- <char num='8656' name='lArr' convertTo='$\\Leftarrow$' />
179
- <char num='8658' name='rArr' convertTo='$\\Rightarrow$' />
180
-
181
- <char num='8660' name='hArr' convertTo='$\\Leftrightarrow$' />
182
- <char num='8704' name='forall' convertTo='$\\forall$' />
183
- <char num='8706' name='part' convertTo='$\\partial$' />
184
- <char num='8707' name='exist' convertTo='$\\exists$' />
185
- <char num='8709' name='empty' convertTo='$\\emptyset$' />
186
- <char num='8711' name='nabla' convertTo='$\\nabla$' />
187
- <char num='8712' name='isin' convertTo='$\\in$' />
188
- <char num='8715' name='ni' convertTo='$\\ni$' />
189
- <char num='8713' name='notin' convertTo='$\\notin$' />
190
-
191
- <char num='8721' name='sum' convertTo='$\\sum$' />
192
- <char num='8719' name='prod' convertTo='$\\prod$' />
193
- <char num='8722' name='minus' convertTo='$-$' />
194
- <char num='8727' name='lowast' convertTo='$\\ast$' />
195
- <char num='8730' name='radic' convertTo='$\\surd$' />
196
- <char num='8733' name='prop' convertTo='$\\propto$' />
197
- <char num='8734' name='infin' convertTo='$\\infty$' />
198
- <char num='8736' name='ang' convertTo='$\\angle$' />
199
- <char num='8743' name='and' convertTo='$\\wedge$' />
200
-
201
- <char num='8744' name='or' convertTo='$\\vee$' />
202
- <char num='8745' name='cup' convertTo='$\\cup$' />
203
- <char num='8746' name='cap' convertTo='$\\cap$' />
204
- <char num='8747' name='int' convertTo='$\\int$' />
205
- <char num='8756' name='there4' convertTo='$\\therefore$' package='amssymb' /> <!-- only AMS -->
206
- <char num='8764' name='sim' convertTo='$\\sim$' />
207
- <char num='8776' name='asymp' convertTo='$\\approx$' />
208
- <char num='8773' name='cong' convertTo='$\\cong$' />
209
-
210
- <char num='8800' name='ne' convertTo='$\\neq$' />
211
- <char num='8801' name='equiv' convertTo='$\\equiv$' />
212
- <char num='8804' name='le' convertTo='$\\leq$' />
213
- <char num='8805' name='ge' convertTo='$\\geq$' />
214
- <char num='8834' name='sub' convertTo='$\\subset$' />
215
- <char num='8835' name='sup' convertTo='$\\supset$' />
216
- <!-- <char num='8838' name='sube' convertTo='$\\subseteq$' />-->
217
- <char num='8839' name='supe' convertTo='$\\supseteq$' />
218
- <!-- <char num='8836' name='nsub' convertTo='$\\nsubset$' /> --><!-- only AMS -->
219
-
220
- <char num='8853' name='oplus' convertTo='$\\oplus$' />
221
- <char num='8855' name='otimes' convertTo='$\\otimes$' />
222
- <char num='8869' name='perp' convertTo='$\\perp$' />
223
- <char num='8901' name='sdot' convertTo='$\\cdot$' />
224
- <char num='8968' name='rceil' convertTo='$\\rceil$' />
225
- <char num='8969' name='lceil' convertTo='$\\lceil$' />
226
- <char num='8970' name='lfloor' convertTo='$\\lfloor$' />
227
- <char num='8971' name='rfloor' convertTo='$\\rfloor$' />
228
- <char num='9001' name='rang' convertTo='$\\rangle$' />
229
-
230
- <char num='9002' name='lang' convertTo='$\\langle$' />
231
- <char num='9674' name='loz' convertTo='$\\lozenge$' package='amssymb' /> <!-- only AMS -->
232
- <char num='9824' name='spades' convertTo='$\\spadesuit$' />
233
- <char num='9827' name='clubs' convertTo='$\\clubsuit$' />
234
- <char num='9829' name='hearts' convertTo='$\\heartsuit$' />
235
- <char num='9830' name='diams' convertTo='$\\diamondsuit$' />
236
- <char num='38' name='amp' convertTo='\\@AMP' />
237
- <!-- <char num='34' name='quot' convertTo='\\@DOUBLEQUOT' /> XXX -->
238
- <char num='34' name='quot' convertTo='\"' />
239
- <char num='39' name='apos' convertTo=\"'\" />
240
- <char num='169' name='copy' convertTo='\\copyright' />
241
-
242
- <char num='60' name='lt' convertTo='$@LT$' />
243
- <char num='62' name='gt' convertTo='$@GT$' />
244
- <char num='338' name='OElig' convertTo='\\OE' />
245
- <char num='339' name='oelig' convertTo='\\oe' />
246
- <char num='352' name='Scaron' convertTo='\\v{S}' />
247
- <char num='353' name='scaron' convertTo='\\v{s}' />
248
- <char num='376' name='Yuml' convertTo='\\\"Y' />
249
- <char num='710' name='circ' convertTo='\\textasciicircum' />
250
- <char num='732' name='tilde' convertTo='\\textasciitilde' />
251
-
252
- <char num='8211' name='ndash' convertTo='--' />
253
- <char num='8212' name='mdash' convertTo='---' />
254
- <char num='8216' name='lsquo' convertTo='`' />
255
- <char num='8217' name='rsquo' convertTo=\"'\" /> <!-- XXXX -->
256
- <char num='8220' name='ldquo' convertTo='``' />
257
- <char num='8221' name='rdquo' convertTo=\"''\" /> <!-- XXXX -->
258
- <char num='8224' name='dagger' convertTo='\\dag' />
259
- <char num='8225' name='Dagger' convertTo='\\ddag' />
260
- <char num='8240' name='permil' convertTo='\\permil' package='wasysym' /> <!-- wasysym package -->
261
-
262
- <char num='8364' name='euro' convertTo='\\euro' package='eurosym' /> <!-- eurosym package -->
263
- <char num='8249' name='lsaquo' convertTo='\\guilsinglleft' package='aeguill'/>
264
- <char num='8250' name='rsaquo' convertTo='\\guilsinglright' package='aeguill' />
265
- <!-- <char num='160' name='nbsp' convertTo='\\nolinebreak' />-->
266
- <char num='160' name='nbsp' convertTo='~' />
267
- <char num='161' name='iexcl' convertTo='\\textexclamdown' />
268
- <char num='163' name='pound' convertTo='\\pounds' />
269
- <char num='164' name='curren' convertTo='\\currency' package='wasysym' /> <!-- wasysym package -->
270
- <char num='165' name='yen' convertTo='\\textyen' package='textcomp'/> <!-- textcomp -->
271
-
272
- <char num='166' name='brvbar' convertTo='\\brokenvert' /> <!-- wasysym -->
273
- <char num='167' name='sect' convertTo='\\S' />
274
- <char num='171' name='laquo' convertTo='\\guillemotleft' package='aeguill'/>
275
- <char num='187' name='raquo' convertTo='\\guillemotright' package='aeguill'/>
276
- <char num='174' name='reg' convertTo='\\textregistered' />
277
- <char num='170' name='ordf' convertTo='\\textordfeminine' />
278
- <char num='172' name='not' convertTo='$\\neg$' />
279
- <!-- <char num='176' name='deg' convertTo='$\\degree$' /> --><!-- mathabx -->
280
- <char num='176' name='deg' convertTo='\\textdegree' package='textcomp'/>
281
-
282
- <char num='177' name='plusmn' convertTo='$\\pm$' />
283
- <char num='180' name='acute' convertTo='@QUOT' />
284
- <char num='181' name='micro' convertTo='$\\mu$' />
285
- <char num='182' name='para' convertTo='\\P' />
286
- <char num='183' name='middot' convertTo='$\\cdot$' />
287
- <char num='186' name='ordm' convertTo='\\textordmasculine' />
288
- <char num='162' name='cent' convertTo='\\cent' package='wasysym' />
289
- <char num='185' name='sup1' convertTo='$^1$' />
290
-
291
- <char num='178' name='sup2' convertTo='$^2$' />
292
- <char num='179' name='sup3' convertTo='$^3$' />
293
- <char num='189' name='frac12' convertTo='$\\frac{1}{2}$' />
294
- <char num='188' name='frac14' convertTo='$\\frac{1}{4}$' />
295
- <char num='190' name='frac34' convertTo='$\\frac{3}{4}$' />
296
- <char num='192' name='Agrave' convertTo='\\`A' />
297
- <char num='193' name='Aacute' convertTo='\\@QUOTA' />
298
- <char num='194' name='Acirc' convertTo='\\^A' />
299
- <char num='195' name='Atilde' convertTo='\\~A' />
300
-
301
- <char num='196' name='Auml' convertTo='\\@DOUBLEQUOTA' />
302
- <char num='197' name='Aring' convertTo='\\AA' />
303
- <char num='198' name='AElig' convertTo='\\AE' />
304
- <char num='199' name='Ccedil' convertTo='\\c{C}' />
305
- <char num='200' name='Egrave' convertTo='\\`E' />
306
- <char num='201' name='Eacute' convertTo='\\@QUOTE' />
307
- <char num='202' name='Ecirc' convertTo='\\^E' />
308
- <char num='203' name='Euml' convertTo='\\@DOUBLEQUOTE' />
309
- <char num='204' name='Igrave' convertTo='\\`I' />
310
- <char num='205' name='Iacute' convertTo='\\@QUOTI' />
311
- <char num='206' name='Icirc' convertTo='\\^I' />
312
- <char num='207' name='Iuml' convertTo='\\\"I' />
313
- <char num='208' name='ETH' convertTo='$\\eth$' /> <!-- AMS -->
314
- <char num='209' name='Ntilde' convertTo='\\~N' />
315
- <char num='210' name='Ograve' convertTo='\\`O' />
316
- <char num='211' name='Oacute' convertTo='\\@QUOT O' />
317
- <char num='212' name='Ocirc' convertTo='\\^O' />
318
- <char num='213' name='Otilde' convertTo='\\~O' />
319
- <char num='214' name='Ouml' convertTo='\\@DOUBLEQUOTO' />
320
- <char num='215' name='times' convertTo='$\\times$' />
321
- <char num='216' name='Oslash' convertTo='\\O' />
322
- <char num='217' name='Ugrave' convertTo='\\`U' />
323
- <char num='218' name='Uacute' convertTo='\\@QUOTU' />
324
- <char num='219' name='Ucirc' convertTo='\\^U' />
325
- <char num='220' name='Uuml' convertTo='\\@DOUBLEQUOTU' />
326
- <char num='221' name='Yacute' convertTo='\\@QUOTY' />
327
- <char num='223' name='szlig' convertTo='\\ss' />
328
- <char num='224' name='agrave' convertTo='\\`a' />
329
- <char num='225' name='aacute' convertTo='\\@QUOTa' />
330
- <char num='226' name='acirc' convertTo='\\^a' />
331
- <char num='227' name='atilde' convertTo='\\~a' />
332
- <char num='228' name='auml' convertTo='\\@DOUBLEQUOTa' />
333
- <char num='229' name='aring' convertTo='\\aa' />
334
- <char num='230' name='aelig' convertTo='\\ae' />
335
- <char num='231' name='ccedil' convertTo='\\c{c}' />
336
- <char num='232' name='egrave' convertTo='\\`e' />
337
- <char num='233' name='eacute' convertTo='\\@QUOTe' />
338
- <char num='234' name='ecirc' convertTo='\\^e' />
339
- <char num='235' name='euml' convertTo='\\@DOUBLEQUOTe' />
340
- <char num='236' name='igrave' convertTo='\\`i' />
341
- <char num='237' name='iacute' convertTo='\\@QUOTi' />
342
- <char num='238' name='icirc' convertTo='\\^i' />
343
- <char num='239' name='iuml' convertTo='\\@DOUBLEQUOTi' />
344
- <char num='240' name='eth' convertTo='$\\eth$' package='amssymb'/> <!-- -->
345
- <char num='241' name='ntilde' convertTo='\\~n' />
346
- <char num='242' name='ograve' convertTo='\\`o' />
347
- <char num='243' name='oacute' convertTo='\\@QUOTo' />
348
- <char num='244' name='ocirc' convertTo='\\^o' />
349
- <char num='245' name='otilde' convertTo='\\~o' />
350
- <char num='246' name='ouml' convertTo='\\@DOUBLEQUOTo' />
351
- <!-- <char num='247' name='divide' convertTo='$\\divide$' /> -->
352
- <char num='248' name='oslash' convertTo='\\o' />
353
- <char num='249' name='ugrave' convertTo='\\`u' />
354
- <char num='250' name='uacute' convertTo='\\@QUOTu' />
355
- <char num='251' name='ucirc' convertTo='\\^u' />
356
- <char num='252' name='uuml' convertTo='\\@DOUBLEQUOTu' />
357
- <char num='253' name='yacute' convertTo='\\@QUOTy' />
358
-
359
- <char num='255' name='yuml' convertTo='\\@DOUBLEQUOTy' />
360
-
361
- <char num='222' name='THORN' convertTo='\\Thorn' package='wasysym' />
362
- <char num='254' name='thorn' convertTo='\\thorn' package='wasysym' />
363
- </chars>"
364
-
365
-
366
- end end end
367
-