class Utopia::Content::MarkupParser
Provides a high level interface for parsing markup.
Public Class Methods
new(buffer, delegate, entities = Trenni::Entities::HTML5)
click to toggle source
# File lib/utopia/content/markup.rb, line 111 def initialize(buffer, delegate, entities = Trenni::Entities::HTML5) @buffer = buffer @delegate = delegate @entities = entities @current = nil @stack = [] end
parse(buffer, delegate, entities = Trenni::Entities::HTML5)
click to toggle source
# File lib/utopia/content/markup.rb, line 104 def self.parse(buffer, delegate, entities = Trenni::Entities::HTML5) # This is for compatibility with the existing API which passes in a string: buffer = Trenni::Buffer(buffer) self.new(buffer, delegate, entities).parse! end
Public Instance Methods
attribute(key, value)
click to toggle source
# File lib/utopia/content/markup.rb, line 133 def attribute(key, value) @current.tag.attributes[key] = value end
cdata(string)
click to toggle source
# File lib/utopia/content/markup.rb, line 172 def cdata(string) @delegate.write(string) end
close_tag(name, offset)
click to toggle source
# File lib/utopia/content/markup.rb, line 149 def close_tag(name, offset) @current = @stack.pop tag = @current.tag if tag.name != name raise UnbalancedTagError.new(@buffer, @current, ParsedTag.new(name, offset)) end @delegate.tag_end(tag) end
comment(string)
click to toggle source
# File lib/utopia/content/markup.rb, line 164 def comment(string) @delegate.write(string) end
doctype(string)
click to toggle source
# File lib/utopia/content/markup.rb, line 160 def doctype(string) @delegate.write(string) end
instruction(string)
click to toggle source
# File lib/utopia/content/markup.rb, line 168 def instruction(string) @delegate.write(string) end
open_tag_begin(name, offset)
click to toggle source
# File lib/utopia/content/markup.rb, line 129 def open_tag_begin(name, offset) @current = ParsedTag.new(name, offset) end
open_tag_end(self_closing)
click to toggle source
# File lib/utopia/content/markup.rb, line 137 def open_tag_end(self_closing) if self_closing @current.tag.closed = true @delegate.tag_complete(@current.tag) else @stack << @current @delegate.tag_begin(@current.tag) end @current = nil end
parse!()
click to toggle source
# File lib/utopia/content/markup.rb, line 121 def parse! Trenni::Parsers.parse_markup(@buffer, self, @entities) if tag = @stack.pop raise UnbalancedTagError.new(@buffer, tag) end end
text(string)
click to toggle source
# File lib/utopia/content/markup.rb, line 176 def text(string) @delegate.text(string) end