Sync with latest Maruku.

This commit is contained in:
Jacques Distler 2007-03-07 12:49:06 -06:00
parent 7b1c7c0da6
commit 8300133c8d
8 changed files with 68 additions and 32 deletions

View file

@ -91,9 +91,8 @@ module Helpers
raw_html = "<marukuwrap>#{raw_html}</marukuwrap>" raw_html = "<marukuwrap>#{raw_html}</marukuwrap>"
e.instance_variable_set :@parsed_html, e.instance_variable_set :@parsed_html,
REXML::Document.new(raw_html) REXML::Document.new(raw_html)
rescue rescue #Exception => ex
e.instance_variable_set :@parsed_html, nil 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

View file

@ -34,10 +34,14 @@ module MaRuKu; module In; module Markdown; module SpanLevelParser
EverythingElse = %r{^[^<]+}m EverythingElse = %r{^[^<]+}m
CommentStart = %r{^<!--}x CommentStart = %r{^<!--}x
CommentEnd = %r{^.*-->} CommentEnd = %r{^.*-->}
TO_SANITIZE = ['img','hr'] TO_SANITIZE = ['img','hr','br']
attr_reader :rest attr_reader :rest
def my_debug(s)
# puts "---"*10+"\n"+inspect+"\t>>>\t"s
end
def initialize def initialize
@rest = "" @rest = ""
@tag_stack = [] @tag_stack = []
@ -46,7 +50,7 @@ module MaRuKu; module In; module Markdown; module SpanLevelParser
self.state = :inside_element self.state = :inside_element
end end
attr_accessor :state # :inside_element, :inside_tag, :inside_comment, attr_accessor :state # = :inside_element, :inside_tag, :inside_comment,
def eat_this(line) def eat_this(line)
@rest = line + @rest @rest = line + @rest
@ -70,15 +74,18 @@ module MaRuKu; module In; module Markdown; module SpanLevelParser
@rest = @m.post_match @rest = @m.post_match
self.state = :inside_comment self.state = :inside_comment
elsif @m = Tag.match(@rest) then elsif @m = Tag.match(@rest) then
my_debug "#{@state}: Tag: #{@m.to_s.inspect}"
things_read += 1 things_read += 1
handle_tag handle_tag
self.state = :inside_element self.state = :inside_element
elsif @m = PartialTag.match(@rest) then elsif @m = PartialTag.match(@rest) then
my_debug "#{@state}: PartialTag: #{@m.to_s.inspect}"
@already += @m.pre_match @already += @m.pre_match
@rest = @m.post_match @rest = @m.post_match
@partial_tag = @m.to_s @partial_tag = @m.to_s
self.state = :inside_tag self.state = :inside_tag
elsif @m = EverythingElse.match(@rest) elsif @m = EverythingElse.match(@rest)
my_debug "#{@state}: Everything: #{@m.to_s.inspect}"
@already += @m.pre_match + @m.to_s @already += @m.pre_match + @m.to_s
@rest = @m.post_match @rest = @m.post_match
self.state = :inside_element self.state = :inside_element
@ -87,7 +94,9 @@ module MaRuKu; module In; module Markdown; module SpanLevelParser
end end
when :inside_tag when :inside_tag
if @m = /^[^>]*>/.match(@rest) then if @m = /^[^>]*>/.match(@rest) then
my_debug "#{@state}: inside_tag: matched #{@m.to_s.inspect}"
@partial_tag += @m.to_s @partial_tag += @m.to_s
my_debug "#{@state}: inside_tag: matched TOTAL: #{@partial_tag.to_s.inspect}"
@rest = @partial_tag + @m.post_match @rest = @partial_tag + @m.post_match
@partial_tag = nil @partial_tag = nil
self.state = :inside_element self.state = :inside_element
@ -112,16 +121,16 @@ module MaRuKu; module In; module Markdown; module SpanLevelParser
is_closing = !!@m[1] is_closing = !!@m[1]
tag = @m[2] tag = @m[2]
attributes = @m[3] attributes = @m[3].to_s
is_single = false is_single = false
if attributes =~ /\A(.*)\/\Z/ if attributes[-1] == ?/ # =~ /\A(.*)\/\Z/
attributes = $1 attributes = attributes[0, attributes.size-1]
is_single = true is_single = true
end end
# puts "READ TAG #{@m.to_s.inspect} tag = #{tag} closing? #{is_closing} single = #{is_single}" my_debug "Attributes: #{attributes.inspect}"
my_debug "READ TAG #{@m.to_s.inspect} tag = #{tag} closing? #{is_closing} single = #{is_single}"
if TO_SANITIZE.include? tag if TO_SANITIZE.include? tag
attributes.strip! attributes.strip!
@ -145,7 +154,10 @@ module MaRuKu; module In; module Markdown; module SpanLevelParser
else else
@already += @m.to_s @already += @m.to_s
@tag_stack.push(tag) unless is_single if not is_single
@tag_stack.push(tag)
my_debug "Pushing #{tag.inspect} when read #{@m.to_s.inspect}"
end
end end
end end
def error(s) def error(s)
@ -167,6 +179,8 @@ module MaRuKu; module In; module Markdown; module SpanLevelParser
@already @already
end end
def rest() @rest end
def is_finished? def is_finished?
(self.state == :inside_element) and @tag_stack.empty? (self.state == :inside_element) and @tag_stack.empty?
end end

