maruku 0.4.2.1 → 0.5.0

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 (85) hide show
  1. data/bin/maruku +66 -20
  2. data/bin/marutest +12 -2
  3. data/docs/changelog.html +188 -23
  4. data/docs/changelog.md +128 -5
  5. data/docs/entity_test.html +245 -240
  6. data/docs/entity_test.md +2 -0
  7. data/docs/exd.html +181 -23
  8. data/docs/index.html +130 -349
  9. data/docs/markdown_syntax.html +55 -51
  10. data/docs/maruku.html +130 -349
  11. data/docs/maruku.md +154 -339
  12. data/docs/math.md +143 -0
  13. data/docs/proposal.html +16 -12
  14. data/lib/maruku.rb +6 -3
  15. data/lib/maruku/attributes.rb +7 -2
  16. data/lib/maruku/defaults.rb +27 -27
  17. data/lib/maruku/errors_management.rb +10 -9
  18. data/lib/maruku/ext/diagrams/diagrams.rb +8 -0
  19. data/lib/maruku/ext/diagrams/grid.rb +78 -0
  20. data/lib/maruku/ext/diagrams/inspect.rb +11 -0
  21. data/lib/maruku/ext/diagrams/layout.rb +105 -0
  22. data/lib/maruku/ext/diagrams/parser.rb +219 -0
  23. data/lib/maruku/ext/diagrams/structures.rb +168 -0
  24. data/lib/maruku/ext/diagrams/to_html.rb +37 -0
  25. data/lib/maruku/ext/diagrams/to_latex.rb +308 -0
  26. data/lib/maruku/ext/diagrams/unittest.rb +123 -0
  27. data/lib/maruku/ext/math.rb +11 -0
  28. data/lib/maruku/ext/math/elements.rb +26 -0
  29. data/lib/maruku/ext/math/mathml_engines/blahtex.rb +108 -0
  30. data/lib/maruku/ext/math/mathml_engines/itex2mml.rb +29 -0
  31. data/lib/maruku/ext/math/mathml_engines/none.rb +20 -0
  32. data/lib/maruku/ext/math/mathml_engines/ritex.rb +24 -0
  33. data/lib/maruku/ext/math/parsing.rb +82 -0
  34. data/lib/maruku/ext/math/to_html.rb +178 -0
  35. data/lib/maruku/ext/math/to_latex.rb +21 -0
  36. data/lib/maruku/helpers.rb +11 -0
  37. data/lib/maruku/input/charsource.rb +1 -1
  38. data/lib/maruku/input/extensions.rb +68 -0
  39. data/lib/maruku/input/html_helper.rb +91 -60
  40. data/lib/maruku/input/parse_block.rb +10 -9
  41. data/lib/maruku/input/parse_doc.rb +21 -13
  42. data/lib/maruku/input/parse_span_better.rb +19 -8
  43. data/lib/maruku/input/type_detection.rb +5 -3
  44. data/lib/maruku/output/to_html.rb +236 -67
  45. data/lib/maruku/output/to_latex.rb +69 -26
  46. data/lib/maruku/output/to_latex_entities.rb +14 -2
  47. data/lib/maruku/output/to_s.rb +8 -0
  48. data/lib/maruku/structures.rb +1 -1
  49. data/lib/maruku/tests/benchmark.rb +2 -2
  50. data/lib/maruku/tests/new_parser.rb +13 -5
  51. data/lib/maruku/version.rb +1 -1
  52. data/lib/sort_prof.rb +22 -0
  53. data/tests/diagrams/diagrams.md +54 -0
  54. data/tests/math/syntax.md +46 -0
  55. data/tests/math_usage/document.md +13 -0
  56. data/tests/unittest/attributes/attributes.md +50 -6
  57. data/tests/unittest/easy.md +1 -1
  58. data/tests/unittest/email.md +3 -3
  59. data/tests/unittest/entities.md +12 -7
  60. data/tests/unittest/escaping.md +4 -4
  61. data/tests/unittest/extra_table1.md +3 -1
  62. data/tests/unittest/footnotes.md +5 -5
  63. data/tests/unittest/headers.md +3 -3
  64. data/tests/unittest/images.md +7 -7
  65. data/tests/unittest/inline_html.md +51 -5
  66. data/tests/unittest/links.md +7 -7
  67. data/tests/unittest/list2.md +1 -1
  68. data/tests/unittest/lists.md +1 -1
  69. data/tests/unittest/lists_after_paragraph.md +1 -1
  70. data/tests/unittest/lists_ol.md +1 -1
  71. data/tests/unittest/math/equations.md +82 -0
  72. data/tests/unittest/math/inline.md +80 -0
  73. data/tests/unittest/math/table.md +51 -0
  74. data/tests/unittest/math/table2.md +67 -0
  75. data/tests/unittest/misc_sw.md +24 -24
  76. data/tests/unittest/notyet/ticks.md +1 -1
  77. data/tests/unittest/references/long_example.md +2 -2
  78. data/tests/unittest/smartypants.md +4 -4
  79. data/tests/unittest/xml.md +68 -0
  80. data/tests/unittest/xml2.md +36 -0
  81. data/tests/unittest/xml3.md +52 -0
  82. data/tests/unittest/xml_instruction.md +5 -5
  83. metadata +33 -4
  84. data/docs/a.html +0 -6
  85. data/docs/char.html +0 -1924
