Blahtex
Sync with latest Maruku. Pave the way for Blahtex (PNG-based math) support (from Ari Stern). (no visible functionality, yet, but that will come)
This commit is contained in:
parent
4e3aefd9d3
commit
c427807274
33 changed files with 610 additions and 101 deletions
1
vendor/plugins/maruku/lib/maruku/defaults.rb
vendored
1
vendor/plugins/maruku/lib/maruku/defaults.rb
vendored
|
@ -47,6 +47,7 @@ Globals = {
|
|||
|
||||
:latex_use_listings => false,
|
||||
:latex_cjk => false,
|
||||
:latex_cache_file => "blahtex_cache.pstore", # cache file for blahtex filter
|
||||
|
||||
:debug_keep_ials => false,
|
||||
:doc_prefix => ''
|
||||
|
|
|
@ -15,36 +15,34 @@ module MaRuKu; module Out; module HTML
|
|||
# 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")
|
||||
|
||||
|
||||
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 'dvipng -D #{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])
|
||||
|
||||
|
||||
cmd = "blahtex #{options} < #{tmp_in.path} > #{result_file}"
|
||||
$stderr.puts "$ #{cmd}"
|
||||
system cmd
|
||||
#$stderr.puts "$ #{cmd}"
|
||||
system cmd
|
||||
tmp_in.delete
|
||||
|
||||
end
|
||||
|
||||
result = nil
|
||||
f = File.open(result_file)
|
||||
result = f.read
|
||||
f.close
|
||||
|
||||
|
||||
result = File.read(result_file)
|
||||
if result.nil? || result.empty?
|
||||
raise "Blahtex error: empty output"
|
||||
end
|
||||
|
||||
doc = Document.new(result, {:respect_whitespace =>:all})
|
||||
png = doc.root.elements[1]
|
||||
if png.name != 'png'
|
||||
maruku_error "Blahtex error: \n#{doc}"
|
||||
return nil
|
||||
raise "Blahtex error: \n#{doc}"
|
||||
end
|
||||
depth = png.elements['depth'] || (raise "No depth element in:\n #{doc}")
|
||||
height = png.elements['height'] || (raise "No height element in:\n #{doc}")
|
||||
|
@ -56,19 +54,19 @@ module MaRuKu; module Out; module HTML
|
|||
|
||||
dir_url = MaRuKu::Globals[:html_png_url]
|
||||
return PNG.new("#{dir_url}#{md5}.png", depth, height)
|
||||
|
||||
rescue Exception => e
|
||||
maruku_error "Error: #{e}"
|
||||
end
|
||||
nil
|
||||
end
|
||||
|
||||
BlahtexCache = PStore.new("blahtex_cache.pstore")
|
||||
|
||||
|
||||
def convert_to_mathml_blahtex(kind, tex)
|
||||
@@BlahtexCache = PStore.new(MaRuKu::Globals[:latex_cache_file])
|
||||
|
||||
begin
|
||||
BlahtexCache.transaction do
|
||||
if BlahtexCache[tex].nil?
|
||||
@@BlahtexCache.transaction do
|
||||
if @@BlahtexCache[tex].nil?
|
||||
tmp_in = Tempfile.new('maruku_blahtex')
|
||||
f = tmp_in.open
|
||||
f.write tex
|
||||
|
@ -77,7 +75,7 @@ module MaRuKu; module Out; module HTML
|
|||
|
||||
options = "--mathml"
|
||||
cmd = "blahtex #{options} < #{tmp_in.path} > #{tmp_out.path}"
|
||||
$stderr.puts "$ #{cmd}"
|
||||
#$stderr.puts "$ #{cmd}"
|
||||
system cmd
|
||||
tmp_in.delete
|
||||
|
||||
|
@ -85,10 +83,10 @@ module MaRuKu; module Out; module HTML
|
|||
File.open(tmp_out.path) do |f| result=f.read end
|
||||
puts result
|
||||
|
||||
BlahtexCache[tex] = result
|
||||
@@BlahtexCache[tex] = result
|
||||
end
|
||||
|
||||
blahtex = BlahtexCache[tex]
|
||||
blahtex = @@BlahtexCache[tex]
|
||||
doc = Document.new(blahtex, {:respect_whitespace =>:all})
|
||||
mathml = doc.root.elements['mathml']
|
||||
if not mathml
|
||||
|
|
|
@ -337,7 +337,7 @@ module MaRuKu; module In; module Markdown; module BlockLevelParser
|
|||
|
||||
# puts "id =_#{id}_; text=_#{text}_ indent=#{indentation}"
|
||||
|
||||
break_list = [:footnote_text]
|
||||
break_list = [:footnote_text, :ref_definition, :definition, :abbreviation]
|
||||
item_type = :footnote_text
|
||||
lines, want_my_paragraph =
|
||||
read_indented_content(src,indentation, break_list, item_type)
|
||||
|
@ -471,9 +471,10 @@ module MaRuKu; module In; module Markdown; module BlockLevelParser
|
|||
def read_ref_definition(src, out)
|
||||
line = src.shift_line
|
||||
|
||||
|
||||
# if link is incomplete, shift next line
|
||||
if src.cur_line && (src.cur_line.md_type != :ref_definition) &&
|
||||
([1,2,3].include? number_of_leading_spaces(src.cur_line) )
|
||||
if src.cur_line && !([:footnote_text, :ref_definition, :definition, :abbreviation].include? src.cur_line.md_type) &&
|
||||
([1,2,3].include? number_of_leading_spaces(src.cur_line) )
|
||||
line += " "+ src.shift_line
|
||||
end
|
||||
|
||||
|
|
|
@ -94,6 +94,7 @@ module MaRuKu; module Strings
|
|||
# *[HTML]: Hyper Text Markup Language
|
||||
Abbreviation = %r{
|
||||
^ # begin of line
|
||||
[ ]{0,3} # up to 3 spaces
|
||||
\* # one asterisk
|
||||
\[ # opening bracket
|
||||
([^\]]+) # any non-closing bracket: id = $1
|
||||
|
@ -106,7 +107,9 @@ module MaRuKu; module Strings
|
|||
}x
|
||||
|
||||
FootnoteText = %r{
|
||||
^\s*\[(\^.+)\]: # id = $1 (including '^')
|
||||
^ # begin of line
|
||||
[ ]{0,3} # up to 3 spaces
|
||||
\[(\^.+)\]: # id = $1 (including '^')
|
||||
\s*(\S.*)?$ # text = $2 (not obb.)
|
||||
}x
|
||||
|
||||
|
@ -115,7 +118,7 @@ module MaRuKu; module Strings
|
|||
LinkRegex = %r{
|
||||
^[ ]{0,3}\[([^\[\]]+)\]: # id = $1
|
||||
[ ]*
|
||||
<?(\S+)>? # url = $2
|
||||
<?([^>\s]+)>? # url = $2
|
||||
[ ]*
|
||||
(?:# Titles are delimited by "quotes" or (parens).
|
||||
["(']
|
||||
|
|
|
@ -188,6 +188,7 @@ Example:
|
|||
|
||||
=end
|
||||
|
||||
METAS = %w{description keywords author revised}
|
||||
|
||||
# Render to a complete HTML document (returns a REXML document tree)
|
||||
def to_html_document_tree
|
||||
|
@ -209,7 +210,25 @@ Example:
|
|||
# me.attributes['content'] = 'text/html;charset=utf-8'
|
||||
me.attributes['content'] = 'application/xhtml+xml;charset=utf-8'
|
||||
|
||||
METAS.each do |m|
|
||||
if value = self.attributes[m.to_sym]
|
||||
meta = Element.new 'meta', head
|
||||
meta.attributes['name'] = m
|
||||
meta.attributes['content'] = value.to_s
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
self.attributes.each do |k,v|
|
||||
if k.to_s =~ /\Ameta-(.*)\Z/
|
||||
meta = Element.new 'meta', head
|
||||
meta.attributes['name'] = $1
|
||||
meta.attributes['content'] = v.to_s
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
# Create title element
|
||||
doc_title = self.attributes[:title] || self.attributes[:subject] || ""
|
||||
title = Element.new 'title', head
|
||||
|
@ -312,7 +331,8 @@ Example:
|
|||
li.insert_after(li.children.last, a)
|
||||
ol << li
|
||||
else
|
||||
maruku_error"Could not find footnote '#{fid}'"
|
||||
maruku_error "Could not find footnote id '#{fid}' among ["+
|
||||
self.footnotes.keys.map{|s|"'"+s+"'"}.join(', ')+"]."
|
||||
end
|
||||
end
|
||||
div << ol
|
||||
|
@ -827,10 +847,21 @@ If true, raw HTML is discarded from the output.
|
|||
# save the order of used footnotes
|
||||
order = @doc.footnotes_order
|
||||
|
||||
if order.include? id
|
||||
# footnote has already been used
|
||||
return []
|
||||
end
|
||||
|
||||
if not @doc.footnotes[id]
|
||||
return []
|
||||
end
|
||||
|
||||
# take next number
|
||||
order << id
|
||||
num = order.size;
|
||||
|
||||
#num = order.size;
|
||||
num = order.index(id) + 1
|
||||
|
||||
sup = Element.new 'sup'
|
||||
sup.attributes['id'] = "#{get_setting(:doc_prefix)}fnref:#{num}"
|
||||
a = Element.new 'a'
|
||||
|
|
|
@ -46,7 +46,7 @@ module MaRuKu; module Strings
|
|||
#
|
||||
def parse_email_headers(s)
|
||||
keys={}
|
||||
match = (s =~ /((\w[\w\s]+: .*\n)+)\n/)
|
||||
match = (s =~ /\A((\w[\w\s\_\-]+: .*\n)+)\s*\n/)
|
||||
if match != 0
|
||||
keys[:data] = s
|
||||
else
|
||||
|
|
2
vendor/plugins/maruku/lib/maruku/version.rb
vendored
2
vendor/plugins/maruku/lib/maruku/version.rb
vendored
|
@ -19,7 +19,7 @@
|
|||
#++
|
||||
|
||||
module MaRuKu
|
||||
Version = '0.5.8'
|
||||
Version = '0.5.9'
|
||||
|
||||
MarukuURL = 'http://maruku.rubyforge.org/'
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue