patcito-maruku 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +23 -0
- data/LICENSE +340 -0
- data/README.md +73 -0
- data/bin/maruku +196 -0
- data/bin/marutex +4 -0
- data/data/entities.xml +261 -0
- data/docs/changelog.md +334 -0
- data/docs/div_syntax.md +36 -0
- data/docs/entity_test.md +23 -0
- data/docs/markdown_syntax.md +899 -0
- data/docs/maruku.md +346 -0
- data/docs/math.md +194 -0
- data/docs/other_stuff.md +51 -0
- data/docs/proposal.md +309 -0
- data/docs/website/src/bluecloth.md +25 -0
- data/docs/website/src/download.md +31 -0
- data/docs/website/src/maruku.md +261 -0
- data/docs/website/src/proposal.md +271 -0
- data/lib/maruku.rb +132 -0
- data/lib/maruku/attributes.rb +138 -0
- data/lib/maruku/defaults.rb +69 -0
- data/lib/maruku/errors.rb +89 -0
- data/lib/maruku/ext/div.rb +121 -0
- data/lib/maruku/ext/fenced_code.rb +78 -0
- data/lib/maruku/ext/math.rb +37 -0
- data/lib/maruku/ext/math/elements.rb +21 -0
- data/lib/maruku/ext/math/latex_fix.rb +12 -0
- data/lib/maruku/ext/math/mathml_engines/blahtex.rb +93 -0
- data/lib/maruku/ext/math/mathml_engines/itex2mml.rb +39 -0
- data/lib/maruku/ext/math/mathml_engines/none.rb +21 -0
- data/lib/maruku/ext/math/mathml_engines/ritex.rb +24 -0
- data/lib/maruku/ext/math/parsing.rb +125 -0
- data/lib/maruku/ext/math/to_html.rb +237 -0
- data/lib/maruku/ext/math/to_latex.rb +36 -0
- data/lib/maruku/ext/yaml.rb +43 -0
- data/lib/maruku/helpers.rb +214 -0
- data/lib/maruku/input/charsource.rb +326 -0
- data/lib/maruku/input/extensions.rb +69 -0
- data/lib/maruku/input/html_helper.rb +189 -0
- data/lib/maruku/input/linesource.rb +111 -0
- data/lib/maruku/input/parse_block.rb +608 -0
- data/lib/maruku/input/parse_doc.rb +240 -0
- data/lib/maruku/input/parse_span_better.rb +746 -0
- data/lib/maruku/input/rubypants.rb +225 -0
- data/lib/maruku/input/type_detection.rb +147 -0
- data/lib/maruku/input_textile2/t2_parser.rb +163 -0
- data/lib/maruku/maruku.rb +31 -0
- data/lib/maruku/output/s5/fancy.rb +756 -0
- data/lib/maruku/output/s5/to_s5.rb +138 -0
- data/lib/maruku/output/to_html.rb +994 -0
- data/lib/maruku/output/to_latex.rb +580 -0
- data/lib/maruku/output/to_latex_entities.rb +101 -0
- data/lib/maruku/output/to_latex_strings.rb +64 -0
- data/lib/maruku/output/to_markdown.rb +164 -0
- data/lib/maruku/output/to_s.rb +54 -0
- data/lib/maruku/string_utils.rb +185 -0
- data/lib/maruku/structures.rb +143 -0
- data/lib/maruku/structures_inspect.rb +51 -0
- data/lib/maruku/structures_iterators.rb +48 -0
- data/lib/maruku/textile2.rb +1 -0
- data/lib/maruku/toc.rb +214 -0
- data/lib/maruku/usage/example1.rb +33 -0
- data/lib/maruku/version +0 -0
- data/lib/maruku/version.rb +54 -0
- data/spec/block_docs/abbreviations.md +52 -0
- data/spec/block_docs/alt.md +17 -0
- data/spec/block_docs/attributes/att2.md +20 -0
- data/spec/block_docs/attributes/att3.md +28 -0
- data/spec/block_docs/attributes/attributes.md +57 -0
- data/spec/block_docs/attributes/circular.md +26 -0
- data/spec/block_docs/attributes/default.md +22 -0
- data/spec/block_docs/blank.md +24 -0
- data/spec/block_docs/blanks_in_code.md +75 -0
- data/spec/block_docs/bug_def.md +16 -0
- data/spec/block_docs/bug_table.md +46 -0
- data/spec/block_docs/code.md +34 -0
- data/spec/block_docs/code2.md +28 -0
- data/spec/block_docs/code3.md +71 -0
- data/spec/block_docs/data_loss.md +25 -0
- data/spec/block_docs/divs/div1.md +167 -0
- data/spec/block_docs/divs/div2.md +21 -0
- data/spec/block_docs/divs/div3_nest.md +45 -0
- data/spec/block_docs/easy.md +15 -0
- data/spec/block_docs/email.md +20 -0
- data/spec/block_docs/encoding/iso-8859-1.md +23 -0
- data/spec/block_docs/encoding/utf-8.md +18 -0
- data/spec/block_docs/entities.md +94 -0
- data/spec/block_docs/escaping.md +67 -0
- data/spec/block_docs/extra_dl.md +52 -0
- data/spec/block_docs/extra_header_id.md +63 -0
- data/spec/block_docs/extra_table1.md +37 -0
- data/spec/block_docs/footnotes.md +97 -0
- data/spec/block_docs/headers.md +37 -0
- data/spec/block_docs/hex_entities.md +37 -0
- data/spec/block_docs/hrule.md +39 -0
- data/spec/block_docs/html2.md +22 -0
- data/spec/block_docs/html3.md +31 -0
- data/spec/block_docs/html4.md +25 -0
- data/spec/block_docs/html5.md +23 -0
- data/spec/block_docs/ie.md +49 -0
- data/spec/block_docs/images.md +90 -0
- data/spec/block_docs/images2.md +31 -0
- data/spec/block_docs/inline_html.md +152 -0
- data/spec/block_docs/inline_html2.md +21 -0
- data/spec/block_docs/links.md +152 -0
- data/spec/block_docs/links2.md +22 -0
- data/spec/block_docs/list1.md +46 -0
- data/spec/block_docs/list12.md +28 -0
- data/spec/block_docs/list2.md +56 -0
- data/spec/block_docs/list3.md +64 -0
- data/spec/block_docs/list4.md +89 -0
- data/spec/block_docs/lists.md +192 -0
- data/spec/block_docs/lists10.md +34 -0
- data/spec/block_docs/lists11.md +23 -0
- data/spec/block_docs/lists6.md +41 -0
- data/spec/block_docs/lists9.md +64 -0
- data/spec/block_docs/lists_after_paragraph.md +208 -0
- data/spec/block_docs/lists_ol.md +262 -0
- data/spec/block_docs/loss.md +16 -0
- data/spec/block_docs/math/equations.md +45 -0
- data/spec/block_docs/math/inline.md +46 -0
- data/spec/block_docs/math/math2.md +45 -0
- data/spec/block_docs/math/notmath.md +25 -0
- data/spec/block_docs/math/table.md +25 -0
- data/spec/block_docs/math/table2.md +42 -0
- data/spec/block_docs/misc_sw.md +525 -0
- data/spec/block_docs/notyet/escape.md +21 -0
- data/spec/block_docs/notyet/header_after_par.md +58 -0
- data/spec/block_docs/notyet/ticks.md +18 -0
- data/spec/block_docs/notyet/triggering.md +157 -0
- data/spec/block_docs/olist.md +45 -0
- data/spec/block_docs/one.md +15 -0
- data/spec/block_docs/paragraph.md +16 -0
- data/spec/block_docs/paragraph_rules/dont_merge_ref.md +42 -0
- data/spec/block_docs/paragraph_rules/tab_is_blank.md +24 -0
- data/spec/block_docs/paragraphs.md +46 -0
- data/spec/block_docs/pending/amps.md +15 -0
- data/spec/block_docs/pending/empty_cells.md +37 -0
- data/spec/block_docs/pending/link.md +72 -0
- data/spec/block_docs/pending/ref.md +21 -0
- data/spec/block_docs/recover/recover_links.md +15 -0
- data/spec/block_docs/red_tests/abbrev.md +679 -0
- data/spec/block_docs/red_tests/lists7.md +32 -0
- data/spec/block_docs/red_tests/lists7b.md +65 -0
- data/spec/block_docs/red_tests/lists8.md +42 -0
- data/spec/block_docs/red_tests/ref.md +23 -0
- data/spec/block_docs/red_tests/xml.md +35 -0
- data/spec/block_docs/references/long_example.md +71 -0
- data/spec/block_docs/references/spaces_and_numbers.md +15 -0
- data/spec/block_docs/smartypants.md +114 -0
- data/spec/block_docs/syntax_hl.md +52 -0
- data/spec/block_docs/table_attributes.md +34 -0
- data/spec/block_docs/test.md +19 -0
- data/spec/block_docs/underscore_in_words.md +15 -0
- data/spec/block_docs/wrapping.md +67 -0
- data/spec/block_docs/xml2.md +19 -0
- data/spec/block_docs/xml3.md +26 -0
- data/spec/block_docs/xml_instruction.md +52 -0
- data/spec/block_spec.rb +49 -0
- data/spec/span_spec.rb +254 -0
- data/spec/spec_helper.rb +6 -0
- metadata +247 -0
@@ -0,0 +1,39 @@
|
|
1
|
+
module MaRuKu
|
2
|
+
module Out
|
3
|
+
module HTML
|
4
|
+
def convert_to_mathml_itex2mml(kind, tex)
|
5
|
+
return if $already_warned_itex2mml
|
6
|
+
begin
|
7
|
+
require 'itextomml'
|
8
|
+
rescue LoadError => e
|
9
|
+
maruku_error "Could not load package 'itex2mml'.\nPlease install it." unless $already_warned_itex2mml
|
10
|
+
$already_warned_itex2mml = true
|
11
|
+
return nil
|
12
|
+
end
|
13
|
+
begin
|
14
|
+
require 'instiki_stringsupport'
|
15
|
+
rescue LoadError
|
16
|
+
require 'itex_stringsupport'
|
17
|
+
end
|
18
|
+
|
19
|
+
parser = Itex2MML::Parser.new
|
20
|
+
mathml =
|
21
|
+
case kind
|
22
|
+
when :equation; parser.block_filter(tex)
|
23
|
+
when :inline; parser.inline_filter(tex)
|
24
|
+
else
|
25
|
+
maruku_error "Unknown itex2mml kind: #{kind}"
|
26
|
+
return
|
27
|
+
end
|
28
|
+
|
29
|
+
return Document.new(mathml.to_utf8, :respect_whitespace => :all).root
|
30
|
+
rescue REXML::ParseException => e
|
31
|
+
maruku_error "Invalid MathML TeX: \n#{tex.gsub(/^/, 'tex>')}\n\n #{e.inspect}"
|
32
|
+
nil
|
33
|
+
rescue
|
34
|
+
maruku_error "Could not produce MathML TeX: \n#{tex}\n\n #{e.inspect}"
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module MaRuKu; module Out; module HTML
|
2
|
+
|
3
|
+
def convert_to_mathml_none(kind, tex)
|
4
|
+
# You can: either return a REXML::Element
|
5
|
+
# return Element.new 'div'
|
6
|
+
# or return an empty array on error
|
7
|
+
# return []
|
8
|
+
# or have a string parsed by REXML:
|
9
|
+
mathml = "<code>#{tex.gsub( /&/, "&" ).
|
10
|
+
gsub( /</, "<" ).gsub( />/, ">" ).
|
11
|
+
gsub(/'/, "'" ).gsub(/"/, """ )}</code>"
|
12
|
+
return Document.new(mathml).root
|
13
|
+
end
|
14
|
+
|
15
|
+
def convert_to_png_none(kind, tex)
|
16
|
+
return nil
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
end end end
|
21
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module MaRuKu; module Out; module HTML
|
2
|
+
|
3
|
+
def convert_to_mathml_ritex(kind, tex)
|
4
|
+
begin
|
5
|
+
if not $ritex_parser
|
6
|
+
require 'ritex'
|
7
|
+
$ritex_parser = Ritex::Parser.new
|
8
|
+
end
|
9
|
+
|
10
|
+
mathml = $ritex_parser.parse(tex.strip)
|
11
|
+
doc = Document.new(mathml, {:respect_whitespace =>:all}).root
|
12
|
+
return doc
|
13
|
+
rescue LoadError => e
|
14
|
+
maruku_error "Could not load package 'ritex'.\n"+
|
15
|
+
"Please install it using:\n"+
|
16
|
+
" $ gem install ritex\n\n"+e.inspect
|
17
|
+
rescue Racc::ParseError => e
|
18
|
+
maruku_error "Could not parse TeX: \n#{tex}"+
|
19
|
+
"\n\n #{e.inspect}"
|
20
|
+
end
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
|
24
|
+
end end end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
module MaRuKu
|
2
|
+
class MDDocument
|
3
|
+
# A hash of equation ids to equation elements
|
4
|
+
#
|
5
|
+
# @return [String => MDElement]
|
6
|
+
attr_accessor :eqid2eq
|
7
|
+
|
8
|
+
def is_math_enabled?
|
9
|
+
get_setting :math_enabled
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# TODO: Properly scope all these regexps
|
15
|
+
# Everything goes; takes care of escaping the "\$" inside the expression
|
16
|
+
RegInlineMath = /\${1}((?:[^\$]|\\\$)+)\$/
|
17
|
+
|
18
|
+
MaRuKu::In::Markdown.register_span_extension(
|
19
|
+
:chars => ?$,
|
20
|
+
:regexp => RegInlineMath,
|
21
|
+
:handler => lambda do |doc, src, con|
|
22
|
+
next false unless doc.is_math_enabled?
|
23
|
+
next false unless m = src.read_regexp(RegInlineMath)
|
24
|
+
math = m.captures.compact.first
|
25
|
+
con.push doc.md_inline_math(math)
|
26
|
+
true
|
27
|
+
end)
|
28
|
+
|
29
|
+
|
30
|
+
MathOpen1 = Regexp.escape('\\begin{equation}')
|
31
|
+
MathClose1 = Regexp.escape('\\end{equation}')
|
32
|
+
MathOpen2 = Regexp.escape('\\[')
|
33
|
+
MathClose2 = Regexp.escape('\\]')
|
34
|
+
MathOpen3 = Regexp.escape('$$')
|
35
|
+
MathClose3 = Regexp.escape('$$')
|
36
|
+
|
37
|
+
EqLabel = /(?:\((\w+)\))/
|
38
|
+
EquationOpen = /#{MathOpen1}|#{MathOpen2}|#{MathOpen3}/
|
39
|
+
EquationClose = /#{MathClose1}|#{MathClose2}|#{MathClose3}/
|
40
|
+
|
41
|
+
# $1 is opening, $2 is tex
|
42
|
+
EquationStart = /^[ ]{0,3}(#{EquationOpen})(.*)$/
|
43
|
+
# $1 is tex, $2 is closing, $3 is tex
|
44
|
+
EquationEnd = /^(.*)(#{EquationClose})\s*#{EqLabel}?\s*$/
|
45
|
+
# $1 is opening, $2 is tex, $3 is closing, $4 is label
|
46
|
+
OneLineEquation = /^[ ]{0,3}(#{EquationOpen})(.*)(#{EquationClose})\s*#{EqLabel}?\s*$/
|
47
|
+
MultiLineEquation = /^[ ]{0,3}(#{EquationOpen})(.*?)(#{EquationClose})\s*?#{EqLabel}?\s*?$/m
|
48
|
+
|
49
|
+
if MaRuKu::Globals[:html_math_output_span_equations]
|
50
|
+
MaRuKu::In::Markdown.register_span_extension(
|
51
|
+
:chars => ?\\,
|
52
|
+
:regexp => EquationStart,
|
53
|
+
:handler => lambda do |doc, src, con|
|
54
|
+
next false unless doc.is_math_enabled?
|
55
|
+
next false unless m = src.read_regexp(MultiLineEquation)
|
56
|
+
opening, tex, closing, label = $1, $2, $3, $4
|
57
|
+
numerate = doc.get_setting(:math_numbered).include?(opening)
|
58
|
+
con.push doc.md_equation(tex, label, numerate)
|
59
|
+
true
|
60
|
+
end)
|
61
|
+
else
|
62
|
+
MaRuKu::In::Markdown.register_block_extension(
|
63
|
+
:regexp => EquationStart,
|
64
|
+
:handler => lambda do |doc, src, con|
|
65
|
+
next false unless doc.is_math_enabled?
|
66
|
+
first = src.shift_line
|
67
|
+
if first =~ OneLineEquation
|
68
|
+
opening, tex, closing, label = $1, $2, $3, $4
|
69
|
+
numerate = doc.get_setting(:math_numbered).include?(opening)
|
70
|
+
con.push doc.md_equation(tex, label, numerate)
|
71
|
+
next true
|
72
|
+
end
|
73
|
+
|
74
|
+
opening, tex = first.scan(EquationStart).first
|
75
|
+
numerate = doc.get_setting(:math_numbered).include?(opening)
|
76
|
+
label = nil
|
77
|
+
loop do
|
78
|
+
unless src.cur_line
|
79
|
+
doc.maruku_error(
|
80
|
+
"Stream finished while reading equation\n\n" + tex.gsub(/^/, '$> '),
|
81
|
+
src, con)
|
82
|
+
break
|
83
|
+
end
|
84
|
+
|
85
|
+
line = src.shift_line
|
86
|
+
if line =~ EquationEnd
|
87
|
+
tex_line, closing = $1, $2
|
88
|
+
label = $3 if $3
|
89
|
+
tex << tex_line << "\n"
|
90
|
+
break
|
91
|
+
end
|
92
|
+
|
93
|
+
tex << line << "\n"
|
94
|
+
end
|
95
|
+
con.push doc.md_equation(tex, label, numerate)
|
96
|
+
true
|
97
|
+
end)
|
98
|
+
end
|
99
|
+
|
100
|
+
# This adds support for \eqref
|
101
|
+
RegEqrefLatex = /\\eqref\{(\w+)\}/
|
102
|
+
RegEqPar = /\(eq:(\w+)\)/
|
103
|
+
RegEqref = Regexp.union(RegEqrefLatex, RegEqPar)
|
104
|
+
|
105
|
+
MaRuKu::In::Markdown.register_span_extension(
|
106
|
+
:chars => [?\\, ?(],
|
107
|
+
:regexp => RegEqref,
|
108
|
+
:handler => lambda do |doc, src, con|
|
109
|
+
return false unless doc.is_math_enabled?
|
110
|
+
eqid = src.read_regexp(RegEqref).captures.compact.first
|
111
|
+
con.push doc.md_el(:eqref, [], :eqid => eqid)
|
112
|
+
true
|
113
|
+
end)
|
114
|
+
|
115
|
+
# This adds support for \ref
|
116
|
+
RegRef = /\\ref\{(\w*)\}/
|
117
|
+
MaRuKu::In::Markdown.register_span_extension(
|
118
|
+
:chars => [?\\, ?(],
|
119
|
+
:regexp => RegRef,
|
120
|
+
:handler => lambda do |doc, src, con|
|
121
|
+
return false unless doc.is_math_enabled?
|
122
|
+
refid = src.read_regexp(RegRef).captures.compact.first
|
123
|
+
con.push doc.md_el(:divref, [], :refid => refid)
|
124
|
+
true
|
125
|
+
end)
|
@@ -0,0 +1,237 @@
|
|
1
|
+
=begin maruku_doc
|
2
|
+
Extension: math
|
3
|
+
Attribute: html_math_engine
|
4
|
+
Scope: document, element
|
5
|
+
Output: html
|
6
|
+
Summary: Select the rendering engine for MathML.
|
7
|
+
Default: <?mrk Globals[:html_math_engine].to_s ?>
|
8
|
+
|
9
|
+
Select the rendering engine for math.
|
10
|
+
|
11
|
+
If you want to use your custom engine `foo`, then set:
|
12
|
+
|
13
|
+
HTML math engine: foo
|
14
|
+
{:lang=markdown}
|
15
|
+
|
16
|
+
and then implement two functions:
|
17
|
+
|
18
|
+
def convert_to_mathml_foo(kind, tex)
|
19
|
+
...
|
20
|
+
end
|
21
|
+
=end
|
22
|
+
|
23
|
+
=begin maruku_doc
|
24
|
+
Extension: math
|
25
|
+
Attribute: html_png_engine
|
26
|
+
Scope: document, element
|
27
|
+
Output: html
|
28
|
+
Summary: Select the rendering engine for math.
|
29
|
+
Default: <?mrk Globals[:html_math_engine].to_s ?>
|
30
|
+
|
31
|
+
Same thing as `html_math_engine`, only for PNG output.
|
32
|
+
|
33
|
+
def convert_to_png_foo(kind, tex)
|
34
|
+
# same thing
|
35
|
+
...
|
36
|
+
end
|
37
|
+
{:lang=ruby}
|
38
|
+
|
39
|
+
=end
|
40
|
+
|
41
|
+
module MaRuKu
|
42
|
+
module Out
|
43
|
+
module HTML
|
44
|
+
# Creates an xml Mathml document of this node's TeX code.
|
45
|
+
#
|
46
|
+
# @return [REXML::Document]
|
47
|
+
def render_mathml(kind, tex)
|
48
|
+
engine = get_setting(:html_math_engine)
|
49
|
+
method = "convert_to_mathml_#{engine}"
|
50
|
+
if self.respond_to? method
|
51
|
+
mathml = self.send(method, kind, tex)
|
52
|
+
return mathml || convert_to_mathml_none(kind, tex)
|
53
|
+
end
|
54
|
+
|
55
|
+
# TODO: Warn here
|
56
|
+
puts "A method called #{method} should be defined."
|
57
|
+
return convert_to_mathml_none(kind, tex)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Renders a PNG image of this node's TeX code.
|
61
|
+
# Returns
|
62
|
+
#
|
63
|
+
# @return [MaRuKu::Out::HTML::PNG, nil]
|
64
|
+
# A struct describing the location and size of the image,
|
65
|
+
# or nil if no library is loaded that can render PNGs.
|
66
|
+
def render_png(kind, tex)
|
67
|
+
engine = get_setting(:html_png_engine)
|
68
|
+
method = "convert_to_png_#{engine}".to_sym
|
69
|
+
return self.send(method, kind, tex) if self.respond_to? method
|
70
|
+
|
71
|
+
puts "A method called #{method} should be defined."
|
72
|
+
return nil
|
73
|
+
end
|
74
|
+
|
75
|
+
# Renders a MathJax block of out this node's TeX code.
|
76
|
+
#
|
77
|
+
# @return [REXML::Document]
|
78
|
+
def render_mathjax(kind,tex)
|
79
|
+
if kind == :equation
|
80
|
+
# using the script that works with Instapaper
|
81
|
+
# see http://www.leancrew.com/all-this/2010/11/mathjax-markdown-and-instapaper/
|
82
|
+
# <span class="MathJax_Preview"><code>[math]</code></span>
|
83
|
+
# <script type="math/tex; mode=display">\int f(x) = F(x)</script>
|
84
|
+
|
85
|
+
equation = create_html_element 'span'
|
86
|
+
|
87
|
+
span = create_html_element 'span'
|
88
|
+
add_class_to(span,'MathJax_Preview')
|
89
|
+
code = convert_to_mathml_none(:equation, tex.strip)
|
90
|
+
span << code
|
91
|
+
|
92
|
+
script = create_html_element 'script'
|
93
|
+
script.attributes['type'] = 'math/tex; mode=display'
|
94
|
+
script << Text.new("#{tex.strip}")
|
95
|
+
|
96
|
+
equation << span
|
97
|
+
equation << script
|
98
|
+
|
99
|
+
return equation
|
100
|
+
else
|
101
|
+
script = create_html_element 'script'
|
102
|
+
script.attributes['type'] = 'math/tex'
|
103
|
+
script << Text.new("#{tex.strip}")
|
104
|
+
return script
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def pixels_per_ex
|
109
|
+
$pixels_per_ex ||= render_png(:inline, "x").height
|
110
|
+
end
|
111
|
+
|
112
|
+
def adjust_png(png, use_depth)
|
113
|
+
src = png.src
|
114
|
+
|
115
|
+
height_in_px = png.height
|
116
|
+
depth_in_px = png.depth
|
117
|
+
height_in_ex = height_in_px / pixels_per_ex
|
118
|
+
depth_in_ex = depth_in_px / pixels_per_ex
|
119
|
+
total_height_in_ex = height_in_ex + depth_in_ex
|
120
|
+
style = ""
|
121
|
+
style << "vertical-align: -#{depth_in_ex}ex;" if use_depth
|
122
|
+
style << "height: #{total_height_in_ex}ex;"
|
123
|
+
|
124
|
+
img = Element.new 'img'
|
125
|
+
img.attributes['src'] = src
|
126
|
+
img.attributes['style'] = style
|
127
|
+
img.attributes['alt'] = "$#{self.math.strip}$"
|
128
|
+
img
|
129
|
+
end
|
130
|
+
|
131
|
+
def to_html_inline_math
|
132
|
+
mathml = get_setting(:html_math_output_mathml) && render_mathml(:inline, self.math)
|
133
|
+
png = get_setting(:html_math_output_png) && render_png(:inline, self.math)
|
134
|
+
mathjax = get_setting(:html_math_output_mathjax) && render_mathjax(:inline, self.math)
|
135
|
+
|
136
|
+
span = create_html_element 'span'
|
137
|
+
add_class_to(span, 'maruku-inline')
|
138
|
+
|
139
|
+
if mathml
|
140
|
+
add_class_to(mathml, 'maruku-mathml')
|
141
|
+
return mathml
|
142
|
+
end
|
143
|
+
|
144
|
+
if png
|
145
|
+
img = adjust_png(png, true)
|
146
|
+
add_class_to(img, 'maruku-png')
|
147
|
+
span << img
|
148
|
+
end
|
149
|
+
|
150
|
+
if mathjax
|
151
|
+
span << mathjax
|
152
|
+
end
|
153
|
+
|
154
|
+
span
|
155
|
+
end
|
156
|
+
|
157
|
+
def to_html_equation
|
158
|
+
mathml = get_setting(:html_math_output_mathml) && render_mathml(:equation, self.math)
|
159
|
+
png = get_setting(:html_math_output_png) && render_png(:equation, self.math)
|
160
|
+
mathjax = get_setting(:html_math_output_mathjax) && render_mathjax(:equation, self.math)
|
161
|
+
|
162
|
+
if mathjax
|
163
|
+
span = create_html_element 'span'
|
164
|
+
add_class_to(span, 'maruku-equation')
|
165
|
+
|
166
|
+
span << mathjax
|
167
|
+
|
168
|
+
# mathjax handles equation numbering
|
169
|
+
return span
|
170
|
+
end
|
171
|
+
|
172
|
+
div = create_html_element 'div'
|
173
|
+
add_class_to(div, 'maruku-equation')
|
174
|
+
if mathml
|
175
|
+
if self.label # then numerate
|
176
|
+
span = Element.new 'span'
|
177
|
+
span.attributes['class'] = 'maruku-eq-number'
|
178
|
+
span << Text.new("(#{self.num})")
|
179
|
+
div << span
|
180
|
+
div.attributes['id'] = "eq:#{self.label}"
|
181
|
+
end
|
182
|
+
add_class_to(mathml, 'maruku-mathml')
|
183
|
+
div << mathml
|
184
|
+
end
|
185
|
+
|
186
|
+
if png
|
187
|
+
img = adjust_png(png, false)
|
188
|
+
add_class_to(img, 'maruku-png')
|
189
|
+
div << img
|
190
|
+
if self.label # then numerate
|
191
|
+
span = Element.new 'span'
|
192
|
+
span.attributes['class'] = 'maruku-eq-number'
|
193
|
+
span << Text.new("(#{self.num})")
|
194
|
+
div << span
|
195
|
+
div.attributes['id'] = "eq:#{self.label}"
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
source_span = Element.new 'span'
|
200
|
+
add_class_to(source_span, 'maruku-eq-tex')
|
201
|
+
code = convert_to_mathml_none(:equation, self.math.strip)
|
202
|
+
code.attributes['style'] = 'display: none'
|
203
|
+
source_span << code
|
204
|
+
div << source_span
|
205
|
+
|
206
|
+
div
|
207
|
+
end
|
208
|
+
|
209
|
+
def to_html_eqref
|
210
|
+
unless eq = self.doc.eqid2eq[self.eqid]
|
211
|
+
maruku_error "Cannot find equation #{self.eqid.inspect}"
|
212
|
+
return Text.new("(eq:#{self.eqid})")
|
213
|
+
end
|
214
|
+
|
215
|
+
a = Element.new 'a'
|
216
|
+
a.attributes['class'] = 'maruku-eqref'
|
217
|
+
a.attributes['href'] = "#eq:#{self.eqid}"
|
218
|
+
a << Text.new("(#{eq.num})")
|
219
|
+
a
|
220
|
+
end
|
221
|
+
|
222
|
+
def to_html_divref
|
223
|
+
unless hash = self.doc.refid2ref.values.find {|h| h.has_key?(self.refid)}
|
224
|
+
maruku_error "Cannot find div #{self.refid.inspect}"
|
225
|
+
return Text.new("\\ref{#{self.refid}}")
|
226
|
+
end
|
227
|
+
ref= hash[self.refid]
|
228
|
+
|
229
|
+
a = Element.new 'a'
|
230
|
+
a.attributes['class'] = 'maruku-ref'
|
231
|
+
a.attributes['href'] = "#" + self.refid
|
232
|
+
a << Text.new(ref.num.to_s)
|
233
|
+
a
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|