Support for IE+MathPlayer.
Sync with latest Maruku.
This commit is contained in:
parent
1c05a94d1b
commit
488dd334f7
9 changed files with 74 additions and 28 deletions
|
@ -148,7 +148,7 @@ class ApplicationController < ActionController::Base
|
||||||
@response.headers['Content-Type'] = 'text/xml; charset=UTF-8'
|
@response.headers['Content-Type'] = 'text/xml; charset=UTF-8'
|
||||||
elsif %w(tex).include?(action_name)
|
elsif %w(tex).include?(action_name)
|
||||||
@response.headers['Content-Type'] = 'text/plain; charset=UTF-8'
|
@response.headers['Content-Type'] = 'text/plain; charset=UTF-8'
|
||||||
elsif Mime::Type.parse(@request.env["HTTP_ACCEPT"]).include?(Mime::XHTML)
|
elsif Mime::Type.parse(@request.env["HTTP_ACCEPT"]).include?(Mime::XHTML) or @request.env["USER_AGENT"] =~ /MathPlayer/
|
||||||
@response.headers['Content-Type'] = 'application/xhtml+xml; charset=UTF-8'
|
@response.headers['Content-Type'] = 'application/xhtml+xml; charset=UTF-8'
|
||||||
else
|
else
|
||||||
@response.headers['Content-Type'] = 'text/html; charset=UTF-8'
|
@response.headers['Content-Type'] = 'text/html; charset=UTF-8'
|
||||||
|
|
|
@ -42,14 +42,6 @@ Same thing as `html_math_engine`, only for PNG output.
|
||||||
module MaRuKu; module Out; module HTML
|
module MaRuKu; module Out; module HTML
|
||||||
|
|
||||||
|
|
||||||
def add_class_to(el, cl)
|
|
||||||
el.attributes['class'] =
|
|
||||||
if already = el.attributes['class']
|
|
||||||
already + " " + cl
|
|
||||||
else
|
|
||||||
cl
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Creates an xml Mathml document of self.math
|
# Creates an xml Mathml document of self.math
|
||||||
def render_mathml(kind, tex)
|
def render_mathml(kind, tex)
|
||||||
|
|
|
@ -205,8 +205,9 @@ class CharSourceStrscan
|
||||||
include SpanLevelParser
|
include SpanLevelParser
|
||||||
include MaRuKu::Strings
|
include MaRuKu::Strings
|
||||||
|
|
||||||
def initialize(s)
|
def initialize(s, parent=nil)
|
||||||
@s = StringScanner.new(s)
|
@s = StringScanner.new(s)
|
||||||
|
@parent = parent
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return current char as a FixNum (or nil).
|
# Return current char as a FixNum (or nil).
|
||||||
|
@ -273,9 +274,9 @@ end
|
||||||
|
|
||||||
|
|
||||||
class CharSourceDebug
|
class CharSourceDebug
|
||||||
def initialize(s)
|
def initialize(s, parent)
|
||||||
@a = CharSourceManual.new(s)
|
@a = CharSourceManual.new(s, parent)
|
||||||
@b = CharSourceStrscan.new(s)
|
@b = CharSourceStrscan.new(s, parent)
|
||||||
end
|
end
|
||||||
|
|
||||||
def method_missing(methodname, *args)
|
def method_missing(methodname, *args)
|
||||||
|
|
|
@ -127,6 +127,7 @@ Disabled by default because of security concerns.
|
||||||
result[:unresolved_references] << " #{v}"
|
result[:unresolved_references] << " #{v}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# $stderr.puts "Unresolved reference #{v.inspect} (avail: #{self.ald.keys.inspect})"
|
||||||
result[v.to_sym] = true
|
result[v.to_sym] = true
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|
|
@ -278,10 +278,10 @@ module MaRuKu; module In; module Markdown; module SpanLevelParser
|
||||||
end
|
end
|
||||||
|
|
||||||
def extension_meta(src, con, break_on_chars)
|
def extension_meta(src, con, break_on_chars)
|
||||||
if m = src.read_regexp(/(\w)+\:/)
|
if m = src.read_regexp(/([^:]+):/)
|
||||||
name = m[1]
|
name = m[1]
|
||||||
content = m[2]
|
|
||||||
al = read_attribute_list(src, con, break_on_chars)
|
al = read_attribute_list(src, con, break_on_chars)
|
||||||
|
# puts "#{name}=#{al.inspect}"
|
||||||
self.doc.ald[name] = al
|
self.doc.ald[name] = al
|
||||||
con.push md_ald(name, al)
|
con.push md_ald(name, al)
|
||||||
else
|
else
|
||||||
|
@ -624,6 +624,11 @@ module MaRuKu; module In; module Markdown; module SpanLevelParser
|
||||||
con.push_element md_im_image(alt_text, url, title)
|
con.push_element md_im_image(alt_text, url, title)
|
||||||
when ?[ # link ref
|
when ?[ # link ref
|
||||||
ref_id = read_ref_id(src,con)
|
ref_id = read_ref_id(src,con)
|
||||||
|
if ref_id.size == 0
|
||||||
|
ref_id = alt_text.to_s.downcase.gsub(' ','_')
|
||||||
|
else
|
||||||
|
ref_id = ref_id.downcase
|
||||||
|
end
|
||||||
con.push_element md_image(alt_text, ref_id)
|
con.push_element md_image(alt_text, ref_id)
|
||||||
else # no stuff
|
else # no stuff
|
||||||
con.push_elements children
|
con.push_elements children
|
||||||
|
|
|
@ -394,7 +394,9 @@ by Maruku, to have the same results in both HTML and LaTeX.
|
||||||
def source2html(source)
|
def source2html(source)
|
||||||
source = source.gsub(/&/,'&')
|
source = source.gsub(/&/,'&')
|
||||||
source = Text.normalize(source)
|
source = Text.normalize(source)
|
||||||
Text.new(source, true, nil, false )
|
source = source.gsub(/\'/,''') # IE bug
|
||||||
|
source = source.gsub(/'/,''') # IE bug
|
||||||
|
Text.new(source, true, nil, true )
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin maruku_doc
|
=begin maruku_doc
|
||||||
|
@ -437,7 +439,6 @@ and
|
||||||
|
|
||||||
lang = 'xml' if lang=='html'
|
lang = 'xml' if lang=='html'
|
||||||
|
|
||||||
|
|
||||||
use_syntax = get_setting :html_use_syntax
|
use_syntax = get_setting :html_use_syntax
|
||||||
|
|
||||||
element =
|
element =
|
||||||
|
@ -455,9 +456,17 @@ and
|
||||||
source = source.gsub(/\n*\Z/,'')
|
source = source.gsub(/\n*\Z/,'')
|
||||||
|
|
||||||
html = convertor.convert( source )
|
html = convertor.convert( source )
|
||||||
|
html = html.gsub(/\'/,''') # IE bug
|
||||||
|
html = html.gsub(/'/,''') # IE bug
|
||||||
|
# html = html.gsub(/&/,'&')
|
||||||
|
|
||||||
pre = Document.new(html, {:respect_whitespace =>:all}).root
|
code = Document.new(html, {:respect_whitespace =>:all}).root
|
||||||
pre.attributes['class'] = lang
|
code.name = 'code'
|
||||||
|
code.attributes['class'] = lang
|
||||||
|
code.attributes['lang'] = lang
|
||||||
|
|
||||||
|
pre = Element.new 'pre'
|
||||||
|
pre << code
|
||||||
pre
|
pre
|
||||||
rescue LoadError => e
|
rescue LoadError => e
|
||||||
maruku_error "Could not load package 'syntax'.\n"+
|
maruku_error "Could not load package 'syntax'.\n"+
|
||||||
|
@ -480,7 +489,7 @@ and
|
||||||
if color != Globals[:code_background_color]
|
if color != Globals[:code_background_color]
|
||||||
element.attributes['style'] = "background-color: #{color};"
|
element.attributes['style'] = "background-color: #{color};"
|
||||||
end
|
end
|
||||||
element
|
add_ws element
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin maruku_doc
|
=begin maruku_doc
|
||||||
|
@ -523,6 +532,10 @@ of the form `#ff00ff`.
|
||||||
|
|
||||||
text = Text.new(s, respect_ws=true, parent=nil, raw=true )
|
text = Text.new(s, respect_ws=true, parent=nil, raw=true )
|
||||||
|
|
||||||
|
if lang = self.attributes[:lang]
|
||||||
|
code.attributes['lang'] = lang
|
||||||
|
code.attributes['class'] = lang
|
||||||
|
end
|
||||||
code << text
|
code << text
|
||||||
pre
|
pre
|
||||||
end
|
end
|
||||||
|
@ -540,12 +553,40 @@ of the form `#ff00ff`.
|
||||||
pre
|
pre
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def add_class_to(el, cl)
|
||||||
|
el.attributes['class'] =
|
||||||
|
if already = el.attributes['class']
|
||||||
|
already + " " + cl
|
||||||
|
else
|
||||||
|
cl
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def add_class_to_link(a)
|
||||||
|
return # not ready yet
|
||||||
|
|
||||||
|
url = a.attributes['href']
|
||||||
|
return if not url
|
||||||
|
|
||||||
|
if url =~ /^#/
|
||||||
|
add_class_to(a, 'maruku-link-samedoc')
|
||||||
|
elsif url =~ /^http:/
|
||||||
|
add_class_to(a, 'maruku-link-external')
|
||||||
|
else
|
||||||
|
add_class_to(a, 'maruku-link-local')
|
||||||
|
end
|
||||||
|
|
||||||
|
# puts a.attributes['class']
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
def to_html_immediate_link
|
def to_html_immediate_link
|
||||||
a = create_html_element 'a'
|
a = create_html_element 'a'
|
||||||
url = self.url
|
url = self.url
|
||||||
text = url.gsub(/^mailto:/,'') # don't show mailto
|
text = url.gsub(/^mailto:/,'') # don't show mailto
|
||||||
a << Text.new(text)
|
a << Text.new(text)
|
||||||
a.attributes['href'] = url
|
a.attributes['href'] = url
|
||||||
|
add_class_to_link(a)
|
||||||
a
|
a
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -564,6 +605,8 @@ of the form `#ff00ff`.
|
||||||
tell_user "Not creating a link for ref_id = #{id.inspect}."
|
tell_user "Not creating a link for ref_id = #{id.inspect}."
|
||||||
return wrap_as_element('span')
|
return wrap_as_element('span')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# add_class_to_link(a)
|
||||||
return a
|
return a
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -623,7 +666,7 @@ of the form `#ff00ff`.
|
||||||
else
|
else
|
||||||
maruku_error"Could not find id = #{id.inspect} for\n #{self.inspect}"
|
maruku_error"Could not find id = #{id.inspect} for\n #{self.inspect}"
|
||||||
tell_user "Could not create image with ref_id = #{id.inspect};"+
|
tell_user "Could not create image with ref_id = #{id.inspect};"+
|
||||||
+" Using SPAN element as replacement."
|
" Using SPAN element as replacement."
|
||||||
return wrap_as_element('span')
|
return wrap_as_element('span')
|
||||||
end
|
end
|
||||||
return a
|
return a
|
||||||
|
|
|
@ -506,11 +506,15 @@ Otherwise, a standard `verbatim` environment is used.
|
||||||
id = self.ref_id
|
id = self.ref_id
|
||||||
ref = @doc.refs[id]
|
ref = @doc.refs[id]
|
||||||
if not ref
|
if not ref
|
||||||
$stderr.puts "Could not find id = '#{id}'"
|
maruku_error "Could not find ref #{id.inspect} for image.\n"+
|
||||||
|
"Available are: #{@docs.refs.keys.inspect}"
|
||||||
|
# $stderr.puts "Could not find id = '#{id}'"
|
||||||
""
|
""
|
||||||
else
|
else
|
||||||
url = ref[:url]
|
url = ref[:url]
|
||||||
"{\\bf Images not supported yet (#{latex_escape(url)})}"
|
$stderr.puts "Images not supported yet (#{url})"
|
||||||
|
# "{\\bf Images not supported yet (#{latex_escape(url)})}"
|
||||||
|
""
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -67,8 +67,8 @@ module MaRuKu; module Out; module Latex
|
||||||
|
|
||||||
# create hash @@entity_to_latex
|
# create hash @@entity_to_latex
|
||||||
def Latex.init_entity_table
|
def Latex.init_entity_table
|
||||||
$stderr.write "Creating entity table.."
|
# $stderr.write "Creating entity table.."
|
||||||
$stderr.flush
|
# $stderr.flush
|
||||||
doc = Document.new XML_TABLE
|
doc = Document.new XML_TABLE
|
||||||
doc.elements.each("//char") do |c|
|
doc.elements.each("//char") do |c|
|
||||||
num = c.attributes['num'].to_i
|
num = c.attributes['num'].to_i
|
||||||
|
@ -92,7 +92,7 @@ module MaRuKu; module Out; module Latex
|
||||||
ENTITY_TABLE[num] = e
|
ENTITY_TABLE[num] = e
|
||||||
ENTITY_TABLE[name] = e
|
ENTITY_TABLE[name] = e
|
||||||
end
|
end
|
||||||
$stderr.puts "..done."
|
# $stderr.puts "..done."
|
||||||
end
|
end
|
||||||
|
|
||||||
ENTITY_TABLE = {}
|
ENTITY_TABLE = {}
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
#++
|
#++
|
||||||
|
|
||||||
module MaRuKu
|
module MaRuKu
|
||||||
Version = '0.5.0'
|
Version = '0.5.1'
|
||||||
|
|
||||||
MarukuURL = 'http://maruku.rubyforge.org/'
|
MarukuURL = 'http://maruku.rubyforge.org/'
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue