Sync with latest Maruku
Contains Ari Stern's additions for Blahtex support.
This commit is contained in:
parent
e1c7d035c9
commit
37aff87d71
100 changed files with 715 additions and 2848 deletions
|
@ -10,23 +10,24 @@ module MaRuKu; module Out; module HTML
|
|||
|
||||
def convert_to_png_blahtex(kind, tex)
|
||||
begin
|
||||
FileUtils::mkdir_p MaRuKu::Globals[:html_png_dir]
|
||||
FileUtils::mkdir_p get_setting(:html_png_dir)
|
||||
|
||||
# first, we check whether this image has already been processed
|
||||
md5sum = Digest::MD5.hexdigest(tex+" params: ")
|
||||
result_file = File.join(MaRuKu::Globals[:html_png_dir], md5sum+".txt")
|
||||
result_file = File.join(get_setting(:html_png_dir), md5sum+".txt")
|
||||
|
||||
if not File.exists?(result_file)
|
||||
tmp_in = Tempfile.new('maruku_blahtex')
|
||||
f = tmp_in.open
|
||||
f = tmp_in.open
|
||||
f.write tex
|
||||
f.close
|
||||
|
||||
resolution = get_setting(:html_png_resolution)
|
||||
|
||||
options = "--png --use-preview-package --shell-dvipng '/usr/bin/dvipng -D #{resolution}' "
|
||||
options += ("--temp-directory '%s' " % MaRuKu::Globals[:html_png_dir])
|
||||
options += ("--png-directory '%s'" % MaRuKu::Globals[:html_png_dir])
|
||||
options = "--png --use-preview-package --shell-dvipng 'dvipng -D #{resolution}' "
|
||||
options += "--displaymath " if kind == :equation
|
||||
options += ("--temp-directory '%s' " % get_setting(:html_png_dir))
|
||||
options += ("--png-directory '%s'" % get_setting(:html_png_dir))
|
||||
|
||||
cmd = "blahtex #{options} < #{tmp_in.path} > #{result_file}"
|
||||
#$stderr.puts "$ #{cmd}"
|
||||
|
@ -52,7 +53,7 @@ module MaRuKu; module Out; module HTML
|
|||
height = height.text.to_f # XXX check != 0
|
||||
md5 = md5.text
|
||||
|
||||
dir_url = MaRuKu::Globals[:html_png_url]
|
||||
dir_url = get_setting(:html_png_url)
|
||||
return PNG.new("#{dir_url}#{md5}.png", depth, height)
|
||||
rescue Exception => e
|
||||
maruku_error "Error: #{e}"
|
||||
|
@ -62,7 +63,7 @@ module MaRuKu; module Out; module HTML
|
|||
|
||||
|
||||
def convert_to_mathml_blahtex(kind, tex)
|
||||
@@BlahtexCache = PStore.new(MaRuKu::Globals[:latex_cache_file])
|
||||
@@BlahtexCache = PStore.new(get_setting(:latex_cache_file))
|
||||
|
||||
begin
|
||||
@@BlahtexCache.transaction do
|
||||
|
|
|
@ -90,7 +90,7 @@ module MaRuKu; module Out; module HTML
|
|||
img = Element.new 'img'
|
||||
img.attributes['src'] = src
|
||||
img.attributes['style'] = style
|
||||
img.attributes['alt'] = "equation"
|
||||
img.attributes['alt'] = "$#{self.math.strip}$"
|
||||
img
|
||||
end
|
||||
|
||||
|
@ -144,7 +144,7 @@ module MaRuKu; module Out; module HTML
|
|||
|
||||
source_div = Element.new 'div'
|
||||
add_class_to(source_div, 'maruku-eq-tex')
|
||||
code = convert_to_mathml_none(:equation, self.math)
|
||||
code = convert_to_mathml_none(:equation, self.math.strip)
|
||||
code.attributes['style'] = 'display: none'
|
||||
source_div << code
|
||||
div << source_div
|
||||
|
|
|
@ -185,15 +185,27 @@ module MaRuKu; module In; module Markdown; module SpanLevelParser
|
|||
maruku_recover "Threating as literal", src, con
|
||||
con.push_char src.shift_char
|
||||
else
|
||||
follows = src.cur_chars(4)
|
||||
if follows =~ /^\_\_\_[^\s\_]/
|
||||
con.push_element read_emstrong(src,'___')
|
||||
elsif follows =~ /^\_\_[^\s\_]/
|
||||
con.push_element read_strong(src,'__')
|
||||
elsif follows =~ /^\_[^\s\_]/
|
||||
con.push_element read_em(src,'_')
|
||||
else # _ is just a normal char
|
||||
con.push_char src.shift_char
|
||||
# we don't want "mod_ruby" to start an emphasis
|
||||
# so we start one only if
|
||||
# 1) there's nothing else in the span (first char)
|
||||
# or 2) the last char was a space
|
||||
# or 3) the current string is empty
|
||||
#if con.elements.empty? ||
|
||||
if (con.cur_string =~ /\s\Z/) || (con.cur_string.size == 0)
|
||||
# also, we check the next characters
|
||||
follows = src.cur_chars(4)
|
||||
if follows =~ /^\_\_\_[^\s\_]/
|
||||
con.push_element read_emstrong(src,'___')
|
||||
elsif follows =~ /^\_\_[^\s\_]/
|
||||
con.push_element read_strong(src,'__')
|
||||
elsif follows =~ /^\_[^\s\_]/
|
||||
con.push_element read_em(src,'_')
|
||||
else # _ is just a normal char
|
||||
con.push_char src.shift_char
|
||||
end
|
||||
else
|
||||
# _ is just a normal char
|
||||
con.push_char src.shift_char
|
||||
end
|
||||
end
|
||||
when ?{ # extension
|
||||
|
@ -696,6 +708,7 @@ module MaRuKu; module In; module Markdown; module SpanLevelParser
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
def push_string_if_present
|
||||
if @cur_string.size > 0
|
||||
@elements << @cur_string
|
||||
|
|
|
@ -106,6 +106,8 @@ module MaRuKu; module Tests
|
|||
["_b_", [md_em('b')], 'Emphasis 7'],
|
||||
["_b_ _c_", [md_em('b'),' ',md_em('c')], 'Emphasis 8'],
|
||||
["_b__c_", [md_em('b'),md_em('c')], 'Emphasis 9'],
|
||||
# underscores in word
|
||||
["mod_ruby", ['mod_ruby'], 'Word with underscore'],
|
||||
# strong
|
||||
["**a*", :throw, 'Unclosed double ** 2'],
|
||||
["\\**a*", ['*', md_em('a')], 'Escaping of *'],
|
||||
|
@ -116,7 +118,8 @@ module MaRuKu; module Tests
|
|||
["**b****c**", [md_strong('b'),md_strong('c')], 'Emphasis 9'],
|
||||
# strong (with underscore)
|
||||
["__a_", :throw, 'Unclosed double __ 2'],
|
||||
["\\__a_", ['_', md_em('a')], 'Escaping of _'],
|
||||
|
||||
# ["\\__a_", ['_', md_em('a')], 'Escaping of _'],
|
||||
["a __b__ ", ['a ', md_strong('b')], 'Emphasis 1'],
|
||||
["a __b__", ['a ', md_strong('b')], 'Emphasis 2'],
|
||||
["a __ b", ['a __ b'], 'Emphasis 3'],
|
||||
|
@ -133,7 +136,7 @@ module MaRuKu; module Tests
|
|||
["a *** b***", :throw, 'Unclosed emphasis'],
|
||||
# same with underscores
|
||||
["___a__", :throw, 'Unclosed triple *** '],
|
||||
["\\___a__", ['_', md_strong('a')], 'Escaping of *'],
|
||||
# ["\\___a__", ['_', md_strong('a')], 'Escaping of _'],
|
||||
["a ___b___ ", ['a ', md_emstrong('b')], 'Strong elements'],
|
||||
["a ___b___", ['a ', md_emstrong('b')]],
|
||||
["a ___ b", ['a ___ b']],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue