Class: PrawnHtml::HtmlParser
- Inherits:
-
Object
- Object
- PrawnHtml::HtmlParser
- Defined in:
- lib/prawn_html/html_parser.rb
Constant Summary collapse
- REGEXP_STYLES =
/\s*([^{\s]+)\s*{\s*([^}]*?)\s*}/m.freeze
Instance Method Summary collapse
-
#initialize(renderer, ignore_content_tags: %i[script style])) ⇒ HtmlParser
constructor
Init the HtmlParser.
-
#parse_styles(text_styles) ⇒ Object
Parses CSS styles.
-
#process(html) ⇒ Object
Processes HTML and renders it.
Constructor Details
#initialize(renderer, ignore_content_tags: %i[script style])) ⇒ HtmlParser
Init the HtmlParser
13 14 15 16 17 18 19 |
# File 'lib/prawn_html/html_parser.rb', line 13 def initialize(renderer, ignore_content_tags: %i[script style]) @processing = false @ignore = false @ignore_content_tags = @renderer = renderer @raw_styles = {} end |
Instance Method Details
#parse_styles(text_styles) ⇒ Object
Parses CSS styles
36 37 38 |
# File 'lib/prawn_html/html_parser.rb', line 36 def parse_styles(text_styles) @raw_styles = text_styles.scan(REGEXP_STYLES).to_h end |
#process(html) ⇒ Object
Processes HTML and renders it
24 25 26 27 28 29 30 31 |
# File 'lib/prawn_html/html_parser.rb', line 24 def process(html) @styles = {} @processing = !html.include?('<body') @document = Oga.parse_html(html) process_styles # apply previously loaded styles traverse_nodes(document.children) renderer.flush end |