@@ -42,12 +42,22 @@ class MDDocument
42
42
  children_to_latex
43
43
  end
44
44
 
45
-
45
+ =begin maruku_doc
46
+ Attribute: maruku_signature
47
+ Scope: document
48
+ Output: html, latex
49
+ Summary: Enables Maruku's signature.
50
+ Default: true
51
+
52
+ If false, Maruku does not append a signature to the
53
+ generated file.
54
+ =end
55
+
46
56
  # Render as a complete LaTeX document
47
57
  def to_latex_document
48
58
  body = to_latex
49
59
 
50
- if get_boolean_setting(:maruku_signature)
60
+ if get_setting(:maruku_signature)
51
61
  body += render_latex_signature
52
62
  end
53
63
 
@@ -68,14 +78,17 @@ You have to have these fonts installed -- and this can be a pain.
68
78
 
69
79
  If `latex_cjk` is specified, this is added to the preamble:
70
80
 
81
+ <?mrk puts "ciao" ?>
82
+
71
83
  <?mrk md_codeblock(Maruku::MDDocument::Latex_preamble_enc_cjk) ?>
72
84
 
85
+
73
86
  while the default is to add this:
74
87
 
75
88
  <?mrk md_codeblock(Maruku::MDDocument::Latex_preamble_enc_utf8) ?>
76
89
 
77
90
  =end
78
- encoding = @doc.attributes[:latex_cjk] ?
91
+ encoding = get_setting(:latex_cjk) ?
79
92
  Latex_preamble_enc_cjk : Latex_preamble_enc_utf8
80
93
 
81
94
  =begin maruku_doc
