Merge branch 'bzr/golem' of /Users/distler/Sites/code/instiki

This commit is contained in:
Jacques Distler 2010-06-19 03:03:36 -05:00
commit 4c4f7a7b82
5 changed files with 29 additions and 22 deletions

View file

@ -2313,7 +2313,7 @@ end
"'" => ''', "'" => ''',
'"' => '"', '"' => '"',
} }
TO_ESCAPE_PATTERN = Regexp.union(TO_ESCAPE.keys) TO_ESCAPE_PATTERN = Regexp.union(*TO_ESCAPE.keys)
def escapeHTML def escapeHTML
self.gsub(TO_ESCAPE_PATTERN){|m| TO_ESCAPE[m]} self.gsub(TO_ESCAPE_PATTERN){|m| TO_ESCAPE[m]}

View file

@ -1,14 +1,14 @@
module MaRuKu; module Out; module HTML module MaRuKu; module Out; module HTML
require 'maruku/string_utils'
def convert_to_mathml_none(kind, tex) def convert_to_mathml_none(kind, tex)
# You can: either return a REXML::Element # You can: either return a REXML::Element
# return Element.new 'div' # return Element.new 'div'
# or return an empty array on error # or return an empty array on error
# return [] # return []
# or have a string parsed by REXML: # or have a string parsed by REXML:
mathml = "<code>#{tex.gsub( /&/, "&amp;" ). mathml = "<code>#{html_escape(tex)}</code>"
gsub( /</, "&lt;" ).gsub( />/, "&gt;" ).
gsub(/'/, "&#39;" ).gsub(/"/, "&quot;" )}</code>"
return Document.new(mathml).root return Document.new(mathml).root
end end

View file

@ -8,20 +8,13 @@ begin
rescue LoadError rescue LoadError
$rexml_new_version = false $rexml_new_version = false
end end
require 'maruku/string_utils'
class MDDocument class MDDocument
def s5_theme def s5_theme
html_escape(self.attributes[:slide_theme] || "default") html_escape(self.attributes[:slide_theme] || "default")
end end
def html_escape(string)
string.gsub( /&/, "&amp;" ).
gsub( /</, "&lt;" ).
gsub( />/, "&gt;" ).
gsub( /'/, "&#39;" ).
gsub( /"/, "&quot;" )
end
# 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_s5(context={}) def to_s5(context={})

View file

@ -74,9 +74,7 @@ module MaRuKu; module Out; module HTML
div.write(xml,indent,transitive=true,ie_hack) div.write(xml,indent,transitive=true,ie_hack)
end end
xml.gsub!(/\A<dummy>\s*/,'') xml.gsub!(/\A<dummy>\s*|\s*<\/dummy>\Z|\A<dummy\s*\/>/,'')
xml.gsub!(/\s*<\/dummy>\Z/,'')
xml.gsub!(/\A<dummy\s*\/>/,'')
xml xml
end end
@ -507,8 +505,7 @@ by Maruku, to have the same results in both HTML and LaTeX.
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.gsub!(/\&apos;|'/,'&#39;') # IE bug
source = source.gsub(/'/,'&#39;') # IE bug
Text.new(source, true, nil, true ) Text.new(source, true, nil, true )
end end
@ -571,8 +568,7 @@ and
source = source.gsub(/\n*\Z/,'') source = source.gsub(/\n*\Z/,'')
html = convertor.convert( source ) html = convertor.convert( source )
html = html.gsub(/\&apos;/,'&#39;') # IE bug html.gsub!(/\&apos;|'/,'&#39;') # IE bug
html = html.gsub(/'/,'&#39;') # IE bug
# html = html.gsub(/&/,'&amp;') # html = html.gsub(/&/,'&amp;')
code = Document.new(html, {:respect_whitespace =>:all}).root code = Document.new(html, {:respect_whitespace =>:all}).root
@ -633,9 +629,7 @@ of the form `#ff00ff`.
s = source s = source
# s = s.gsub(/&/,'&amp;') # s = s.gsub(/&/,'&amp;')
s = Text.normalize(s) s = Text.normalize(s).gsub(/\&apos;|'/,'&#39;') # IE bug
s = s.gsub(/\&apos;/,'&#39;') # IE bug
s = s.gsub(/'/,'&#39;') # IE bug
if get_setting(:code_show_spaces) if get_setting(:code_show_spaces)
# 187 = raquo # 187 = raquo

View file

@ -141,6 +141,26 @@ module MaRuKu
return s return s
end end
#--
MARUKU_HTML_ESCAPE = {
'&' => '&amp;',
'<' => '&lt;',
'>' => '&gt;',
"'" => '&#39;',
'"' => '&quot;',
}
MARUKU_HTML_ESCAPE_PATTERN = Regexp.union(*MARUKU_HTML_ESCAPE.keys)
#++
# HTML-escapes a string.
#
# @param str [String]
# @return [String]
def html_escape(string)
string.gsub(MARUKU_HTML_ESCAPE_PATTERN){|m| MARUKU_HTML_ESCAPE[m]}
end
# Escapes a string so that it can be safely used in a Bourne shell command line. # Escapes a string so that it can be safely used in a Bourne shell command line.
# #
# Note that a resulted string should be used unquoted # Note that a resulted string should be used unquoted