lib/trac-wiki/parser.rb in trac-wiki-0.3.37 vs lib/trac-wiki/parser.rb in trac-wiki-0.3.38
- old
+ new
@@ -89,11 +89,11 @@
# $e^x$ for inline math
# $$ e^x $$ for display math
attr_writer :math
def math?; @math; end
- # allow some <b> <form> <html>
+ # allow some <b> <form> <html>
# html will be sanitized
attr_writer :allow_html
def allow_html?; @allow_html; end
# add '<a class='editheading' href="?edit=N>edit</a>'
@@ -253,11 +253,11 @@
fmt = env.arg(0)
args = (1 .. env.arg_count ).map{ |i| env.expand_arg(i)}
begin
sprintf fmt, *args
rescue Exception => e
- "(sprintf error:`#{e}`)"
+ "(sprintf error:`#{e}`)"
end
},
'!digest' => proc { |env| Base64.urlsafe_encode64(Digest::SHA256.digest(env.expand_arg(0))) },
'!base64' => proc { |env| Base64.urlsafe_encode64(env.expand_arg(0)) },
'!tt' => proc { |env| "`#{env.expand_arg(0)}`" },
@@ -374,10 +374,17 @@
else
start_tag(tag)
end
end
+ def end_to_tag(tag)
+ if @stack.include?(tag)
+ end_tag while @stack.last != tag
+ end_tag
+ end
+ end
+
def end_paragraph
end_tag while !@stack.empty?
@p = false
end
@@ -513,11 +520,11 @@
# raw url http://example.com/
when str =~ /\A(!)?((https?|ftps?):\/\/\S+?)(?=([\]\,.?!:;"'\)]+)?(\s|$))/
notlink, link = $1, $2
make_link(link, nil, link, 0, !!notlink)
# [[Image(pic.jpg|tag)]]
- when str =~ /\A\[\[Image\(([^,]*?)(,(.*?))?\)\]\]/ # image
+ when str =~ /\A\[\[Image\(([^,]*?)(,(.*?))?\)\]\]/ # image
make_image($1, $3)
# [[link]]
# [ link2 | text5 ]
when str =~ /\A (\[ \s* ([^\[|]*?) \s*) ((\|\s*)(.*?))? \s* \] /mx
link, content, content_offset, whole = $2, $5, $1.size + ($4||'').size, $&
@@ -541,11 +548,11 @@
when str =~ /\A`(.*?)`/ # inline pre (tt)
@tree.tag(:tt, $1)
when math? && str =~ /\A\$(.+?)\$/ # inline math (tt)
@tree.tag(:span, {:class => 'math'}, $1)
@was_math = true
- when str =~ /\A(\&\w*;)/ # html entity
+ when str =~ /\A(\&\w*;)/ # html entity
#print "add html ent: #{$1}\n"
@tree.add_raw($1)
when str =~ /\A([:alpha:]|[:digit:])+/
@tree.add($&) # word
when str =~ /\A\s+/
@@ -569,11 +576,11 @@
when str =~ /\A\^/
toggle_tag 'sup', $& # ^{}
when str =~ /\A,,/
toggle_tag 'sub', $& # _{}
when str =~ /\A!\./
- @tree.add('') # !. \relax
+ @tree.add('') # !. \relax
when str =~ /\A!(\{\{|[\S])/
@tree.add($1) # !neco !{{
# when str =~ /\A!(\{\{)/
# @tree.add($1) # !neco !{
when str =~ /\A./
@@ -759,10 +766,33 @@
when '>' ; 'merge-your'
end
end_paragraph
@tree.tag(:div, { class: "merge #{merge_class}" }, who)
end
+
+ def do_wikimedia_table(text)
+ end_paragraph
+ start_tag(:table)
+ start_tag(:tr)
+ offset = 0
+ text.split("\n").each do |line|
+ offset += line.length + 1
+ if line == '|-'
+ end_to_tag :tr
+ start_tag(:tr)
+ elsif line =~ /^([!\|])(.*)/
+ end_to_tag :td
+ fst, rest = $1, $2
+ start_tag($1 == '|' ? :td : :th)
+ parse_inline(rest.strip, offset)
+ else
+ parse_inline(' ' +line.strip, offset)
+ end
+ end
+ end_to_tag :table
+ end
+
def do_pre(text)
end_paragraph
nowikiblock = make_nowikiblock(text)
@tree.tag(:pre, nowikiblock)
end
@@ -874,10 +904,13 @@
when merge? && str =~ /\A(<{7}|={7}|>{7}|\|{7}) *(\S*).*$(\r?\n)?/
do_merge($1, $2)
# pre {{{ ... }}}
when str =~ /\A\{\{\{\r?\n(.*?)\r?\n\}\}\}/m
do_pre($1)
+ # wikimedia table {| ... |}
+ when str =~ /\A\{\|\r?\n(.*?)\r?\n\|\}/m
+ do_wikimedia_table($1)
# horizontal rule
when str =~ /\A\s*-{4,}\s*$/
do_hr()
# heading == Wiki Ruless ==
# heading == Wiki Ruless == #tag
@@ -890,14 +923,14 @@
when str =~ /\A\s*$(\r?\n)?/
end_paragraph
#when str =~ /\A([:\w\s]+)::(\s+|\r?\n)/
when str =~ /\A(.+)::(\s+|\r?\n)/
do_term($1)
- # li
+ # li *
when str =~ /\A((\s*)([*-]|[aAIi\d]\.)\s+)(.*?)$(\r?\n)?/
parse_li_line($2.size, $3)
parse_inline($4, $1.size)
- # citation
+ # citation >
when str =~ /\A(>[>\s]*)(.*?)$(\r?\n)?/
do_citation($1.count('>'))
parse_inline($2, $1.size)
# ordinary line
when str =~ /\A(\s*)(\S+.*?)$(\r?\n)?/