From 148afb77e0b731939cb3d88a7a181ab17cf14e83 Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Wed, 10 Oct 2007 22:06:44 -0500 Subject: [PATCH] Sync with latest Maruku Apparently, Maruku had trouble with the latest release of Ruby (1.8.6, patchlevel 110). This should fix it. --- .../maruku/lib/maruku/ext/math/latex_fix.rb | 19 +++-- .../ext/math/mathml_engines/itex2mml.rb | 4 +- .../maruku/lib/maruku/ext/math/to_latex.rb | 6 +- .../maruku/lib/maruku/input/parse_doc.rb | 1 + .../maruku/lib/maruku/output/to_html.rb | 72 ++++++++++++------- vendor/plugins/maruku/lib/maruku/version.rb | 2 +- 6 files changed, 61 insertions(+), 43 deletions(-) diff --git a/vendor/plugins/maruku/lib/maruku/ext/math/latex_fix.rb b/vendor/plugins/maruku/lib/maruku/ext/math/latex_fix.rb index 6ce588d6..90bb53d2 100644 --- a/vendor/plugins/maruku/lib/maruku/ext/math/latex_fix.rb +++ b/vendor/plugins/maruku/lib/maruku/ext/math/latex_fix.rb @@ -1,12 +1,11 @@ class String - - # fix some LaTeX command-name clashes - def fix_latex - if #{html_math_engine} == 'itex2mml' - s = self.gsub("\\mathop{", "\\operatorname{") - s.gsub("\\space{", "\\itexspace{") - else - self - end - end + # fix some LaTeX command-name clashes + def fix_latex + if #{html_math_engine} == 'itex2mml' + s = self.gsub("\\mathop{", "\\operatorname{") + s.gsub("\\space{", "\\itexspace{") + else + self + end + end end diff --git a/vendor/plugins/maruku/lib/maruku/ext/math/mathml_engines/itex2mml.rb b/vendor/plugins/maruku/lib/maruku/ext/math/mathml_engines/itex2mml.rb index 164247fb..69d273d3 100644 --- a/vendor/plugins/maruku/lib/maruku/ext/math/mathml_engines/itex2mml.rb +++ b/vendor/plugins/maruku/lib/maruku/ext/math/mathml_engines/itex2mml.rb @@ -14,8 +14,8 @@ module MaRuKu; module Out; module HTML doc = Document.new(mathml, {:respect_whitespace =>:all}).root return doc rescue LoadError => e - maruku_error "Could not load package 'itex2mml'.\n"+ - "Please install it." + maruku_error "Could not load package 'itex2mml'.\n"+ "Please install it." unless $already_warned_itex2mml + $already_warned_itex2mml = true rescue REXML::ParseException => e maruku_error "Invalid MathML TeX: \n#{add_tabs(tex,1,'tex>')}"+ "\n\n #{e.inspect}" diff --git a/vendor/plugins/maruku/lib/maruku/ext/math/to_latex.rb b/vendor/plugins/maruku/lib/maruku/ext/math/to_latex.rb index fb925bc1..12d8a4d6 100644 --- a/vendor/plugins/maruku/lib/maruku/ext/math/to_latex.rb +++ b/vendor/plugins/maruku/lib/maruku/ext/math/to_latex.rb @@ -1,9 +1,9 @@ -module MaRuKu; module Out; module Latex - require 'maruku/ext/math/latex_fix' +module MaRuKu; module Out; module Latex + def to_latex_inline_math - s = "$#{self.math.strip}$".fix_latex + "$#{self.math.strip}$".fix_latex end def to_latex_equation diff --git a/vendor/plugins/maruku/lib/maruku/input/parse_doc.rb b/vendor/plugins/maruku/lib/maruku/input/parse_doc.rb index bc7fb595..5b11725e 100644 --- a/vendor/plugins/maruku/lib/maruku/input/parse_doc.rb +++ b/vendor/plugins/maruku/lib/maruku/input/parse_doc.rb @@ -173,6 +173,7 @@ Disabled by default because of security concerns. self.abbreviations.each do |abbrev, title| reg = Regexp.new(Regexp.escape(abbrev)) self.replace_each_string do |s| + # bug if many abbreviations are present (agorf) if m = reg.match(s) e = md_abbr(abbrev.dup, title ? title.dup : nil) [m.pre_match, e, m.post_match] diff --git a/vendor/plugins/maruku/lib/maruku/output/to_html.rb b/vendor/plugins/maruku/lib/maruku/output/to_html.rb index 7e053cd6..c5a05854 100644 --- a/vendor/plugins/maruku/lib/maruku/output/to_html.rb +++ b/vendor/plugins/maruku/lib/maruku/output/to_html.rb @@ -18,9 +18,16 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #++ - require 'rexml/document' +begin + require 'rexml/formatters/pretty' + require 'rexml/formatters/default' + $rexml_new_version = true +rescue LoadError + $rexml_new_version = false +end + class String # A string is rendered into HTML by creating # a REXML::Text node. REXML takes care of all the encoding. @@ -30,11 +37,6 @@ class String end -class REXML::Element - # We only want to output the children in Maruku::to_html - public :write_children -end - # This module groups all functions related to HTML export. module MaRuKu; module Out; module HTML include REXML @@ -42,7 +44,7 @@ module MaRuKu; module Out; module HTML # Render as an HTML fragment (no head, just the content of BODY). (returns a string) def to_html(context={}) indent = context[:indent] || -1 - ie_hack = context[:ie_hack] ||true + ie_hack = context[:ie_hack] || true div = Element.new 'dummy' children_to_html.each do |e| @@ -60,7 +62,21 @@ module MaRuKu; module Out; module HTML # REXML Bug? if indent!=-1 whitespace is not respected for 'pre' elements # containing code. xml ="" - div.write_children(xml,indent,transitive=true,ie_hack) + + if $rexml_new_version + formatter = if indent > -1 + REXML::Formatters::Pretty.new( indent, ie_hack ) + else + REXML::Formatters::Default.new( ie_hack ) + end + formatter.write( div, xml) + else + div.write(xml,indent,transitive=true,ie_hack) + end + + xml.gsub!(/\A\s*/,'') + xml.gsub!(/\s*<\/dummy>\Z/,'') + xml.gsub!(/\A/,'') xml end @@ -141,6 +157,23 @@ Synonim for `title`. =end + # Render to an HTML fragment (returns a REXML document tree) + def to_html_tree + div = Element.new 'div' + div.attributes['class'] = 'maruku_wrapper_div' + children_to_html.each do |e| + div << e + end + + # render footnotes + if @doc.footnotes_order.size > 0 + div << render_footnotes + end + + doc = Document.new(nil,{:respect_whitespace =>:all}) + doc << div + end + =begin maruku_doc Attribute: css Scope: document @@ -150,26 +183,11 @@ Summary: Activates CSS stylesheets for HTML. `css` should be a space-separated list of urls. Example: - + CSS: style.css math.css =end - # Render to an HTML fragment (returns a REXML document tree) - def to_html_tree - div = Element.new 'div' - div.attributes['class'] = 'maruku_wrapper_div' - children_to_html.each do |e| - div << e - end - # render footnotes - if @doc.footnotes_order.size > 0 - div << render_footnotes - end - - doc = Document.new(nil,{:respect_whitespace =>:all}) - doc << div - end # Render to a complete HTML document (returns a REXML document tree) def to_html_document_tree @@ -465,7 +483,7 @@ by Maruku, to have the same results in both HTML and LaTeX. end def source2html(source) - source = source.gsub(/&/,'&') +# source = source.gsub(/&/,'&') source = Text.normalize(source) source = source.gsub(/\'/,''') # IE bug source = source.gsub(/'/,''') # IE bug @@ -591,7 +609,7 @@ of the form `#ff00ff`. code = Element.new 'code', pre s = source - s = s.gsub(/&/,'&') +# s = s.gsub(/&/,'&') s = Text.normalize(s) s = s.gsub(/\'/,''') # IE bug s = s.gsub(/'/,''') # IE bug @@ -892,7 +910,7 @@ If true, raw HTML is discarded from the output. # Entity.new(entity_name) Text.new('&#%d;' % [entity_name], false, nil, true) else - Text.new('&%s;' % [entity_name]) + Text.new('&%s;' % [entity_name], false, nil, true) end end diff --git a/vendor/plugins/maruku/lib/maruku/version.rb b/vendor/plugins/maruku/lib/maruku/version.rb index 1a12be9c..886f372a 100644 --- a/vendor/plugins/maruku/lib/maruku/version.rb +++ b/vendor/plugins/maruku/lib/maruku/version.rb @@ -19,7 +19,7 @@ #++ module MaRuKu - Version = '0.5.6' + Version = '0.5.7' MarukuURL = 'http://maruku.rubyforge.org/'