maruku 0.4.2.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -32,17 +32,17 @@ module MaRuKu; module In; module Markdown; module SpanLevelParser
32
32
 
33
33
  EscapedCharInInlineCode = [?\\,?`]
34
34
 
35
- def parse_lines_as_span(lines)
36
- parse_span_better lines.join("\n")
35
+ def parse_lines_as_span(lines, parent=nil)
36
+ parse_span_better lines.join("\n"), parent
37
37
  end
38
38
 
39
- def parse_span_better(string)
39
+ def parse_span_better(string, parent=nil)
40
40
  if not string.kind_of? String then
41
41
  error "Passed #{string.class}." end
42
42
 
43
43
  st = (string + "")
44
44
  st.freeze
45
- src = CharSource.new(st)
45
+ src = CharSource.new(st, parent)
46
46
  read_span(src, EscapedCharInText, [nil])
47
47
  end
48
48
 
@@ -67,7 +67,12 @@ module MaRuKu; module In; module Markdown; module SpanLevelParser
67
67
  break if exit_on_chars && exit_on_chars.include?(c)
68
68
  break if exit_on_strings && exit_on_strings.any? {|x| src.cur_chars_are x}
69
69
 
70
- case c
70
+ # check if there are extensions
71
+ if check_span_extensions(src, con)
72
+ next
73
+ end
74
+
75
+ case c = src.cur_char
71
76
  when ?\ # it's space (32)
72
77
  if src.cur_chars_are " \n"
73
78
  src.ignore_chars(3)
@@ -190,7 +195,6 @@ module MaRuKu; module In; module Markdown; module SpanLevelParser
190
195
  src.ignore_char # {
191
196
  interpret_extension(src, con, [?}])
192
197
  src.ignore_char # }
193
-
194
198
  when nil
195
199
  maruku_error ("Unclosed span (waiting for %s"+
196
200
  "#{exit_on_strings.inspect})") % [
@@ -509,6 +513,7 @@ module MaRuKu; module In; module Markdown; module SpanLevelParser
509
513
  (src.next_char == ?[ or src.next_char == ?( )
510
514
  src.shift_char
511
515
  end
516
+
512
517
  case src.cur_char
513
518
  when ?(
514
519
  src.ignore_char # opening (
@@ -552,6 +557,11 @@ module MaRuKu; module In; module Markdown; module SpanLevelParser
552
557
  when ?[ # link ref
553
558
  ref_id = read_ref_id(src,con)
554
559
  if ref_id
560
+ if ref_id.size == 0
561
+ ref_id = children.to_s.downcase.gsub(' ','_')
562
+ else
563
+ ref_id = ref_id.downcase
564
+ end
555
565
  con.push_element md_link(children, ref_id)
556
566
  else
557
567
  maruku_error "Could not read ref_id", src, con
@@ -560,8 +570,9 @@ module MaRuKu; module In; module Markdown; module SpanLevelParser
560
570
  con.push_elements children
561
571
  return
562
572
  end
563
- else # no stuff
564
- con.push_elements children
573
+ else # empty [link]
574
+ id = children.to_s.downcase.gsub(' ','_')
575
+ con.push_element md_link(children, id)
565
576
  end
566
577
  end # read link
567
578
 
@@ -44,11 +44,12 @@ module MaRuKu; module Strings
44
44
  return :definition if l =~ Definition
45
45
  # I had a bug with emails and urls at the beginning of the
46
46
  # line that were mistaken for raw_html
47
- return :text if l=~EMailAddress or l=~ URL
47
+ return :text if l=~ /^#{EMailAddress}/
48
+ return :text if l=~ /^<http:/
48
49
  # raw html is like PHP Markdown Extra: at most three spaces before
49
50
  return :xml_instr if l =~ %r{^\s*<\?}
50
51
  return :raw_html if l =~ %r{^[ ]?[ ]?[ ]?</?\s*\w+}
51
- return :raw_html if l =~ %r{[ ]{0,3}<\!\-\-}
52
+ return :raw_html if l =~ %r{^[ ]?[ ]?[ ]?<\!\-\-}
52
53
  return :ulist if l =~ /^\s?([\*\-\+])\s+.*\w+/
53
54
  return :olist if l =~ /^\s?\d+\..*\w+/
54
55
  return :header1 if l =~ /^(=)+/
@@ -64,9 +65,11 @@ module MaRuKu; module Strings
64
65
  return :ald if l =~ AttributeDefinitionList
65
66
  return :ial if l =~ InlineAttributeList
66
67
  # end
68
+ # return :equation_end if l =~ EquationEnd
67
69
  return :text # else, it's just text
68
70
  end
69
71
 
72
+
70
73
  # $1 = id $2 = attribute list
71
74
  AttributeDefinitionList = /^\s{0,3}\{([\w\d\s]+)\}:\s*(.*)\s*$/
72
75
  #
@@ -135,5 +138,4 @@ module MaRuKu; module Strings
135
138
 
136
139
 
137
140
  EMailAddress = /<([^:]+@[^:]+)>/
138
- URL = /^<http:/
139
141
  end end
@@ -21,11 +21,6 @@
21
21
 
22
22
  require 'rexml/document'
23
23
 
24
- require 'rubygems'
25
- require 'syntax'
26
- require 'syntax/convertors/html'
27
-
28
-
29
24
  class String
30
25
  # A string is rendered into HTML by creating
31
26
  # a REXML::Text node. REXML takes care of all the encoding.
@@ -43,7 +38,6 @@ end
43
38
  # This module groups all functions related to HTML export.
44
39
  module MaRuKu; module Out; module HTML
45
40
  include REXML
46
- include MaRuKu::Defaults
47
41
 
48
42
  # Render as an HTML fragment (no head, just the content of BODY). (returns a string)
49
43
  def to_html(context={})
@@ -81,12 +75,76 @@ module MaRuKu; module Out; module HTML
81
75
  # containing code.
82
76
  doc.write(xml,indent,transitive=true,ie_hack);
83
77
 
84
- xhtml10strict = "<?xml version='1.0' encoding='utf-8'?>
78
+ xhtml10strict = "
79
+ <?xml version='1.0' encoding='utf-8'?>
85
80
  <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
86
81
  'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>\n"
87
- xhtml10strict + xml
82
+
83
+ xhtml11strict_mathml2 = '<?xml version="1.0" encoding="utf-8"?>
84
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN"
85
+ "http://www.w3.org/TR/MathML2/dtd/xhtml-math11-f.dtd" [
86
+ <!ENTITY mathml "http://www.w3.org/1998/Math/MathML">
87
+ ]>
88
+ '
89
+
90
+ xhtml11_mathml2_svg11 =
91
+ '<?xml version="1.0" encoding="utf-8"?>
92
+ <!DOCTYPE html PUBLIC
93
+ "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"
94
+ "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">
95
+ '
96
+
97
+ xhtml11_mathml2_svg11 + xml
88
98
  end
89
99
 
100
+ def xml_newline() Text.new("\n") end
101
+
102
+
103
+ =begin maruku_doc
104
+ Attribute: title
105
+ Scope: document
106
+
107
+ Sets the title of the document.
108
+ If a title is not specified, the first header will be used.
109
+
110
+ These should be equivalent:
111
+
112
+ Title: my document
113
+
114
+ Content
115
+
116
+ and
117
+
118
+ my document
119
+ ===========
120
+
121
+ Content
122
+
123
+ In both cases, the title is set to "my document".
124
+ =end
125
+
126
+ =begin maruku_doc
127
+ Attribute: subject
128
+ Scope: document
129
+
130
+ Synonim for `title`.
131
+ =end
132
+
133
+
134
+ =begin maruku_doc
135
+ Attribute: css
136
+ Scope: document
137
+ Output: HTML
138
+ Summary: Activates CSS stylesheets for HTML.
139
+
140
+ `css` should be a space-separated list of urls.
141
+
142
+ Example:
143
+
144
+ CSS: style.css math.css
145
+
146
+ =end
147
+
90
148
  # Render to a complete HTML document (returns a REXML document tree)
91
149
  def to_html_document_tree
92
150
  doc = Document.new(nil,{:respect_whitespace =>:all})
@@ -94,34 +152,41 @@ module MaRuKu; module Out; module HTML
94
152
 
95
153
  root = Element.new('html', doc)
96
154
  root.add_namespace('http://www.w3.org/1999/xhtml')
97
-
155
+ root.add_namespace('svg', "http://www.w3.org/2000/svg" )
98
156
  lang = self.attributes[:lang] || 'en'
99
- root.attributes['lang'] = lang
100
157
  root.attributes['xml:lang'] = lang
101
158
 
159
+ root << xml_newline
102
160
  head = Element.new 'head', root
103
161
 
104
162
  #<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
105
163
  me = Element.new 'meta', head
106
164
  me.attributes['http-equiv'] = 'Content-type'
107
- me.attributes['content'] = 'text/html; charset=utf-8'
165
+ # me.attributes['content'] = 'text/html;charset=utf-8'
166
+ me.attributes['content'] = 'application/xhtml+xml;charset=utf-8'
108
167
 
168
+
109
169
  # Create title element
110
170
  doc_title = self.attributes[:title] || self.attributes[:subject] || ""
111
171
  title = Element.new 'title', head
112
172
  title << Text.new(doc_title)
113
173
 
114
174
 
115
- css = self.attributes[:css]
116
- if css
175
+
176
+ if css_list = self.attributes[:css]
177
+ css_list.split.each do |css|
117
178
  # <link type="text/css" rel="stylesheet" href="..." />
118
179
  link = Element.new 'link'
119
180
  link.attributes['type'] = 'text/css'
120
181
  link.attributes['rel'] = 'stylesheet'
121
182
  link.attributes['href'] = css
122
- head << link
183
+ head << link
184
+ head << xml_newline
185
+ end
123
186
  end
124
-
187
+
188
+ root << xml_newline
189
+
125
190
  body = Element.new 'body'
126
191
 
127
192
  children_to_html.each do |e|
@@ -135,7 +200,7 @@ module MaRuKu; module Out; module HTML
135
200
 
136
201
  # When we are rendering a whole document, we add a signature
137
202
  # at the bottom.
138
- if get_boolean_setting(:maruku_signature)
203
+ if get_setting(:maruku_signature)
139
204
  body << maruku_html_signature
140
205
  end
141
206
 
@@ -144,33 +209,18 @@ module MaRuKu; module Out; module HTML
144
209
  doc
145
210
  end
146
211
 
147
- def add_whitespace(element)
148
- blocks = ['p','pre','h1','h2','h3','h4','h5','h6',
149
- 'style','table','div','ul','ol','li','dl','dt',
150
- 'head','blockquote','tr','thead','td','dd','title',
151
- 'link','hr']
152
-
153
- element.get_elements( "//*" ).each do |e|
154
- if blocks.include? e.name
155
- e.parent.insert_before(e, Text.new("\n"))
156
- e.parent.insert_after(e, Text.new("\n"))
157
- end
158
- end
159
-
160
- element.get_elements( "//br" ).each do |e|
161
- e.parent.insert_after(e, Text.new("\n"))
162
- end
163
- end
164
-
165
212
  # returns "st","nd","rd" or "th" as appropriate
166
213
  def day_suffix(day)
167
- return 'th' if day == 11
168
- case day%10
169
- when 1; 'st'
170
- when 2; 'nd'
171
- when 3; 'rd'
172
- else 'th'
173
- end
214
+ s = {
215
+ 1 => 'st',
216
+ 2 => 'nd',
217
+ 3 => 'rd',
218
+ 21 => 'st',
219
+ 22 => 'nd',
220
+ 23 => 'rd',
221
+ 31 => 'st'
222
+ }
223
+ return s[day] || 'th';
174
224
  end
175
225
 
176
226
  # formats a nice date
@@ -191,7 +241,7 @@ module MaRuKu; module Out; module HTML
191
241
  span << Text.new('Created by ')
192
242
  a = Element.new('a', span)
193
243
  a.attributes['href'] = 'http://maruku.rubyforge.org'
194
- a.attributes['title'] = 'Maruku: a Markdown interpreter for Ruby'
244
+ a.attributes['title'] = 'Maruku: a Markdown-superset interpreter for Ruby'
195
245
  a << Text.new('Maruku')
196
246
  span << Text.new(nice_date+".")
197
247
  div
@@ -229,8 +279,8 @@ module MaRuKu; module Out; module HTML
229
279
  # renders children as html and wraps into an element of given name
230
280
  #
231
281
  # Sets 'id' if meta is set
232
- def wrap_as_element(name)
233
- m = create_html_element name
282
+ def wrap_as_element(name, attributes_to_copy=[])
283
+ m = create_html_element(name, attributes_to_copy)
234
284
  children_to_html.each do |e| m << e; end
235
285
 
236
286
  # m << Comment.new( "{"+self.al.to_md+"}") if not self.al.empty?
@@ -238,11 +288,40 @@ module MaRuKu; module Out; module HTML
238
288
  m
239
289
  end
240
290
 
241
- def create_html_element(name)
291
+ =begin maruku_doc
292
+ Attribute: id
293
+ Scope: element
294
+ Output: LaTeX, HTML
295
+
296
+ It is copied as a standard HTML attribute.
297
+
298
+ Moreover, it used as a label name for hyperlinks in both HTML and
299
+ in PDF.
300
+
301
+ =end
302
+
303
+ =begin maruku_doc
304
+ Attribute: class
305
+ Scope: element
306
+ Output: HTML
307
+
308
+ It is copied as a standard HTML attribute.
309
+ =end
310
+
311
+ =begin maruku_doc
312
+ Attribute: style
313
+ Scope: element
314
+ Output: HTML
315
+
316
+ It is copied as a standard HTML attribute.
317
+ =end
318
+
319
+ StandardAttributes = [:id, :style, :class]
320
+ def create_html_element(name, attributes_to_copy=[])
242
321
  m = Element.new name
243
- if (v=@attributes[:id] ) then m.attributes['id' ] = v.to_s end
244
- if (v=@attributes[:style]) then m.attributes['style'] = v.to_s end
245
- if (v=@attributes[:class]) then m.attributes['class'] = v.to_s end
322
+ (StandardAttributes+attributes_to_copy).each do |a|
323
+ if v = @attributes[a] then m.attributes[a.to_s] = v.to_s end
324
+ end
246
325
  m
247
326
  end
248
327
 
@@ -266,9 +345,20 @@ module MaRuKu; module Out; module HTML
266
345
  def to_html_strong; wrap_as_element('strong') end
267
346
  def to_html_emphasis; wrap_as_element('em') end
268
347
 
348
+ =begin maruku_doc
349
+ Attribute: use_numbered_headers
350
+ Scope: document
351
+ Summary: Activates the numbering of headers.
352
+
353
+ If `true`, section headers will be numbered.
354
+
355
+ In LaTeX export, the numbering of headers is managed
356
+ by Maruku, to have the same results in both HTML and LaTeX.
357
+ =end
358
+
269
359
  # nil if not applicable, else string
270
360
  def section_number
271
- return nil if not @doc.attributes[:use_numbered_headers]
361
+ return nil if not get_setting(:use_numbered_headers)
272
362
 
273
363
  n = @attributes[:section_number]
274
364
  if n && (not n.empty?)
@@ -307,17 +397,58 @@ module MaRuKu; module Out; module HTML
307
397
  Text.new(source, true, nil, false )
308
398
  end
309
399
 
400
+ =begin maruku_doc
401
+ Attribute: html_use_syntax
402
+ Scope: global, document, element
403
+ Output: HTML
404
+ Summary: Enables the use of the `syntax` package.
405
+ Related: lang, code_lang
406
+ Default: <?mrk md_code(Globals[:html_use_syntax].to_s) ?>
407
+
408
+ If true, the `syntax` package is used. It supports the `ruby` and `xml`
409
+ languages. Remember to set the `lang` attribute of the code block.
410
+
411
+ Examples:
412
+
413
+ require 'maruku'
414
+ {:lang=ruby html_use_syntax=true}
415
+
416
+ and
417
+
418
+ <div style="text-align:center">Div</div>
419
+ {:lang=html html_use_syntax=true}
420
+
421
+ produces:
422
+
423
+ require 'maruku'
424
+ {:lang=ruby html_use_syntax=true}
425
+
426
+ and
427
+
428
+ <div style="text-align:center">Div</div>
429
+ {:lang=html html_use_syntax=true}
430
+
431
+ =end
432
+
310
433
  def to_html_code;
311
434
  source = self.raw_code
312
435
 
313
436
  lang = self.attributes[:lang] || @doc.attributes[:code_lang]
314
437
 
315
438
  lang = 'xml' if lang=='html'
316
- use_syntax = get_setting(:html_use_syntax)
439
+
440
+
441
+ use_syntax = get_setting :html_use_syntax
317
442
 
318
443
  element =
319
444
  if use_syntax && lang
320
445
  begin
446
+ if not $syntax_loaded
447
+ require 'rubygems'
448
+ require 'syntax'
449
+ require 'syntax/convertors/html'
450
+ $syntax_loaded = true
451
+ end
321
452
  convertor = Syntax::Convertors::HTML.for_syntax lang
322
453
 
323
454
  # eliminate trailing newlines otherwise Syntax crashes
@@ -328,6 +459,10 @@ module MaRuKu; module Out; module HTML
328
459
  pre = Document.new(html, {:respect_whitespace =>:all}).root
329
460
  pre.attributes['class'] = lang
330
461
  pre
462
+ rescue LoadError => e
463
+ maruku_error "Could not load package 'syntax'.\n"+
464
+ "Please install it, for example using 'gem install syntax'."
465
+ to_html_code_using_pre(source)
331
466
  rescue Object => e
332
467
  maruku_error"Error while using the syntax library for code:\n#{source.inspect}"+
333
468
  "Lang is #{lang} object is: \n"+
@@ -341,13 +476,33 @@ module MaRuKu; module Out; module HTML
341
476
  to_html_code_using_pre(source)
342
477
  end
343
478
 
344
- color = get_setting(:code_background_color,DEFAULT_CODE_COLOR)
345
- if color != DEFAULT_CODE_COLOR
479
+ color = get_setting(:code_background_color)
480
+ if color != Globals[:code_background_color]
346
481
  element.attributes['style'] = "background-color: #{color};"
347
482
  end
348
483
  element
349
484
  end
350
485
 
486
+ =begin maruku_doc
487
+ Attribute: code_background_color
488
+ Scope: global, document, element
489
+ Summary: Background color for code blocks.
490
+
491
+ The format is either a named color (`green`, `red`) or a CSS color
492
+ of the form `#ff00ff`.
493
+
494
+ * for **HTML output**, the value is put straight in the `background-color` CSS
495
+ property of the block.
496
+
497
+ * for **LaTeX output**, if it is a named color, it must be a color accepted
498
+ by the LaTeX `color` packages. If it is of the form `#ff00ff`, Maruku
499
+ defines a color using the `\color[rgb]{r,g,b}` macro.
500
+
501
+ For example, for `#0000ff`, the macro is called as: `\color[rgb]{0,0,1}`.
502
+
503
+ =end
504
+
505
+
351
506
  def to_html_code_using_pre(source)
352
507
  pre = create_html_element 'pre'
353
508
  code = Element.new 'code', pre
@@ -358,10 +513,12 @@ module MaRuKu; module Out; module HTML
358
513
  s = s.gsub(/\&apos;/,'&#39;') # IE bug
359
514
  s = s.gsub(/'/,'&#39;') # IE bug
360
515
 
361
- show_spaces = get_setting(:code_show_spaces)
362
- if show_spaces
363
- s.gsub!(/\t/,'&raquo;'+'&nbsp;'*3)
364
- s.gsub!(/ /,'&not;')
516
+ if get_setting(:code_show_spaces)
517
+ # 187 = raquo
518
+ # 160 = nbsp
519
+ # 172 = not
520
+ s.gsub!(/\t/,'&#187;'+'&#160;'*3)
521
+ s.gsub!(/ /,'&#172;')
365
522
  end
366
523
 
367
524
  text = Text.new(s, respect_ws=true, parent=nil, raw=true )
@@ -375,8 +532,8 @@ module MaRuKu; module Out; module HTML
375
532
  source = self.raw_code
376
533
  pre << source2html(source)
377
534
 
378
- color = get_setting(:code_background_color, DEFAULT_CODE_COLOR)
379
- if color != DEFAULT_CODE_COLOR
535
+ color = get_setting(:code_background_color)
536
+ if color != Globals[:code_background_color]
380
537
  pre.attributes['style'] = "background-color: #{color};"
381
538
  end
382
539
 
@@ -395,10 +552,6 @@ module MaRuKu; module Out; module HTML
395
552
  def to_html_link
396
553
  a = wrap_as_element 'a'
397
554
  id = self.ref_id
398
- # if empty, use text
399
- if id.size == 0
400
- id = children.to_s.downcase
401
- end
402
555
 
403
556
  if ref = @doc.refs[id]
404
557
  url = ref[:url]
@@ -406,7 +559,8 @@ module MaRuKu; module Out; module HTML
406
559
  a.attributes['href'] = url if url
407
560
  a.attributes['title'] = title if title
408
561
  else
409
- maruku_error"Could not find ref_id = #{id.inspect} for #{self.inspect}"
562
+ maruku_error "Could not find ref_id = #{id.inspect} for #{self.inspect}\n"+
563
+ "Available refs are #{@doc.refs.keys.inspect}"
410
564
  tell_user "Not creating a link for ref_id = #{id.inspect}."
411
565
  return wrap_as_element('span')
412
566
  end
@@ -460,7 +614,9 @@ module MaRuKu; module Out; module HTML
460
614
  id = self.ref_id
461
615
  if ref = @doc.refs[id]
462
616
  url = ref[:url]
463
- a.attributes['src'] = url
617
+ title = ref[:title]
618
+ a.attributes['src'] = url.to_s
619
+ a.attributes['alt'] = title.to_s
464
620
  [:title, :class, :style].each do |s|
465
621
  a.attributes[s.to_s] = ref[s] if ref[s]
466
622
  end
@@ -483,7 +639,7 @@ module MaRuKu; module Out; module HTML
483
639
  title = self.title
484
640
  a = create_html_element 'img'
485
641
  a.attributes['src'] = url
486
- a.attributes['title'] = title if title
642
+ a.attributes['alt'] = title.to_s
487
643
  return a
488
644
  end
489
645
 
@@ -578,22 +734,35 @@ module MaRuKu; module Out; module HTML
578
734
  tr<<x
579
735
  end
580
736
 
581
- tbody << tr
737
+ tbody << tr << Text.new("\n")
582
738
  end
583
739
  table << tbody
584
740
  table
585
741
  end
586
742
 
587
743
  def to_html_head_cell; wrap_as_element('th') end
588
- def to_html_cell; wrap_as_element('td') end
744
+ def to_html_cell
745
+ if @attributes[:scope]
746
+ wrap_as_element('th', [:scope])
747
+ else
748
+ wrap_as_element('td')
749
+ end
750
+ end
589
751
 
590
752
  def to_html_entity
753
+ MaRuKu::Out::Latex.need_entity_table
754
+
591
755
  entity_name = self.entity_name
592
756
 
757
+ if (e = MaRuKu::Out::Latex::ENTITY_TABLE[entity_name]) && e.html_num
758
+ entity_name = e.html_num
759
+ end
760
+
593
761
  # Fix for Internet Explorer
594
762
  if entity_name == 'apos'
595
763
  entity_name = 39
596
764
  end
765
+
597
766
 
598
767
  if entity_name.kind_of? Fixnum
599
768
  # Entity.new(entity_name)