Sync with latest Maruku.
Finally able to ditch BlueCloth completely.
This commit is contained in:
parent
0556f43180
commit
ff63e894b2
18 changed files with 393 additions and 1249 deletions
|
@ -1,12 +1,14 @@
|
||||||
<h3>Markdown formatting tips (<a target="_new" href="http://daringfireball.net/projects/markdown/syntax">advanced</a>)</h3>
|
<h3>Markdown formatting tips (<a target="_new" href="http://daringfireball.net/projects/markdown/syntax">basics</a>, <a target="_new" href="http://maruku.rubyforge.org/#extra">extended syntax</a>, <a target="_new" href="http://maruku.rubyforge.org/proposal.html">metadata</a>)</h3>
|
||||||
<table cellspacing="0" cellpadding="0">
|
<table cellspacing="0" cellpadding="0">
|
||||||
<tr><td>_your text_</td><td class="arrow">→</td><td><em>your text</em></td></tr>
|
<tr><td>_your text_</td><td class="arrow">→</td><td><em>your text</em></td></tr>
|
||||||
<tr><td>**your text**</td><td class="arrow">→</td><td><strong>your text</strong></td></tr>
|
<tr><td>**your text**</td><td class="arrow">→</td><td><strong>your text</strong></td></tr>
|
||||||
<tr><td>`my code`</td><td class="arrow">→</td><td><code>my code</code></td></tr>
|
<tr><td>`my code`</td><td class="arrow">→</td><td><code>my code</code></td></tr>
|
||||||
<tr><td>* Bulleted list<br />* Second item</td><td class="arrow">→</td><td>• Bulleted list<br />• Second item</td></tr>
|
<tr><td>* Bulleted list<br />* Second item</td><td class="arrow">→</td><td>• Bulleted list<br />• Second item</td></tr>
|
||||||
<tr><td>1. Numbered list<br />1. Second item</td><td class="arrow">→</td><td>1. Numbered list<br />2. Second item</td></tr>
|
<tr><td>1. Numbered list<br />1. Second item</td><td class="arrow">→</td><td>1. Numbered list<br />2. Second item</td></tr>
|
||||||
|
<tr><td>Definition list<br />: is useful</td><td class="arrow">→</td><td><dl style="display:inline"><dt>Definition list</dt><dd>is useful</dd></dl></td></tr>
|
||||||
<tr><td>[link name](URL)</td><td class="arrow">→</td><td><a href="URL">link name</a></td></tr>
|
<tr><td>[link name](URL)</td><td class="arrow">→</td><td><a href="URL">link name</a></td></tr>
|
||||||
|
<tr><td>![Alt text](URL)</td><td class="arrow">→</td><td>Image</td></tr>
|
||||||
|
<tr><td>## Header ##<br />### Subheader ###<br />#### Etc. ####</td><td class="arrow">→</td><td><b><span style="font-size:1.2em">Header</span><br /><span style="font-size:1.1em">Subheader</span><br /><span style="font-size:1em">Etc.</span></b></td></tr>
|
||||||
<tr><td>***</td><td class="arrow">→</td><td>Horizontal ruler</td></tr>
|
<tr><td>***</td><td class="arrow">→</td><td>Horizontal ruler</td></tr>
|
||||||
<tr><td><http://url><br /><email@add.com></td><td class="arrow">→</td><td>Auto-linked</td></tr>
|
<tr><td><http://url><br /><email@add.com></td><td class="arrow">→</td><td>Auto-linked</td></tr>
|
||||||
<tr><td>![Alt text](URL)</td><td class="arrow">→</td><td>Image</td></tr>
|
|
||||||
</table>
|
</table>
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -35,8 +35,8 @@ module Engines
|
||||||
|
|
||||||
class Markdown < AbstractEngine
|
class Markdown < AbstractEngine
|
||||||
def mask
|
def mask
|
||||||
require_dependency 'bluecloth_tweaked'
|
require_dependency 'maruku'
|
||||||
BlueCloth.new(@content, @content.options[:engine_opts]).to_html
|
Maruku.new(@content.delete("\r"), {:math_enabled => false}).to_html
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ module Engines
|
||||||
def mask
|
def mask
|
||||||
require_dependency 'maruku'
|
require_dependency 'maruku'
|
||||||
require_dependency 'maruku/ext/math'
|
require_dependency 'maruku/ext/math'
|
||||||
Maruku.new(@content.delete("\r")).to_html
|
Maruku.new(@content.delete("\r"), {:math_enabled => true}).to_html
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -192,9 +192,10 @@ module MaRuKu; module In; module Markdown; module SpanLevelParser
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# We need a helper
|
||||||
|
def is_ial(e); e.kind_of? MDElement and e.node_type == :ial end
|
||||||
|
|
||||||
def merge_ial(elements, src, con)
|
def merge_ial(elements, src, con)
|
||||||
# We need a helper
|
|
||||||
def is_ial(e); e.kind_of? MDElement and e.node_type == :ial end
|
|
||||||
|
|
||||||
# Apply each IAL to the element before
|
# Apply each IAL to the element before
|
||||||
elements.each_with_index do |e, i|
|
elements.each_with_index do |e, i|
|
||||||
|
|
30
vendor/plugins/maruku/lib/maruku/ext/math.rb
vendored
30
vendor/plugins/maruku/lib/maruku/ext/math.rb
vendored
|
@ -9,3 +9,33 @@ require 'maruku/ext/math/mathml_engines/none'
|
||||||
require 'maruku/ext/math/mathml_engines/ritex'
|
require 'maruku/ext/math/mathml_engines/ritex'
|
||||||
require 'maruku/ext/math/mathml_engines/itex2mml'
|
require 'maruku/ext/math/mathml_engines/itex2mml'
|
||||||
require 'maruku/ext/math/mathml_engines/blahtex'
|
require 'maruku/ext/math/mathml_engines/blahtex'
|
||||||
|
|
||||||
|
|
||||||
|
=begin maruku_doc
|
||||||
|
Attribute: math_enabled
|
||||||
|
Scope: global, document
|
||||||
|
Summary: Enables parsing of LaTeX math
|
||||||
|
|
||||||
|
To explicitly disable the math parsing:
|
||||||
|
|
||||||
|
Maruku.new(string, {:math_enabled => false})
|
||||||
|
{:ruby}
|
||||||
|
|
||||||
|
=end
|
||||||
|
|
||||||
|
MaRuKu::Globals[:math_enabled] = true
|
||||||
|
|
||||||
|
|
||||||
|
=begin maruku_doc
|
||||||
|
Attribute: math_numbered
|
||||||
|
Scope: global, document
|
||||||
|
Summary: Math openings which should be numerated
|
||||||
|
|
||||||
|
Array containing any of `'\\['`, `'\\begin{equation}'`, `'$$'`.
|
||||||
|
|
||||||
|
MaRuKu::Globals[math_numbered] = ['\\[']
|
||||||
|
|
||||||
|
=end
|
||||||
|
|
||||||
|
|
||||||
|
MaRuKu::Globals[:math_numbered] = []
|
||||||
|
|
|
@ -4,7 +4,7 @@ module MaRuKu; class MDElement
|
||||||
self.md_el(:inline_math, [], meta={:math=>math})
|
self.md_el(:inline_math, [], meta={:math=>math})
|
||||||
end
|
end
|
||||||
|
|
||||||
def md_equation(math, label=nil)
|
def md_equation(math, label, numerate)
|
||||||
reglabel= /\\label\{(\w+)\}/
|
reglabel= /\\label\{(\w+)\}/
|
||||||
if math =~ reglabel
|
if math =~ reglabel
|
||||||
label = $1
|
label = $1
|
||||||
|
@ -12,9 +12,10 @@ module MaRuKu; class MDElement
|
||||||
end
|
end
|
||||||
# puts "Found label = #{label} math #{math.inspect} "
|
# puts "Found label = #{label} math #{math.inspect} "
|
||||||
num = nil
|
num = nil
|
||||||
if label && @doc #take number
|
if (label || numerate) && @doc #take number
|
||||||
@doc.eqid2eq ||= {}
|
@doc.eqid2eq ||= {}
|
||||||
num = @doc.eqid2eq.size + 1
|
num = @doc.eqid2eq.size + 1
|
||||||
|
label = "eq#{num}" if not label # FIXME do id for document
|
||||||
end
|
end
|
||||||
e = self.md_el(:equation, [], meta={:math=>math, :label=>label,:num=>num})
|
e = self.md_el(:equation, [], meta={:math=>math, :label=>label,:num=>num})
|
||||||
if label && @doc #take number
|
if label && @doc #take number
|
||||||
|
|
139
vendor/plugins/maruku/lib/maruku/ext/math/parsing.rb
vendored
139
vendor/plugins/maruku/lib/maruku/ext/math/parsing.rb
vendored
|
@ -1,70 +1,90 @@
|
||||||
module MaRuKu
|
module MaRuKu
|
||||||
|
|
||||||
class MDDocument
|
class MDDocument
|
||||||
# Hash equation id (String) to equation element (MDElement)
|
# Hash equation id (String) to equation element (MDElement)
|
||||||
attr_accessor :eqid2eq
|
attr_accessor :eqid2eq
|
||||||
|
|
||||||
|
def is_math_enabled?
|
||||||
|
get_setting :math_enabled
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# At least one slash inside
|
|
||||||
#RegInlineMath1 = /\$([^\$]*[\\][^\$]*)\$/
|
|
||||||
# No spaces around the delimiters
|
|
||||||
#RegInlineMath2 = /\$([^\s\$](?:[^\$]*[^\s\$])?)\$/
|
|
||||||
#RegInlineMath = Regexp::union(RegInlineMath1,RegInlineMath2)
|
|
||||||
|
|
||||||
# Everything goes; takes care of escaping the "\$" inside the expression
|
# Everything goes; takes care of escaping the "\$" inside the expression
|
||||||
RegInlineMath = /\${1}((?:[^\$]|\\\$)+)\$/
|
RegInlineMath = /\${1}((?:[^\$]|\\\$)+)\$/
|
||||||
|
|
||||||
MaRuKu::In::Markdown::
|
MaRuKu::In::Markdown::register_span_extension(
|
||||||
register_span_extension(:chars => ?$, :regexp => RegInlineMath) do
|
:chars => ?$,
|
||||||
|doc, src, con|
|
:regexp => RegInlineMath,
|
||||||
if m = src.read_regexp(RegInlineMath)
|
:handler => lambda { |doc, src, con|
|
||||||
math = m.captures.compact.first
|
return false if not doc.is_math_enabled?
|
||||||
con.push doc.md_inline_math(math)
|
|
||||||
true
|
|
||||||
else
|
|
||||||
#puts "not math: #{src.cur_chars 10}"
|
|
||||||
false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
EquationStart = /^[ ]{0,3}(?:\\\[|\$\$)(.*)$/
|
if m = src.read_regexp(RegInlineMath)
|
||||||
|
math = m.captures.compact.first
|
||||||
|
con.push doc.md_inline_math(math)
|
||||||
|
true
|
||||||
|
else
|
||||||
|
#puts "not math: #{src.cur_chars 10}"
|
||||||
|
false
|
||||||
|
end
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
MathOpen1 = Regexp.escape('\\begin{equation}')
|
||||||
|
MathClose1 = Regexp.escape('\\end{equation}')
|
||||||
|
MathOpen2 = Regexp.escape('\\[')
|
||||||
|
MathClose2 = Regexp.escape('\\]')
|
||||||
|
MathOpen3 = Regexp.escape('$$')
|
||||||
|
MathClose3 = Regexp.escape('$$')
|
||||||
|
|
||||||
EqLabel = /(?:\((\w+)\))/
|
EqLabel = /(?:\((\w+)\))/
|
||||||
OneLineEquation = /^[ ]{0,3}(?:\\\[|\$\$)(.*)(?:\\\]|\$\$)\s*#{EqLabel}?\s*$/
|
EquationOpen = /#{MathOpen1}|#{MathOpen2}|#{MathOpen3}/
|
||||||
EquationEnd = /^(.*)(?:\\\]|\$\$)\s*#{EqLabel}?\s*$/
|
EquationClose = /#{MathClose1}|#{MathClose2}|#{MathClose3}/
|
||||||
|
|
||||||
MaRuKu::In::Markdown::
|
# $1 is opening, $2 is tex
|
||||||
register_block_extension(:regexp => EquationStart) do |doc, src, con|
|
EquationStart = /^[ ]{0,3}(#{EquationOpen})(.*)$/
|
||||||
# puts "Equation :#{self}"
|
# $1 is tex, $2 is closing, $3 is tex
|
||||||
first = src.shift_line
|
EquationEnd = /^(.*)(#{EquationClose})\s*#{EqLabel}?\s*$/
|
||||||
if first =~ OneLineEquation
|
# $1 is opening, $2 is tex, $3 is closing, $4 is label
|
||||||
math = $1
|
OneLineEquation = /^[ ]{0,3}(#{EquationOpen})(.*)(#{EquationClose})\s*#{EqLabel}?\s*$/
|
||||||
label = $2
|
|
||||||
con.push doc.md_equation($1, $2)
|
MaRuKu::In::Markdown::register_block_extension(
|
||||||
else
|
:regexp => EquationStart,
|
||||||
first =~ EquationStart
|
:handler => lambda { |doc, src, con|
|
||||||
math = $1
|
return false if not doc.is_math_enabled?
|
||||||
label = nil
|
first = src.shift_line
|
||||||
while true
|
if first =~ OneLineEquation
|
||||||
if not src.cur_line
|
opening, tex, closing, label = $1, $2, $3, $4
|
||||||
maruku_error "Stream finished while reading equation\n\n"+
|
numerate = doc.get_setting(:math_numbered).include?(opening)
|
||||||
add_tabs(math,1,'$> '), src, con
|
con.push doc.md_equation(tex, label, numerate)
|
||||||
break
|
else
|
||||||
end
|
first =~ EquationStart
|
||||||
line = src.shift_line
|
opening, tex = $1, $2
|
||||||
if line =~ EquationEnd
|
|
||||||
math += $1 + "\n"
|
numerate = doc.get_setting(:math_numbered).include?(opening)
|
||||||
label = $2 if $2
|
label = nil
|
||||||
break
|
while true
|
||||||
else
|
if not src.cur_line
|
||||||
math += line + "\n"
|
doc.maruku_error("Stream finished while reading equation\n\n"+
|
||||||
|
doc.add_tabs(tex,1,'$> '), src, con)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
line = src.shift_line
|
||||||
|
if line =~ EquationEnd
|
||||||
|
tex_line, closing = $1, $2
|
||||||
|
label = $3 if $3
|
||||||
|
tex += tex_line + "\n"
|
||||||
|
break
|
||||||
|
else
|
||||||
|
tex += line + "\n"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
con.push doc.md_equation(tex, label, numerate)
|
||||||
end
|
end
|
||||||
con.push doc.md_equation(math, label)
|
true
|
||||||
end
|
})
|
||||||
true
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
# This adds support for \eqref
|
# This adds support for \eqref
|
||||||
|
@ -72,11 +92,14 @@ end
|
||||||
RegEqPar = /\(eq:(\w+)\)/
|
RegEqPar = /\(eq:(\w+)\)/
|
||||||
RegEqref = Regexp::union(RegEqrefLatex, RegEqPar)
|
RegEqref = Regexp::union(RegEqrefLatex, RegEqPar)
|
||||||
|
|
||||||
MaRuKu::In::Markdown::
|
MaRuKu::In::Markdown::register_span_extension(
|
||||||
register_span_extension(:chars => [?\\, ?(], :regexp => RegEqref) do
|
:chars => [?\\, ?(],
|
||||||
|doc, src, con|
|
:regexp => RegEqref,
|
||||||
eqid = src.read_regexp(RegEqref).captures.compact.first
|
:handler => lambda { |doc, src, con|
|
||||||
r = doc.md_el(:eqref, [], meta={:eqid=>eqid})
|
return false if not doc.is_math_enabled?
|
||||||
con.push r
|
eqid = src.read_regexp(RegEqref).captures.compact.first
|
||||||
true
|
r = doc.md_el(:eqref, [], meta={:eqid=>eqid})
|
||||||
end
|
con.push r
|
||||||
|
true
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
|
@ -121,7 +121,7 @@ module MaRuKu; module Out; module HTML
|
||||||
|
|
||||||
div = create_html_element 'div'
|
div = create_html_element 'div'
|
||||||
add_class_to(div, 'maruku-equation')
|
add_class_to(div, 'maruku-equation')
|
||||||
if self.label # then numerate
|
if self.label # then numerate
|
||||||
span = Element.new 'span'
|
span = Element.new 'span'
|
||||||
span.attributes['class'] = 'maruku-eq-number'
|
span.attributes['class'] = 'maruku-eq-number'
|
||||||
num = self.num
|
num = self.num
|
||||||
|
|
2
vendor/plugins/maruku/lib/maruku/helpers.rb
vendored
2
vendor/plugins/maruku/lib/maruku/helpers.rb
vendored
|
@ -92,6 +92,8 @@ module Helpers
|
||||||
e.instance_variable_set :@parsed_html,
|
e.instance_variable_set :@parsed_html,
|
||||||
REXML::Document.new(raw_html)
|
REXML::Document.new(raw_html)
|
||||||
rescue
|
rescue
|
||||||
|
e.instance_variable_set :@parsed_html, nil
|
||||||
|
|
||||||
# tell_user "Malformed block of HTML:\n"+
|
# tell_user "Malformed block of HTML:\n"+
|
||||||
# add_tabs(raw_html,1,'|')
|
# add_tabs(raw_html,1,'|')
|
||||||
# " #{raw_html.inspect}\n\n"+ex.inspect
|
# " #{raw_html.inspect}\n\n"+ex.inspect
|
||||||
|
|
|
@ -262,7 +262,7 @@ class CharSourceStrscan
|
||||||
end
|
end
|
||||||
|
|
||||||
def consume_whitespace
|
def consume_whitespace
|
||||||
@s.scan /\s+/
|
@s.scan(/\s+/)
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -29,19 +29,19 @@ module MaRuKu; module In; module Markdown
|
||||||
return false # not special
|
return false # not special
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.register_span_extension(args, &block)
|
def self.register_span_extension(args)
|
||||||
e = SpanExtension.new
|
e = SpanExtension.new
|
||||||
e.chars = [*args[:chars]]
|
e.chars = [*args[:chars]]
|
||||||
e.regexp = args[:regexp]
|
e.regexp = args[:regexp]
|
||||||
e.block = block
|
e.block = args[:handler] || raise("No blocks passed")
|
||||||
e.chars.each do |c|
|
e.chars.each do |c|
|
||||||
(SpanExtensionsTrigger[c] ||= []).push e
|
(SpanExtensionsTrigger[c] ||= []).push e
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.register_block_extension(args, &block)
|
def self.register_block_extension(args)
|
||||||
regexp = args[:regexp]
|
regexp = args[:regexp]
|
||||||
BlockExtensions[regexp] = block
|
BlockExtensions[regexp] = (args[:handler] || raise("No blocks passed"))
|
||||||
end
|
end
|
||||||
|
|
||||||
# Hash Regexp -> Block
|
# Hash Regexp -> Block
|
||||||
|
@ -50,8 +50,10 @@ module MaRuKu; module In; module Markdown
|
||||||
def check_block_extensions(src, con, line)
|
def check_block_extensions(src, con, line)
|
||||||
BlockExtensions.each do |reg, block|
|
BlockExtensions.each do |reg, block|
|
||||||
if m = reg.match(line)
|
if m = reg.match(line)
|
||||||
|
p m
|
||||||
block = BlockExtensions[reg]
|
block = BlockExtensions[reg]
|
||||||
return true if block.call(doc, src, con)
|
accepted = block.call(doc, src, con)
|
||||||
|
return true if accepted
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return false # not special
|
return false # not special
|
||||||
|
|
|
@ -215,7 +215,7 @@ module MaRuKu; module In; module Markdown; module BlockLevelParser
|
||||||
if result.kind_of? String
|
if result.kind_of? String
|
||||||
raise "Not expected"
|
raise "Not expected"
|
||||||
else
|
else
|
||||||
output.push *result
|
output.push(*result)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
@ -242,7 +242,7 @@ module MaRuKu; module In; module Markdown; module BlockLevelParser
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_paragraph(src)
|
def read_paragraph(src)
|
||||||
lines = []
|
lines = [src.shift_line]
|
||||||
while src.cur_line
|
while src.cur_line
|
||||||
# :olist does not break
|
# :olist does not break
|
||||||
case t = src.cur_line.md_type
|
case t = src.cur_line.md_type
|
||||||
|
@ -491,12 +491,11 @@ module MaRuKu; module In; module Markdown; module BlockLevelParser
|
||||||
out.push md_ref_def(id, url, meta={:title=>title})
|
out.push md_ref_def(id, url, meta={:title=>title})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def split_cells(s)
|
||||||
|
s.strip.split('|').select{|x|x.strip.size>0}.map{|x|x.strip}
|
||||||
|
end
|
||||||
|
|
||||||
def read_table(src)
|
def read_table(src)
|
||||||
|
|
||||||
def split_cells(s)
|
|
||||||
s.strip.split('|').select{|x|x.strip.size>0}.map{|x|x.strip}
|
|
||||||
end
|
|
||||||
|
|
||||||
head = split_cells(src.shift_line).map{|s| md_el(:head_cell, parse_lines_as_span([s])) }
|
head = split_cells(src.shift_line).map{|s| md_el(:head_cell, parse_lines_as_span([s])) }
|
||||||
|
|
||||||
separator=split_cells(src.shift_line)
|
separator=split_cells(src.shift_line)
|
||||||
|
|
|
@ -196,10 +196,10 @@ module MaRuKu; module In; module Markdown; module SpanLevelParser
|
||||||
interpret_extension(src, con, [?}])
|
interpret_extension(src, con, [?}])
|
||||||
src.ignore_char # }
|
src.ignore_char # }
|
||||||
when nil
|
when nil
|
||||||
maruku_error ("Unclosed span (waiting for %s"+
|
maruku_error( ("Unclosed span (waiting for %s"+
|
||||||
"#{exit_on_strings.inspect})") % [
|
"#{exit_on_strings.inspect})") % [
|
||||||
exit_on_chars ? "#{exit_on_chars.inspect} or" : ""],
|
exit_on_chars ? "#{exit_on_chars.inspect} or" : ""],
|
||||||
src,con
|
src,con)
|
||||||
break
|
break
|
||||||
else # normal text
|
else # normal text
|
||||||
con.push_char src.shift_char
|
con.push_char src.shift_char
|
||||||
|
@ -618,8 +618,8 @@ module MaRuKu; module In; module Markdown; module SpanLevelParser
|
||||||
src.consume_whitespace
|
src.consume_whitespace
|
||||||
closing = src.shift_char # closing )
|
closing = src.shift_char # closing )
|
||||||
if closing != ?)
|
if closing != ?)
|
||||||
error ("Unclosed link: '"<<closing<<"'")+
|
error( ("Unclosed link: '"<<closing<<"'")+
|
||||||
" Read url=#{url.inspect} title=#{title.inspect}",src,con
|
" Read url=#{url.inspect} title=#{title.inspect}",src,con)
|
||||||
end
|
end
|
||||||
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
|
||||||
|
|
163
vendor/plugins/maruku/lib/maruku/input_textile2/t2_parser.rb
vendored
Normal file
163
vendor/plugins/maruku/lib/maruku/input_textile2/t2_parser.rb
vendored
Normal file
|
@ -0,0 +1,163 @@
|
||||||
|
class String
|
||||||
|
Textile2_EmptyLine = /^\s*$/
|
||||||
|
Textile2_Signature = /^(\S+\.?)\.\s(.*)/
|
||||||
|
|
||||||
|
def t2_empty?
|
||||||
|
self =~ Textile2_EmptyLine
|
||||||
|
end
|
||||||
|
|
||||||
|
def t2_contains_signature?
|
||||||
|
self =~ Textile2_Signature
|
||||||
|
end
|
||||||
|
|
||||||
|
# sig, rest = t2_get_signature
|
||||||
|
def t2_get_signature
|
||||||
|
self =~ Textile2_Signature
|
||||||
|
return Textile2Signature.new($1), $2
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class Textile2Signature
|
||||||
|
Reg = %r{
|
||||||
|
^
|
||||||
|
# block name is 1
|
||||||
|
([A-Za-z0-9]+)?
|
||||||
|
# style is 2
|
||||||
|
(
|
||||||
|
\{ # open bracket
|
||||||
|
([^\}]+) # style spec is 3
|
||||||
|
\} # close bracket
|
||||||
|
)?
|
||||||
|
# language is 4
|
||||||
|
(\[(\w+)\])? # value is 5
|
||||||
|
# class and id
|
||||||
|
(?:
|
||||||
|
\( # open par
|
||||||
|
(\w+)? # optional class specification is 6
|
||||||
|
(?:\#(\w+))? # optional id is 7
|
||||||
|
\) # close par
|
||||||
|
)?
|
||||||
|
# alignment is 8
|
||||||
|
(\<|\>|\<\>|\=)?
|
||||||
|
# padding
|
||||||
|
(\(+)? # left is 9
|
||||||
|
(\)+)? # right is 10
|
||||||
|
# filters is 11
|
||||||
|
(\|
|
||||||
|
(?:(?:\w+)\|)+
|
||||||
|
)?
|
||||||
|
# optional final dot is 12
|
||||||
|
(\.)?
|
||||||
|
$
|
||||||
|
}x
|
||||||
|
|
||||||
|
|
||||||
|
def initialize(s)
|
||||||
|
if m = Reg.match(s)
|
||||||
|
self.block_name = m[1]
|
||||||
|
self.style = m[3]
|
||||||
|
self.lang = m[4]
|
||||||
|
self.css_class = m[6]
|
||||||
|
self.css_id = m[7]
|
||||||
|
self.text_align = {nil=>nil,'>'=>'right','<'=>'left',
|
||||||
|
'<>'=>'center','='=>'justified'}[m[8]]
|
||||||
|
self.num_left_pad = m[9] && m[9].size
|
||||||
|
self.num_right_pad = m[10] && m[10].size
|
||||||
|
self.filters = m[11] && m[11].split('|')
|
||||||
|
self.double_dot = m[12] && true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
attr_accessor :block_name # or nil
|
||||||
|
attr_accessor :style # or nil
|
||||||
|
attr_accessor :lang # or nil
|
||||||
|
attr_accessor :css_class # or nil
|
||||||
|
attr_accessor :css_id # or nil
|
||||||
|
attr_accessor :text_align # {nil, 'left', 'right', 'center', 'justified'}
|
||||||
|
attr_accessor :num_left_pad # nil or 1..
|
||||||
|
attr_accessor :num_right_pad # nil or 1..
|
||||||
|
attr_accessor :filters # nil [], array of strings
|
||||||
|
attr_accessor :double_dot # nil or true
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
module MaRuKu
|
||||||
|
|
||||||
|
def self.textile2(source, params)
|
||||||
|
m = Maruku.new
|
||||||
|
m.t2_parse(source, params)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
class MDDocument
|
||||||
|
def t2_parse(source, params)
|
||||||
|
src = LineSource.new(source)
|
||||||
|
output = BlockContext.new
|
||||||
|
t2_parse_blocks(src, output)
|
||||||
|
self.children = output.elements
|
||||||
|
end
|
||||||
|
|
||||||
|
Handling = Struct.new(:method, :parse_lines)
|
||||||
|
T2_Handling = {
|
||||||
|
nil => Handling.new(:t2_block_paragraph, true),
|
||||||
|
'p' => Handling.new(:t2_block_paragraph, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
# Input is a LineSource
|
||||||
|
def t2_parse_blocks(src, output)
|
||||||
|
while src.cur_line
|
||||||
|
|
||||||
|
# ignore empty line
|
||||||
|
if l.t2_empty? then
|
||||||
|
src.shift_line
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
|
l = src.shift_line
|
||||||
|
# TODO: lists
|
||||||
|
# TODO: xml
|
||||||
|
# TODO: `==`
|
||||||
|
|
||||||
|
signature, l =
|
||||||
|
if l.t2_contains_signature?
|
||||||
|
l.t2_get_signature
|
||||||
|
else
|
||||||
|
[Textile2Signature.new, l]
|
||||||
|
end
|
||||||
|
|
||||||
|
if handling = T2_Handling.has_key?(signature.block_name)
|
||||||
|
if self.responds_to? handling.method
|
||||||
|
# read as many non-empty lines that you can
|
||||||
|
lines = [l]
|
||||||
|
if handling.parse_lines
|
||||||
|
while not src.cur_line.t2_empty?
|
||||||
|
lines.push src.shift_line
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
self.send(handling.method, src, output, signature, lines)
|
||||||
|
else
|
||||||
|
maruku_error("We don't know about method #{handling.method.inspect}")
|
||||||
|
next
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def t2_block_paragraph(src, output, signature, lines)
|
||||||
|
paragraph = lines.join("\n")
|
||||||
|
src2 = CharSource.new(paragraph, src)
|
||||||
|
# output =
|
||||||
|
end
|
||||||
|
|
||||||
|
def t2_parse_span(src, output)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end # MDDocument
|
||||||
|
|
||||||
|
end
|
2
vendor/plugins/maruku/lib/maruku/maruku.rb
vendored
2
vendor/plugins/maruku/lib/maruku/maruku.rb
vendored
|
@ -20,9 +20,9 @@
|
||||||
|
|
||||||
|
|
||||||
# The Maruku class is the public interface
|
# The Maruku class is the public interface
|
||||||
|
#
|
||||||
|
|
||||||
class Maruku
|
class Maruku
|
||||||
|
|
||||||
def initialize(s=nil, meta={})
|
def initialize(s=nil, meta={})
|
||||||
super(nil)
|
super(nil)
|
||||||
self.attributes.merge! meta
|
self.attributes.merge! meta
|
||||||
|
|
|
@ -316,11 +316,55 @@ Output: HTML
|
||||||
It is copied as a standard HTML attribute.
|
It is copied as a standard HTML attribute.
|
||||||
=end
|
=end
|
||||||
|
|
||||||
StandardAttributes = [:id, :style, :class]
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
HTML4Attributes = {}
|
||||||
|
|
||||||
|
coreattrs = [:id, :class, :style, :title]
|
||||||
|
i18n = [:lang, 'xml:lang'.to_sym]
|
||||||
|
events = [
|
||||||
|
:onclick, :ondblclick, :onmousedown, :onmouseup, :onmouseover,
|
||||||
|
:onmousemove, :onmouseout,
|
||||||
|
:onkeypress, :onkeydown, :onkeyup]
|
||||||
|
attrs = coreattrs + i18n + events
|
||||||
|
cellhalign = [:align, :char, :charoff]
|
||||||
|
cellvalign = [:valign]
|
||||||
|
[
|
||||||
|
['body', attrs + [:onload, :onunload]],
|
||||||
|
['address', attrs],
|
||||||
|
['div', attrs],
|
||||||
|
['a', attrs+[:charset, :type, :name, :rel, :rev, :accesskey, :shape, :coords, :tabindex,
|
||||||
|
:onfocus,:onblur]],
|
||||||
|
['img', attrs + [:longdesc, :name, :height, :width, :alt] ],
|
||||||
|
['p', attrs],
|
||||||
|
[['h1','h2','h3','h4','h5','h6'], attrs],
|
||||||
|
[['pre'], attrs],
|
||||||
|
[['q', 'blockquote'], attrs+[:cite]],
|
||||||
|
[['ins','del'], attrs+[:cite,:datetime]],
|
||||||
|
[['ol','ul','li'], attrs],
|
||||||
|
['table',attrs+[:summary, :width, :frame, :rules, :border, :cellspacing, :cellpadding]],
|
||||||
|
['caption',attrs],
|
||||||
|
[['colgroup','col'],attrs+[:span, :width]+cellhalign+cellvalign],
|
||||||
|
[['thead','tbody','tfoot'], attrs+cellhalign+cellvalign],
|
||||||
|
[['td','td','th'], attrs+[:abbr, :axis, :headers, :scope, :rowspan, :colspan, :cellvalign, :cellhalign]],
|
||||||
|
|
||||||
|
# altri
|
||||||
|
[['em','code','strong','hr','span','dl','dd','dt'], attrs]
|
||||||
|
].each do |el, a| [*el].each do |e| HTML4Attributes[e] = a end end
|
||||||
|
|
||||||
|
|
||||||
def create_html_element(name, attributes_to_copy=[])
|
def create_html_element(name, attributes_to_copy=[])
|
||||||
m = Element.new name
|
m = Element.new name
|
||||||
(StandardAttributes+attributes_to_copy).each do |a|
|
if atts = HTML4Attributes[name] then
|
||||||
if v = @attributes[a] then m.attributes[a.to_s] = v.to_s end
|
atts.each do |att|
|
||||||
|
if v = @attributes[att] then
|
||||||
|
m.attributes[att.to_s] = v.to_s
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
# puts "not atts for #{name.inspect}"
|
||||||
end
|
end
|
||||||
m
|
m
|
||||||
end
|
end
|
||||||
|
@ -337,11 +381,11 @@ It is copied as a standard HTML attribute.
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def to_html_paragraph; add_ws wrap_as_element('p', [:'xml:lang']) end
|
def to_html_paragraph; add_ws wrap_as_element('p') end
|
||||||
def to_html_ol; add_ws wrap_as_element('ol') end
|
def to_html_ol; add_ws wrap_as_element('ol') end
|
||||||
def to_html_li; add_ws wrap_as_element('li') end
|
def to_html_li; add_ws wrap_as_element('li') end
|
||||||
def to_html_li_span; add_ws wrap_as_element('li') end
|
def to_html_li_span; add_ws wrap_as_element('li') end
|
||||||
def to_html_quote; add_ws wrap_as_element('blockquote', [:cite, :'xml:lang']) end
|
def to_html_quote; add_ws wrap_as_element('blockquote') end
|
||||||
def to_html_strong; wrap_as_element('strong') end
|
def to_html_strong; wrap_as_element('strong') end
|
||||||
def to_html_emphasis; wrap_as_element('em') end
|
def to_html_emphasis; wrap_as_element('em') end
|
||||||
|
|
||||||
|
@ -383,7 +427,7 @@ by Maruku, to have the same results in both HTML and LaTeX.
|
||||||
|
|
||||||
def to_html_header
|
def to_html_header
|
||||||
element_name = "h#{self.level}"
|
element_name = "h#{self.level}"
|
||||||
h = wrap_as_element(element_name, [:title, :'xml:lang'])
|
h = wrap_as_element element_name
|
||||||
|
|
||||||
if span = render_section_number
|
if span = render_section_number
|
||||||
h.insert_before(h.children.first, span)
|
h.insert_before(h.children.first, span)
|
||||||
|
@ -432,6 +476,7 @@ and
|
||||||
|
|
||||||
=end
|
=end
|
||||||
|
|
||||||
|
$syntax_loaded = false
|
||||||
def to_html_code;
|
def to_html_code;
|
||||||
source = self.raw_code
|
source = self.raw_code
|
||||||
|
|
||||||
|
@ -547,7 +592,7 @@ of the form `#ff00ff`.
|
||||||
|
|
||||||
color = get_setting(:code_background_color)
|
color = get_setting(:code_background_color)
|
||||||
if color != Globals[:code_background_color]
|
if color != Globals[:code_background_color]
|
||||||
pre.attributes['style'] = "background-color: #{color};"
|
pre.attributes['style'] = "background-color: #{color};"+(pre.attributes['style']||"")
|
||||||
end
|
end
|
||||||
|
|
||||||
pre
|
pre
|
||||||
|
@ -565,17 +610,17 @@ of the form `#ff00ff`.
|
||||||
def add_class_to_link(a)
|
def add_class_to_link(a)
|
||||||
return # not ready yet
|
return # not ready yet
|
||||||
|
|
||||||
url = a.attributes['href']
|
# url = a.attributes['href']
|
||||||
return if not url
|
# return if not url
|
||||||
|
#
|
||||||
if url =~ /^#/
|
# if url =~ /^#/
|
||||||
add_class_to(a, 'maruku-link-samedoc')
|
# add_class_to(a, 'maruku-link-samedoc')
|
||||||
elsif url =~ /^http:/
|
# elsif url =~ /^http:/
|
||||||
add_class_to(a, 'maruku-link-external')
|
# add_class_to(a, 'maruku-link-external')
|
||||||
else
|
# else
|
||||||
add_class_to(a, 'maruku-link-local')
|
# add_class_to(a, 'maruku-link-local')
|
||||||
end
|
# end
|
||||||
|
#
|
||||||
# puts a.attributes['class']
|
# puts a.attributes['class']
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -659,10 +704,7 @@ of the form `#ff00ff`.
|
||||||
url = ref[:url]
|
url = ref[:url]
|
||||||
title = ref[:title]
|
title = ref[:title]
|
||||||
a.attributes['src'] = url.to_s
|
a.attributes['src'] = url.to_s
|
||||||
a.attributes['alt'] = title.to_s
|
a.attributes['alt'] = title.to_s if not a.attributes['alt']
|
||||||
[:title, :class, :style].each do |s|
|
|
||||||
a.attributes[s.to_s] = ref[s] if ref[s]
|
|
||||||
end
|
|
||||||
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};"+
|
||||||
|
@ -674,15 +716,15 @@ of the form `#ff00ff`.
|
||||||
|
|
||||||
def to_html_im_image
|
def to_html_im_image
|
||||||
if not url = self.url
|
if not url = self.url
|
||||||
maruku_error"Image with no url: #{self.inspect}"
|
maruku_error "Image with no url: #{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
|
||||||
title = self.title
|
title = self.title
|
||||||
a = create_html_element 'img'
|
a = create_html_element 'img'
|
||||||
a.attributes['src'] = url
|
a.attributes['src'] = url.to_s
|
||||||
a.attributes['alt'] = title.to_s
|
a.attributes['alt'] = title.to_s if not a.attributes['alt']
|
||||||
return a
|
return a
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -762,8 +804,7 @@ of the form `#ff00ff`.
|
||||||
i += num_columns
|
i += num_columns
|
||||||
end
|
end
|
||||||
|
|
||||||
table = create_html_element 'table',
|
table = create_html_element 'table'
|
||||||
[:summary, :width, :frame, :rules, :border, :cellspacing, :cellpadding]
|
|
||||||
thead = Element.new 'thead'
|
thead = Element.new 'thead'
|
||||||
tr = Element.new 'tr'
|
tr = Element.new 'tr'
|
||||||
array_to_html(head).each do |x| tr<<x end
|
array_to_html(head).each do |x| tr<<x end
|
||||||
|
|
|
@ -266,8 +266,8 @@ module MaRuKu; module Tests
|
||||||
# ['$ 20,000$', ['$ 20,000$']],
|
# ['$ 20,000$', ['$ 20,000$']],
|
||||||
# ['$20,000 $ $20,000$', ['$20,000 $ ', md_inline_math('20,000')]],
|
# ['$20,000 $ $20,000$', ['$20,000 $ ', md_inline_math('20,000')]],
|
||||||
["#{Maruku8}", [Maruku8], "Reading UTF-8"],
|
["#{Maruku8}", [Maruku8], "Reading UTF-8"],
|
||||||
["#{AccIta1}", [AccIta8], "Converting ISO-8859-1 to UTF-8",
|
# ["#{AccIta1}", [AccIta8], "Converting ISO-8859-1 to UTF-8",
|
||||||
{:encoding => 'iso-8859-1'}],
|
# {:encoding => 'iso-8859-1'}],
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -294,6 +294,7 @@ module MaRuKu; module Tests
|
||||||
m.attributes[:on_error] = :raise
|
m.attributes[:on_error] = :raise
|
||||||
Globals[:debug_keep_ials] = true
|
Globals[:debug_keep_ials] = true
|
||||||
|
|
||||||
|
num_ok = 0
|
||||||
good_cases.each do |input, expected, comment|
|
good_cases.each do |input, expected, comment|
|
||||||
output = nil
|
output = nil
|
||||||
begin
|
begin
|
||||||
|
@ -309,6 +310,7 @@ module MaRuKu; module Tests
|
||||||
raise e if @break_on_first_error
|
raise e if @break_on_first_error
|
||||||
else
|
else
|
||||||
quiet || print_status(comment,'OK')
|
quiet || print_status(comment,'OK')
|
||||||
|
num_ok += 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -318,6 +320,7 @@ module MaRuKu; module Tests
|
||||||
print_status(comment, 'FAILED', s)
|
print_status(comment, 'FAILED', s)
|
||||||
break if break_on_first_error
|
break if break_on_first_error
|
||||||
else
|
else
|
||||||
|
num_ok += 1
|
||||||
quiet || print_status(comment, 'OK')
|
quiet || print_status(comment, 'OK')
|
||||||
end
|
end
|
||||||
else # I expected a raise
|
else # I expected a raise
|
||||||
|
@ -328,7 +331,11 @@ module MaRuKu; module Tests
|
||||||
break if break_on_first_error
|
break if break_on_first_error
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end # do
|
||||||
|
if num_ok != good_cases.size
|
||||||
|
return false
|
||||||
|
else
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -358,6 +365,6 @@ end
|
||||||
verbose = ARGV.include? 'v'
|
verbose = ARGV.include? 'v'
|
||||||
break_on_first = ARGV.include? 'b'
|
break_on_first = ARGV.include? 'b'
|
||||||
quiet = ARGV.include? 'q'
|
quiet = ARGV.include? 'q'
|
||||||
Maruku.new.test_span_parser(verbose, break_on_first, quiet)
|
ok = Maruku.new.test_span_parser(verbose, break_on_first, quiet)
|
||||||
|
|
||||||
|
|
||||||
|
exit (ok ? 0 : 1)
|
||||||
|
|
2
vendor/plugins/maruku/lib/maruku/version.rb
vendored
2
vendor/plugins/maruku/lib/maruku/version.rb
vendored
|
@ -19,7 +19,7 @@
|
||||||
#++
|
#++
|
||||||
|
|
||||||
module MaRuKu
|
module MaRuKu
|
||||||
Version = '0.5.2'
|
Version = '0.5.3'
|
||||||
|
|
||||||
MarukuURL = 'http://maruku.rubyforge.org/'
|
MarukuURL = 'http://maruku.rubyforge.org/'
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue