Class: Prawn::Markup::Processor
- Inherits:
-
Nokogiri::XML::SAX::Document
- Object
- Nokogiri::XML::SAX::Document
- Prawn::Markup::Processor
- Defined in:
- lib/prawn/markup/processor.rb
Overview
Processes known HTML tags. Unknown tags are ignored.
Defined Under Namespace
Modules: Blocks, Headings, Images, Inputs, Lists, Tables, Text Classes: Error
Constant Summary
Constants included from Images
Constants included from Inputs
Inputs::DEFAULT_CHECKABLE_CHARS
Class Method Summary collapse
Instance Method Summary collapse
- #characters(string) ⇒ Object
- #end_element(name) ⇒ Object
- #error(string) ⇒ Object
-
#initialize(pdf, options = {}) ⇒ Processor
constructor
A new instance of Processor.
- #parse(html) ⇒ Object
- #start_element(name, attrs = []) ⇒ Object
- #warning(string) ⇒ Object
Methods included from Text
#append_color_tag, #default_link_options, #end_a, #end_b, #end_color, #end_font, #end_i, #end_strikethrough, #end_sub, #end_sup, #end_u, #link_options, prepended, #start_a, #start_b, #start_color, #start_font, #start_i, #start_strikethrough, #start_sub, #start_sup, #start_u
Methods included from Blocks
#end_div, #end_document, #end_p, prepended, #start_br, #start_div, #start_hr, #start_p
Methods included from Headings
#end_heading, prepended, #start_heading
Methods included from Images
prepended, #start_iframe, #start_img
Methods included from Inputs
Methods included from Tables
#end_table, #end_td, prepended, #start_img, #start_table, #start_td, #start_th, #start_tr
Methods included from Lists
#end_li, #end_list, prepended, #start_img, #start_li, #start_list, #start_ol, #start_ul
Constructor Details
#initialize(pdf, options = {}) ⇒ Processor
Returns a new instance of Processor.
41 42 43 44 45 |
# File 'lib/prawn/markup/processor.rb', line 41 def initialize(pdf, = {}) super() @pdf = pdf @options = end |
Class Method Details
.known_elements ⇒ Object
10 11 12 |
# File 'lib/prawn/markup/processor.rb', line 10 def known_elements @@known_elments ||= [] end |
.logger ⇒ Object
14 15 16 |
# File 'lib/prawn/markup/processor.rb', line 14 def logger @@logger end |
.logger=(logger) ⇒ Object
18 19 20 |
# File 'lib/prawn/markup/processor.rb', line 18 def logger=(logger) @@logger = logger end |
Instance Method Details
#characters(string) ⇒ Object
67 68 69 70 |
# File 'lib/prawn/markup/processor.rb', line 67 def characters(string) # entities will be replaced again later by inline_format append_text(string.gsub('&', '&').gsub('<', '<').gsub('>', '>')) end |
#end_element(name) ⇒ Object
62 63 64 65 |
# File 'lib/prawn/markup/processor.rb', line 62 def end_element(name) send("end_#{name}") if respond_to?("end_#{name}", true) stack.pop end |
#error(string) ⇒ Object
72 73 74 |
# File 'lib/prawn/markup/processor.rb', line 72 def error(string) logger.info("SAX parsing error: #{string.strip}") if logger end |
#parse(html) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/prawn/markup/processor.rb', line 47 def parse(html) return if html.to_s.strip.empty? reset html = Prawn::Markup::Normalizer.new(html).normalize Nokogiri::HTML::SAX::Parser.new(self, html.encoding&.to_s).parse(html) do |ctx| ctx.recovery = true end end |
#start_element(name, attrs = []) ⇒ Object
57 58 59 60 |
# File 'lib/prawn/markup/processor.rb', line 57 def start_element(name, attrs = []) stack.push(name: name, attrs: attrs.to_h) send("start_#{name}") if known_element?(name) && respond_to?("start_#{name}", true) end |
#warning(string) ⇒ Object
76 77 78 |
# File 'lib/prawn/markup/processor.rb', line 76 def warning(string) logger.info("SAX parsing warning: #{string.strip}") if logger end |