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>"
e.instance_variable_set :@parsed_html,
REXML::Document.new(raw_html)
rescue
rescue #Exception => ex
e.instance_variable_set :@parsed_html, nil
# tell_user "Malformed block of HTML:\n"+
# add_tabs(raw_html,1,'|')
# " #{raw_html.inspect}\n\n"+ex.inspect

View file

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

View file

@ -237,6 +237,10 @@ module MaRuKu; module In; module Markdown; module BlockLevelParser
ex = e.inspect + e.backtrace.join("\n")
maruku_error "Bad block-level HTML:\n#{add_tabs(ex,1,'|')}\n", src
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
return md_html(raw_html)
end
@ -246,7 +250,7 @@ module MaRuKu; module In; module Markdown; module BlockLevelParser
while src.cur_line
# :olist does not break
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
when :olist,:ulist
break if src.next_line.md_type == t
@ -349,6 +353,7 @@ module MaRuKu; module In; module Markdown; module BlockLevelParser
# collect all indented lines
saw_empty = false; saw_anything_after = false
while src.cur_line
# puts "Reading indent = #{indentation} #{src.cur_line.inspect}"
#puts "#{src.cur_line.md_type} #{src.cur_line.inspect}"
if src.cur_line.md_type == :empty
saw_empty = true
@ -365,7 +370,9 @@ module MaRuKu; module In; module Markdown; module BlockLevelParser
end
saw_anything_after = true
else
# if src.cur_line[0] != ?\
break if break_list.include? src.cur_line.md_type
# end
# break if src.cur_line.md_type != :text
end

View file

@ -451,22 +451,35 @@ module MaRuKu; module In; module Markdown; module SpanLevelParser
h = HTMLHelper.new
begin
# This is our current buffer in the context
start = src.current_remaining_buffer
next_stuff = src.current_remaining_buffer
h.eat_this start
if not h.is_finished?
error "inline_html: Malformed:\n "+
"#{start.inspect}\n #{h.inspect}",src,con
consumed = 0
while true
h.eat_this next_stuff[consumed].chr; consumed += 1
break if h.is_finished?
if consumed >= next_stuff.size
maruku_error "Malformed HTML starting at #{next_stuff.inspect}", src, con
end
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
con.push_element md_html(h.stuff_you_read)
#start = src.current_remaining_buffer
# 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
maruku_error "Bad html: \n" +
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 :raw_html if l =~ %r{^[ ]?[ ]?[ ]?</?\s*\w+}
return :raw_html if l =~ %r{^[ ]?[ ]?[ ]?<\!\-\-}
return :ulist if l =~ /^\s?([\*\-\+])\s+.*\w+/
return :olist if l =~ /^\s?\d+\..*\w+/
# Something is wrong with how we parse lists! :-(
#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 :header2 if l =~ /^([-\s])+$/
return :header3 if l =~ /^(#)+\s*\S+/

View file

@ -75,7 +75,7 @@ module MaRuKu
slide_num += 1
@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.attributes['class'] = 'slide'

View file

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

View file

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