Support for IE+MathPlayer.

Sync with latest Maruku.
This commit is contained in:
Jacques Distler 2007-01-24 10:53:10 -06:00
parent 1c05a94d1b
commit 488dd334f7
9 changed files with 74 additions and 28 deletions

View file

@ -148,7 +148,7 @@ class ApplicationController < ActionController::Base
@response.headers['Content-Type'] = 'text/xml; charset=UTF-8'
elsif %w(tex).include?(action_name)
@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'
else
@response.headers['Content-Type'] = 'text/html; charset=UTF-8'

View file

@ -42,14 +42,6 @@ Same thing as `html_math_engine`, only for PNG output.
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
def render_mathml(kind, tex)

View file

@ -205,8 +205,9 @@ class CharSourceStrscan
include SpanLevelParser
include MaRuKu::Strings
def initialize(s)
def initialize(s, parent=nil)
@s = StringScanner.new(s)
@parent = parent
end
# Return current char as a FixNum (or nil).
@ -273,9 +274,9 @@ end
class CharSourceDebug
def initialize(s)
@a = CharSourceManual.new(s)
@b = CharSourceStrscan.new(s)
def initialize(s, parent)
@a = CharSourceManual.new(s, parent)
@b = CharSourceStrscan.new(s, parent)
end
def method_missing(methodname, *args)

View file

@ -127,6 +127,7 @@ Disabled by default because of security concerns.
result[:unresolved_references] << " #{v}"
end
# $stderr.puts "Unresolved reference #{v.inspect} (avail: #{self.ald.keys.inspect})"
result[v.to_sym] = true
end
else

View file

@ -278,10 +278,10 @@ module MaRuKu; module In; module Markdown; module SpanLevelParser
end
def extension_meta(src, con, break_on_chars)
if m = src.read_regexp(/(\w)+\:/)
if m = src.read_regexp(/([^:]+):/)
name = m[1]
content = m[2]
al = read_attribute_list(src, con, break_on_chars)
# puts "#{name}=#{al.inspect}"
self.doc.ald[name] = al
con.push md_ald(name, al)
else
@ -624,6 +624,11 @@ module MaRuKu; module In; module Markdown; module SpanLevelParser
con.push_element md_im_image(alt_text, url, title)
when ?[ # link ref
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)
else # no stuff
con.push_elements children

View file

@ -394,7 +394,9 @@ by Maruku, to have the same results in both HTML and LaTeX.
def source2html(source)
source = source.gsub(/&/,'&amp;')
source = Text.normalize(source)
Text.new(source, true, nil, false )
source = source.gsub(/\&apos;/,'&#39;') # IE bug
source = source.gsub(/'/,'&#39;') # IE bug
Text.new(source, true, nil, true )
end
=begin maruku_doc
@ -437,7 +439,6 @@ and
lang = 'xml' if lang=='html'
use_syntax = get_setting :html_use_syntax
element =
@ -455,9 +456,17 @@ and
source = source.gsub(/\n*\Z/,'')
html = convertor.convert( source )
pre = Document.new(html, {:respect_whitespace =>:all}).root
pre.attributes['class'] = lang
html = html.gsub(/\&apos;/,'&#39;') # IE bug
html = html.gsub(/'/,'&#39;') # IE bug
# html = html.gsub(/&/,'&amp;')
code = Document.new(html, {:respect_whitespace =>:all}).root
code.name = 'code'
code.attributes['class'] = lang
code.attributes['lang'] = lang
pre = Element.new 'pre'
pre << code
pre
rescue LoadError => e
maruku_error "Could not load package 'syntax'.\n"+
@ -480,7 +489,7 @@ and
if color != Globals[:code_background_color]
element.attributes['style'] = "background-color: #{color};"
end
element
add_ws element
end
=begin maruku_doc
@ -523,6 +532,10 @@ of the form `#ff00ff`.
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
pre
end
@ -540,12 +553,40 @@ of the form `#ff00ff`.
pre
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
a = create_html_element 'a'
url = self.url
text = url.gsub(/^mailto:/,'') # don't show mailto
a << Text.new(text)
a.attributes['href'] = url
add_class_to_link(a)
a
end
@ -564,6 +605,8 @@ of the form `#ff00ff`.
tell_user "Not creating a link for ref_id = #{id.inspect}."
return wrap_as_element('span')
end
# add_class_to_link(a)
return a
end
@ -623,7 +666,7 @@ of the form `#ff00ff`.
else
maruku_error"Could not find id = #{id.inspect} for\n #{self.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')
end
return a

View file

@ -506,11 +506,15 @@ Otherwise, a standard `verbatim` environment is used.
id = self.ref_id
ref = @doc.refs[id]
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
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

View file

@ -67,8 +67,8 @@ module MaRuKu; module Out; module Latex
# create hash @@entity_to_latex
def Latex.init_entity_table
$stderr.write "Creating entity table.."
$stderr.flush
# $stderr.write "Creating entity table.."
# $stderr.flush
doc = Document.new XML_TABLE
doc.elements.each("//char") do |c|
num = c.attributes['num'].to_i
@ -92,7 +92,7 @@ module MaRuKu; module Out; module Latex
ENTITY_TABLE[num] = e
ENTITY_TABLE[name] = e
end
$stderr.puts "..done."
# $stderr.puts "..done."
end
ENTITY_TABLE = {}

View file

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