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,10 +192,11 @@ module MaRuKu; module In; module Markdown; module SpanLevelParser
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def merge_ial(elements, src, con)
|
|
||||||
# We need a helper
|
# We need a helper
|
||||||
def is_ial(e); e.kind_of? MDElement and e.node_type == :ial end
|
def is_ial(e); e.kind_of? MDElement and e.node_type == :ial end
|
||||||
|
|
||||||
|
def merge_ial(elements, src, con)
|
||||||
|
|
||||||
# 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|
|
||||||
if is_ial(e) && i>= 1 then
|
if is_ial(e) && i>= 1 then
|
||||||
|
|
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
|
||||||
|
|
|
@ -1,23 +1,25 @@
|
||||||
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,
|
||||||
|
:handler => lambda { |doc, src, con|
|
||||||
|
return false if not doc.is_math_enabled?
|
||||||
|
|
||||||
if m = src.read_regexp(RegInlineMath)
|
if m = src.read_regexp(RegInlineMath)
|
||||||
math = m.captures.compact.first
|
math = m.captures.compact.first
|
||||||
con.push doc.md_inline_math(math)
|
con.push doc.md_inline_math(math)
|
||||||
|
@ -26,45 +28,63 @@ end
|
||||||
#puts "not math: #{src.cur_chars 10}"
|
#puts "not math: #{src.cur_chars 10}"
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
end
|
}
|
||||||
|
)
|
||||||
|
|
||||||
EquationStart = /^[ ]{0,3}(?:\\\[|\$\$)(.*)$/
|
|
||||||
|
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
|
||||||
|
EquationEnd = /^(.*)(#{EquationClose})\s*#{EqLabel}?\s*$/
|
||||||
|
# $1 is opening, $2 is tex, $3 is closing, $4 is label
|
||||||
|
OneLineEquation = /^[ ]{0,3}(#{EquationOpen})(.*)(#{EquationClose})\s*#{EqLabel}?\s*$/
|
||||||
|
|
||||||
|
MaRuKu::In::Markdown::register_block_extension(
|
||||||
|
:regexp => EquationStart,
|
||||||
|
:handler => lambda { |doc, src, con|
|
||||||
|
return false if not doc.is_math_enabled?
|
||||||
first = src.shift_line
|
first = src.shift_line
|
||||||
if first =~ OneLineEquation
|
if first =~ OneLineEquation
|
||||||
math = $1
|
opening, tex, closing, label = $1, $2, $3, $4
|
||||||
label = $2
|
numerate = doc.get_setting(:math_numbered).include?(opening)
|
||||||
con.push doc.md_equation($1, $2)
|
con.push doc.md_equation(tex, label, numerate)
|
||||||
else
|
else
|
||||||
first =~ EquationStart
|
first =~ EquationStart
|
||||||
math = $1
|
opening, tex = $1, $2
|
||||||
|
|
||||||
|
numerate = doc.get_setting(:math_numbered).include?(opening)
|
||||||
label = nil
|
label = nil
|
||||||
while true
|
while true
|
||||||
if not src.cur_line
|
if not src.cur_line
|
||||||
maruku_error "Stream finished while reading equation\n\n"+
|
doc.maruku_error("Stream finished while reading equation\n\n"+
|
||||||
add_tabs(math,1,'$> '), src, con
|
doc.add_tabs(tex,1,'$> '), src, con)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
line = src.shift_line
|
line = src.shift_line
|
||||||
if line =~ EquationEnd
|
if line =~ EquationEnd
|
||||||
math += $1 + "\n"
|
tex_line, closing = $1, $2
|
||||||
label = $2 if $2
|
label = $3 if $3
|
||||||
|
tex += tex_line + "\n"
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
math += line + "\n"
|
tex += line + "\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
con.push doc.md_equation(math, label)
|
con.push doc.md_equation(tex, label, numerate)
|
||||||
end
|
end
|
||||||
true
|
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,
|
||||||
|
:handler => lambda { |doc, src, con|
|
||||||
|
return false if not doc.is_math_enabled?
|
||||||
eqid = src.read_regexp(RegEqref).captures.compact.first
|
eqid = src.read_regexp(RegEqref).captures.compact.first
|
||||||
r = doc.md_el(:eqref, [], meta={:eqid=>eqid})
|
r = doc.md_el(:eqref, [], meta={:eqid=>eqid})
|
||||||
con.push r
|
con.push r
|
||||||
true
|
true
|
||||||
end
|
}
|
||||||
|
)
|
||||||
|
|
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 read_table(src)
|
|
||||||
|
|
||||||
def split_cells(s)
|
def split_cells(s)
|
||||||
s.strip.split('|').select{|x|x.strip.size>0}.map{|x|x.strip}
|
s.strip.split('|').select{|x|x.strip.size>0}.map{|x|x.strip}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def read_table(src)
|
||||||
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};"+
|
||||||
|
@ -676,13 +718,13 @@ of the form `#ff00ff`.
|
||||||
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