Sync with latest Maruku

Apparently, Maruku had trouble with the latest release of Ruby (1.8.6, patchlevel 110). This should fix it.
This commit is contained in:
Jacques Distler 2007-10-10 22:06:44 -05:00
parent 5dd75d4cb0
commit 148afb77e0
6 changed files with 61 additions and 43 deletions

View file

@ -1,12 +1,11 @@
class String class String
# fix some LaTeX command-name clashes
# fix some LaTeX command-name clashes def fix_latex
def fix_latex if #{html_math_engine} == 'itex2mml'
if #{html_math_engine} == 'itex2mml' s = self.gsub("\\mathop{", "\\operatorname{")
s = self.gsub("\\mathop{", "\\operatorname{") s.gsub("\\space{", "\\itexspace{")
s.gsub("\\space{", "\\itexspace{") else
else self
self end
end end
end
end end

View file

@ -14,8 +14,8 @@ module MaRuKu; module Out; module HTML
doc = Document.new(mathml, {:respect_whitespace =>:all}).root doc = Document.new(mathml, {:respect_whitespace =>:all}).root
return doc return doc
rescue LoadError => e rescue LoadError => e
maruku_error "Could not load package 'itex2mml'.\n"+ maruku_error "Could not load package 'itex2mml'.\n"+ "Please install it." unless $already_warned_itex2mml
"Please install it." $already_warned_itex2mml = true
rescue REXML::ParseException => e rescue REXML::ParseException => e
maruku_error "Invalid MathML TeX: \n#{add_tabs(tex,1,'tex>')}"+ maruku_error "Invalid MathML TeX: \n#{add_tabs(tex,1,'tex>')}"+
"\n\n #{e.inspect}" "\n\n #{e.inspect}"

View file

@ -1,9 +1,9 @@
module MaRuKu; module Out; module Latex
require 'maruku/ext/math/latex_fix' require 'maruku/ext/math/latex_fix'
module MaRuKu; module Out; module Latex
def to_latex_inline_math def to_latex_inline_math
s = "$#{self.math.strip}$".fix_latex "$#{self.math.strip}$".fix_latex
end end
def to_latex_equation def to_latex_equation

View file

@ -173,6 +173,7 @@ Disabled by default because of security concerns.
self.abbreviations.each do |abbrev, title| self.abbreviations.each do |abbrev, title|
reg = Regexp.new(Regexp.escape(abbrev)) reg = Regexp.new(Regexp.escape(abbrev))
self.replace_each_string do |s| self.replace_each_string do |s|
# bug if many abbreviations are present (agorf)
if m = reg.match(s) if m = reg.match(s)
e = md_abbr(abbrev.dup, title ? title.dup : nil) e = md_abbr(abbrev.dup, title ? title.dup : nil)
[m.pre_match, e, m.post_match] [m.pre_match, e, m.post_match]

View file

@ -18,9 +18,16 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#++ #++
require 'rexml/document' 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 class String
# A string is rendered into HTML by creating # A string is rendered into HTML by creating
# a REXML::Text node. REXML takes care of all the encoding. # a REXML::Text node. REXML takes care of all the encoding.
@ -30,11 +37,6 @@ class String
end 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. # This module groups all functions related to HTML export.
module MaRuKu; module Out; module HTML module MaRuKu; module Out; module HTML
include REXML 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) # Render as an HTML fragment (no head, just the content of BODY). (returns a string)
def to_html(context={}) def to_html(context={})
indent = context[:indent] || -1 indent = context[:indent] || -1
ie_hack = context[:ie_hack] ||true ie_hack = context[:ie_hack] || true
div = Element.new 'dummy' div = Element.new 'dummy'
children_to_html.each do |e| 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 # REXML Bug? if indent!=-1 whitespace is not respected for 'pre' elements
# containing code. # containing code.
xml ="" 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<dummy>\s*/,'')
xml.gsub!(/\s*<\/dummy>\Z/,'')
xml.gsub!(/\A<dummy\s*\/>/,'')
xml xml
end end
@ -141,6 +157,23 @@ Synonim for `title`.
=end =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 =begin maruku_doc
Attribute: css Attribute: css
Scope: document Scope: document
@ -150,26 +183,11 @@ Summary: Activates CSS stylesheets for HTML.
`css` should be a space-separated list of urls. `css` should be a space-separated list of urls.
Example: Example:
CSS: style.css math.css CSS: style.css math.css
=end =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) # Render to a complete HTML document (returns a REXML document tree)
def to_html_document_tree def to_html_document_tree
@ -465,7 +483,7 @@ by Maruku, to have the same results in both HTML and LaTeX.
end end
def source2html(source) def source2html(source)
source = source.gsub(/&/,'&amp;') # source = source.gsub(/&/,'&amp;')
source = Text.normalize(source) source = Text.normalize(source)
source = source.gsub(/\&apos;/,'&#39;') # IE bug source = source.gsub(/\&apos;/,'&#39;') # IE bug
source = source.gsub(/'/,'&#39;') # IE bug source = source.gsub(/'/,'&#39;') # IE bug
@ -591,7 +609,7 @@ of the form `#ff00ff`.
code = Element.new 'code', pre code = Element.new 'code', pre
s = source s = source
s = s.gsub(/&/,'&amp;') # s = s.gsub(/&/,'&amp;')
s = Text.normalize(s) s = Text.normalize(s)
s = s.gsub(/\&apos;/,'&#39;') # IE bug s = s.gsub(/\&apos;/,'&#39;') # IE bug
s = s.gsub(/'/,'&#39;') # IE bug s = s.gsub(/'/,'&#39;') # IE bug
@ -892,7 +910,7 @@ If true, raw HTML is discarded from the output.
# Entity.new(entity_name) # Entity.new(entity_name)
Text.new('&#%d;' % [entity_name], false, nil, true) Text.new('&#%d;' % [entity_name], false, nil, true)
else else
Text.new('&%s;' % [entity_name]) Text.new('&%s;' % [entity_name], false, nil, true)
end end
end end

View file

@ -19,7 +19,7 @@
#++ #++
module MaRuKu module MaRuKu
Version = '0.5.6' Version = '0.5.7'
MarukuURL = 'http://maruku.rubyforge.org/' MarukuURL = 'http://maruku.rubyforge.org/'