View file

@ -237,6 +237,10 @@ module MaRuKu; module In; module Markdown; module BlockLevelParser
ex = e.inspect + e.backtrace.join("\n") ex = e.inspect + e.backtrace.join("\n")
maruku_error "Bad block-level HTML:\n#{add_tabs(ex,1,'|')}\n", src maruku_error "Bad block-level HTML:\n#{add_tabs(ex,1,'|')}\n", src
end end
if not (h.rest =~ /^\s*$/)
maruku_error "Could you please format this better?\n"+
"I see that #{h.rest.inspect} is left after the raw HTML.", src
end
raw_html = h.stuff_you_read raw_html = h.stuff_you_read
return md_html(raw_html) return md_html(raw_html)
end end
@ -246,7 +250,7 @@ module MaRuKu; module In; module Markdown; module BlockLevelParser
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
when :quote,:header3,:empty,:raw_html,:ref_definition,:ial,:xml_instr when :quote,:header3,:empty,:ref_definition,:ial #,:xml_instr,:raw_html
break break
when :olist,:ulist when :olist,:ulist
break if src.next_line.md_type == t break if src.next_line.md_type == t
@ -349,6 +353,7 @@ module MaRuKu; module In; module Markdown; module BlockLevelParser
# collect all indented lines # collect all indented lines
saw_empty = false; saw_anything_after = false saw_empty = false; saw_anything_after = false
while src.cur_line while src.cur_line
# puts "Reading indent = #{indentation} #{src.cur_line.inspect}"
#puts "#{src.cur_line.md_type} #{src.cur_line.inspect}" #puts "#{src.cur_line.md_type} #{src.cur_line.inspect}"
if src.cur_line.md_type == :empty if src.cur_line.md_type == :empty
saw_empty = true saw_empty = true
@ -365,7 +370,9 @@ module MaRuKu; module In; module Markdown; module BlockLevelParser
end end
saw_anything_after = true saw_anything_after = true
else else
# if src.cur_line[0] != ?\
break if break_list.include? src.cur_line.md_type break if break_list.include? src.cur_line.md_type
# end
# break if src.cur_line.md_type != :text # break if src.cur_line.md_type != :text
end end

View file