@@ -138,7 +151,6 @@ Created by \\href{http://maruku.rubyforge.org}{Maruku} #{self.nice_date}.
138
151
  end end
139
152
 
140
153
  module MaRuKu; module Out; module Latex
141
- include Maruku::Defaults
142
154
 
143
155
  def to_latex_hrule; "\n\\vspace{.5em} \\hrule \\vspace{.5em}\n" end
144
156
  def to_latex_linebreak; "\\linebreak " end
@@ -147,9 +159,7 @@ module MaRuKu; module Out; module Latex
147
159
  children_to_latex+"\n\n"
148
160
  end
149
161
 
150
- def get_setting(name, default=nil)
151
- self.attributes[name] || @doc.attributes[name] || default
152
- end
162
+
153
163
  =begin maruku_doc
154
164
  Title: Input format for colors
155
165
  Output: latex, html
@@ -180,8 +190,31 @@ Admissible formats:
180
190
  end
181
191
  end
182
192
 
183
- def to_latex_code;
184
- raw_code = self.raw_code
193
+ =begin maruku_doc
194
+ Attribute: code_show_spaces
195
+ Scope: global, document, element
196
+
197
+ If `true`, shows spaces and tabs in code blocks.
198
+
199
+ Example:
200
+
201
+ One space
202
+ Two spaces
203
+ Tab, space, tab
204
+ Tab, tab, tab and all is green!
205
+ {:code_show_spaces code_background_color=#ffeedd}
206
+ {:markdown}
207
+
208
+ That will produce:
209
+
210
+ One space
211
+ Two spaces
212
+ Tab, space, tab
213
+ Tab, tab, tab and all is green!
214
+ {:code_show_spaces code_background_color=#ffeedd}
215
+
216
+ =end
217
+
185
218
  =begin maruku_doc
186
219
  Attribute: latex_use_listings
187
220
  Scope: document
@@ -202,33 +235,35 @@ Otherwise, a standard `verbatim` environment is used.
202
235
 
203
236
  Please refer to the documentation of the `listings` package for
204
237
  supported languages.
205
-
238
+
206
239
  If a language is not supported, the `listings` package will emit
207
240
  a warning during the compilation. Just press enter and nothing
208
241
  wrong will happen.
209
242
 
210
243
  * If the `code_show_spaces` is specified, than spaces and tabs will
211
244
  be shown using the macro:
212
-
245
+
213
246
  \lstset{showspaces=true,showtabs=true}
214
-
247
+
215
248
  * The background color is given by `code_background_color`.
216
249
 
217
250
  =end
251
+
252
+ def to_latex_code;
253
+ raw_code = self.raw_code
218
254
 
219
- if @doc.attributes[:latex_use_listings]
255
+ if get_setting(:latex_use_listings)
220
256
  @doc.latex_require_package('listings')
221
257
 
222
258
  s = "\\lstset{columns=fixed,frame=shadowbox}"
223
259
 
224
- show_spaces = get_setting(:code_show_spaces)
225
- if show_spaces
260
+ if get_setting(:code_show_spaces)
226
261
  s+= "\\lstset{showspaces=true,showtabs=true}\n"
227
262
  else
228
263
  s+= "\\lstset{showspaces=false,showtabs=false}\n"
229
264
  end
230
265
 
231
- color = latex_color get_setting(:code_background_color,DEFAULT_CODE_COLOR)
266
+ color = latex_color get_setting(:code_background_color)
232
267
 
233
268
  s+= "\\lstset{backgroundcolor=#{color}}\n"
234
269
 
@@ -287,8 +322,12 @@ Otherwise, a standard `verbatim` environment is used.
287
322
  "\\item #{children_to_latex}\n"
288
323
  end
289
324
 
290
- def to_latex_strong; wrap_as_span('\bf') end
291
- def to_latex_emphasis; wrap_as_span('\em') end
325
+ def to_latex_strong
326
+ "\\textbf{#{children_to_latex}}"
327
+ end
328
+ def to_latex_emphasis
329
+ "\\emph{#{children_to_latex}}"
330
+ end
292
331
 
293
332
  def wrap_as_span(c)
294
333
  "{#{c} #{children_to_latex}}"
@@ -300,11 +339,21 @@ Otherwise, a standard `verbatim` environment is used.
300
339
  \\end{#{name}}\n"
301
340
  end
302
341
 
342
+ SAFE_CHARS = Set.new((?a..?z).to_a + (?A..?Z).to_a)
303
343
  # the ultimate escaping
304
344
  # (is much better than using \verb)
305
345
  def latex_escape(source)
306
346
  s="";
307
- source.each_byte do |b| s+= "\\char%d" % b end
347
+
348
+ source.each_byte do |b|
349
+ if b == ?\
350
+ s << '~'
351
+ elsif SAFE_CHARS.include? b
352
+ s << b
353
+ else
354
+ s += "\\char%d" % b
355
+ end
356
+ end
308
357
  s
309
358
  end
310
359
 
@@ -314,14 +363,13 @@ Otherwise, a standard `verbatim` environment is used.
314
363
  # Convert to printable latex chars
315
364
  s = latex_escape(source)
316
365
 
317
- color = get_setting(:code_background_color,DEFAULT_CODE_COLOR)
366
+ color = get_setting(:code_background_color)
318
367
  colorspec = latex_color(color, 'colorbox')
319
368
 
320
369
  "#{colorspec}{\\tt #{s}}"
321
370
  end
322
371
 
323
372
  def to_latex_immediate_link
324
- a = create_html_element 'a'
325
373
  url = self.url
326
374
  text = url.gsub(/^mailto:/,'') # don't show mailto
327
375
  # gsub('~','$\sim$')
@@ -348,11 +396,6 @@ Otherwise, a standard `verbatim` environment is used.
348
396
 
349
397
  def to_latex_link
350
398
  id = self.ref_id
351
- # if empty, use text
352
- if id.size == 0
353
- id = children.to_s.downcase
354
- end
355
-
356
399
  ref = @doc.refs[id]
357
400
  if not ref
358
401
  $stderr.puts "Could not find id = '#{id}'"
@@ -25,11 +25,17 @@ module MaRuKu; module Out; module Latex
25
25
 
26
26
  include REXML
27
27
 
28
-
29
28
  def to_latex_entity
29
+ MaRuKu::Out::Latex.need_entity_table
30
+
30
31
  entity_name = self.entity_name
31
32
 
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
33
39
  replace = entity.latex_string
34
40
 
35
41
  entity.latex_packages.each do |p|
@@ -55,8 +61,14 @@ module MaRuKu; module Out; module Latex
55
61
  safe_attr_accessor :latex_packages, Array
56
62
  end
57
63
 
64
+ def Latex.need_entity_table
65
+ Latex.init_entity_table if ENTITY_TABLE.empty?
66
+ end
67
+
58
68
  # create hash @@entity_to_latex
59
69
  def Latex.init_entity_table
70
+ $stderr.write "Creating entity table.."
71
+ $stderr.flush
60
72
  doc = Document.new XML_TABLE
61
73
  doc.elements.each("//char") do |c|
62
74
  num = c.attributes['num'].to_i
@@ -80,6 +92,7 @@ module MaRuKu; module Out; module Latex
80
92
  ENTITY_TABLE[num] = e
81
93
  ENTITY_TABLE[name] = e
82
94
  end
95
+ $stderr.puts "..done."
83
96
  end
84
97
 
85
98
  ENTITY_TABLE = {}
@@ -349,7 +362,6 @@ module MaRuKu; module Out; module Latex
349
362
  <char num='254' name='thorn' convertTo='\\thorn' package='wasysym' />
350
363
  </chars>"
351
364
 
352
- init_entity_table
353
365
 
354
366
  end end end
355
367
 
@@ -38,6 +38,14 @@ class MDElement
38
38
  title.gsub!(/ /,'_')
39
39
  title.downcase!
40
40
  title.gsub!(/[^\w_]/,'')
41
+ title.strip!
42
+
43
+ if title.size == 0
44
+ $uid ||= 0
45
+ $uid += 1
46
+ title = "id#{$uid}"
47
+ end
48
+
41
49
  title
42
50
  end
43
51
  end
@@ -43,7 +43,7 @@ EOF
43
43
  attr_accessor symbol
44
44
  end
45
45
 
46
- alias safe_attr_accessor safe_attr_accessor1
46
+ alias safe_attr_accessor safe_attr_accessor2
47
47
  end
48
48
 
49
49
  module MaRuKu
@@ -20,7 +20,7 @@
20
20
 
21
21
 
22
22
  require 'maruku'
23
- require 'bluecloth'
23
+ #require 'bluecloth'
24
24
 
25
25
 
26
26
  data = $stdin.read
@@ -35,7 +35,7 @@ methods =
35
35
  [
36
36
 
37
37
  [Maruku, :to_html],
38
- [BlueCloth, :to_html],
38
+ # [BlueCloth, :to_html],
39
39
  [Maruku, :to_latex]
40
40
 
41
41
  ]
@@ -20,6 +20,7 @@
20
20
 
21
21
 
22
22
  require 'maruku'
23
+ require 'maruku/ext/math'
23
24
 
24
25
  module MaRuKu; module Tests
25
26
  # 5 accented letters in italian, encoded as UTF-8
@@ -149,10 +150,12 @@ module MaRuKu; module Tests
149
150
  # links of the form [text][ref]
150
151
  ["\\[a]", ["[a]"], 'Escaping 1'],
151
152
  ["\\[a\\]", ["[a]"], 'Escaping 2'],
152
- ["[a]", ["a"], 'Not a link'],
153
- ["[a][]", [ md_link(["a"],'')], 'Empty link'],
154
- ["[a][]b", [ md_link(["a"],''),'b'], 'Empty link'],
155
- ["[a\\]][]", [ md_link(["a]"],'')], 'Escape inside link'],
153
+ # This is valid in the new Markdown version
154
+ # ["[a]", ["a"], 'Not a link'],
155
+ ["[a]", [ md_link(["a"],'a')], 'Empty link'],
156
+ ["[a][]", ],
157
+ ["[a][]b", [ md_link(["a"],'a'),'b'], 'Empty link'],
158
+ ["[a\\]][]", [ md_link(["a]"],'a]')], 'Escape inside link'],
156
159
 
157
160
  ["[a", :throw, 'Link not closed'],
158
161
  ["[a][", :throw, 'Ref not closed'],
@@ -256,7 +259,12 @@ module MaRuKu; module Tests
256
259
  ['[bar](/url/ "Title with "quotes" inside")',
257
260
  [md_im_link(["bar"],'/url/', 'Title with "quotes" inside')],
258
261
  "Link with quotes"],
259
-
262
+
263
+ # We dropped this idea
264
+ # ['$20,000 and $30,000', ['$20,000 and $30,000'], 'Math: spaces'],
265
+ ['$20,000$', [md_inline_math('20,000')]],
266
+ # ['$ 20,000$', ['$ 20,000$']],
267
+ # ['$20,000 $ $20,000$', ['$20,000 $ ', md_inline_math('20,000')]],
260
268
  ["#{Maruku8}", [Maruku8], "Reading UTF-8"],
261
269
  ["#{AccIta1}", [AccIta8], "Converting ISO-8859-1 to UTF-8",
262
270
  {:encoding => 'iso-8859-1'}],
@@ -19,7 +19,7 @@
19
19
  #++
20
20
 
21
21
  module MaRuKu
22
- Version = '0.4.2.1'
22
+ Version = '0.5.0'
23
23
 
24
24
  MarukuURL = 'http://maruku.rubyforge.org/'
25
25
 
@@ -0,0 +1,22 @@
1
+
2
+ field = (ARGV.shift or '2').to_i
3
+
4
+ lines = $stdin.read.split("\n")
5
+ # leave the first lines
6
+
7
+ while l = lines.shift
8
+ puts l
9
+ break if l =~ /total/
10
+ end
11
+
12
+
13
+
14
+
15
+ puts lines.sort {|a,b|
16
+ a.split[field].to_f <=> b.split[field].to_f
17
+ }.reverse.join("\n")
18
+
19
+
20
+
21
+
22
+
@@ -0,0 +1,54 @@
1
+
2
+ I would like to add a syntax for drawing basic diagrams
3
+ and convert them to PNG/PDF/SVG.
4
+
5
+
6
+ +----------+ +----------+
7
+ | Makefile | ---> | Compiler | ==> ...
8
+ +----------+ +----------+
9
+ | ^
10
+ v |
11
+ ---------
12
+ {:diagram title="My diagram"}
13
+
14
+
15
+ {:diagram: style=""}
16
+
17
+ How to do vertical bold arrows?
18
+
19
+ !
20
+ V
21
+
22
+ Curved arrows:
23
+ +-> | Yes: |
24
+ ___________________ /
25
+ | is the agent ok? | --|
26
+ --------------{:r}+
27
+
28
+ {:r: border="solid 3px red"}
29
+
30
+ Big boxes:
31
+
32
+ +-------+
33
+ |{:long}| --->
34
+ +-------+
35
+
36
+ {+long: This is a long box}
37
+
38
+ Or
39
+
40
+ +----------------+ ________
41
+ | This is a very | ---> | Box |
42
+ | long cell | |________|
43
+ +----------------+
44
+ - Yes
45
+ /
46
+ -------+
47
+ \
48
+ - No
49
+
50
+
51
+
52
+
53
+
54
+
@@ -0,0 +1,46 @@
1
+ LaTeX preamble: preamble.tex
2
+ CSS: math.css
3
+
4
+ Here are some formulas:
5
+
6
+ * $\alpha$
7
+ * $x^{n}+y^{n} \neq z^{n}$
8
+
9
+ Some inline maths: $\sum_{n=1}^\infty \frac{(-1)^n}{n} = \ln 2$.
10
+
11
+ Some display maths:
12
+
13
+ \[ \sum_{n=1}^\infty \frac{1}{n} \]
14
+ \[ \sum_{n=1}^\infty \frac{1}{n} \text{ is divergent, but } \lim_{n \to \infty} \sum_{i=1}^n \frac{1}{i} - \ln n \text{ exists.} \] (a)
15
+
16
+ Some random AMSTeX symbols - thanks to Robin Snader for adding these:
17
+
18
+ $$ \beth \Subset \bigtriangleup \smallsmile \bumpeq \ggg \pitchfork $$
19
+
20
+ Note that $\hat g$ , $J$, and $\gamma_1\gamma_2$ all restrict to
21
+
22
+ $x_1 \overline{x_2} \oplus x_2 \overline{x_1}$ and that this module
23
+ is linear in $x_1$ and $x_2$.
24
+
25
+ See label \eqref{a}.
26
+
27
+ $$ \href{#hello}{\alpha+\beta} $$
28
+
29
+ ## Cross references ##
30
+
31
+ The following are 4 equations, labeled A,B,C,D:
32
+
33
+ $$ \alpha $$ (A)
34
+
35
+ \[
36
+ \beta
37
+ \] (B)
38
+
39
+ $$ \gamma \label{C} $$
40
+
41
+ \[
42
+ \delta \label{D}
43
+ \]
44
+
45
+ You can now refer to (eq:A), (eq:B), \eqref{C}, \eqref{D}.
46
+