@ -451,22 +451,35 @@ module MaRuKu; module In; module Markdown; module SpanLevelParser
h = HTMLHelper.new h = HTMLHelper.new
begin begin
# This is our current buffer in the context # This is our current buffer in the context
start = src.current_remaining_buffer next_stuff = src.current_remaining_buffer
h.eat_this start consumed = 0
if not h.is_finished? while true
error "inline_html: Malformed:\n "+ h.eat_this next_stuff[consumed].chr; consumed += 1
"#{start.inspect}\n #{h.inspect}",src,con break if h.is_finished?
if consumed >= next_stuff.size
maruku_error "Malformed HTML starting at #{next_stuff.inspect}", src, con
end
end end
consumed = start.size - h.rest.size
if consumed > 0
con.push_element md_html(h.stuff_you_read)
src.ignore_chars(consumed) src.ignore_chars(consumed)
else con.push_element md_html(h.stuff_you_read)
puts "HTML helper did not work on #{start.inspect}"
con.push_char src.shift_char #start = src.current_remaining_buffer
end # h.eat_this start
# if not h.is_finished?
# error "inline_html: Malformed:\n "+
# "#{start.inspect}\n #{h.inspect}",src,con
# end
#
# consumed = start.size - h.rest.size
# if consumed > 0
# con.push_element md_html(h.stuff_you_read)
# src.ignore_chars(consumed)
# else
# puts "HTML helper did not work on #{start.inspect}"
# con.push_char src.shift_char
# end
rescue Exception => e rescue Exception => e
maruku_error "Bad html: \n" + maruku_error "Bad html: \n" +
add_tabs(e.inspect+e.backtrace.join("\n"),1,'>'), add_tabs(e.inspect+e.backtrace.join("\n"),1,'>'),

View file

@ -50,8 +50,11 @@ module MaRuKu; module Strings
return :xml_instr if l =~ %r{^\s*<\?} return :xml_instr if l =~ %r{^\s*<\?}
return :raw_html if l =~ %r{^[ ]?[ ]?[ ]?</?\s*\w+} return :raw_html if l =~ %r{^[ ]?[ ]?[ ]?</?\s*\w+}
return :raw_html if l =~ %r{^[ ]?[ ]?[ ]?<\!\-\-} return :raw_html if l =~ %r{^[ ]?[ ]?[ ]?<\!\-\-}
return :ulist if l =~ /^\s?([\*\-\+])\s+.*\w+/ # Something is wrong with how we parse lists! :-(
return :olist if l =~ /^\s?\d+\..*\w+/ #return :ulist if l =~ /^[ ]{0,3}([\*\-\+])\s+.*\w+/
#return :olist if l =~ /^[ ]{0,3}\d+\..*\w+/
return :ulist if l =~ /^[ ]{0,1}([\*\-\+])\s+.*\w+/
return :olist if l =~ /^[ ]{0,1}\d+\..*\w+/
return :header1 if l =~ /^(=)+/ return :header1 if l =~ /^(=)+/
return :header2 if l =~ /^([-\s])+$/ return :header2 if l =~ /^([-\s])+$/
return :header3 if l =~ /^(#)+\s*\S+/ return :header3 if l =~ /^(#)+\s*\S+/

View file

@ -42,7 +42,7 @@ module MaRuKu
dummy_layout_slide = dummy_layout_slide =
" "
<div class='layout'> <div class='layout'>
<div id='controls'> </div> <div id='controls'></div>
<div id='currentSlide'> </div> <div id='currentSlide'> </div>
<div id='header'> #{slide_header}</div> <div id='header'> #{slide_header}</div>
<div id='footer'> <div id='footer'>
@ -75,7 +75,7 @@ module MaRuKu
slide_num += 1 slide_num += 1
@doc.attributes[:doc_prefix] = "s#{slide_num}" @doc.attributes[:doc_prefix] = "s#{slide_num}"
# puts "Slide #{slide_num}: " + slide.header_element.to_s puts "Slide #{slide_num}: " + slide.header_element.to_s
div = Element.new('div', presentation) div = Element.new('div', presentation)
div.attributes['class'] = 'slide' div.attributes['class'] = 'slide'

View file

@ -29,7 +29,7 @@ module MaRuKu; module Strings
TabSize = 4; TabSize = 4;
def split_lines(s) def split_lines(s)
s.split("\n") s.gsub("\r","").split("\n")
end end
# This parses email headers. Returns an hash. # This parses email headers. Returns an hash.

View file

@ -19,7 +19,7 @@
#++ #++
module MaRuKu module MaRuKu
Version = '0.5.4' Version = '0.5.5'
MarukuURL = 'http://maruku.rubyforge.org/' MarukuURL = 'http://maruku.rubyforge.org/'