Class: Ghostwriter::Writer
- Inherits:
-
Object
- Object
- Ghostwriter::Writer
- Defined in:
- lib/ghostwriter/writer.rb
Overview
Main Ghostwriter converter object.
Instance Attribute Summary collapse
-
#heading_marker ⇒ Object
readonly
Returns the value of attribute heading_marker.
-
#link_base ⇒ Object
readonly
Returns the value of attribute link_base.
-
#ol_marker ⇒ Object
readonly
Returns the value of attribute ol_marker.
-
#table_column ⇒ Object
readonly
Returns the value of attribute table_column.
-
#table_corner ⇒ Object
readonly
Returns the value of attribute table_corner.
-
#table_row ⇒ Object
readonly
Returns the value of attribute table_row.
-
#ul_marker ⇒ Object
readonly
Returns the value of attribute ul_marker.
Instance Method Summary collapse
-
#initialize(link_base: '', heading_marker: '--', ul_marker: '-', ol_marker: '1', table_column: '|', table_row: '-', table_corner: '|') ⇒ Writer
constructor
Creates a new ghostwriter.
-
#textify(html) ⇒ Object
Strips HTML down to plain text.
Constructor Details
#initialize(link_base: '', heading_marker: '--', ul_marker: '-', ol_marker: '1', table_column: '|', table_row: '-', table_corner: '|') ⇒ Writer
Creates a new ghostwriter
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/ghostwriter/writer.rb', line 11 def initialize(link_base: '', heading_marker: '--', ul_marker: '-', ol_marker: '1', table_column: '|', table_row: '-', table_corner: '|') @link_base = link_base @heading_marker = heading_marker @ul_marker = ul_marker @ol_marker = ol_marker @table_column = table_column @table_row = table_row @table_corner = table_corner freeze end |
Instance Attribute Details
#heading_marker ⇒ Object (readonly)
Returns the value of attribute heading_marker.
6 7 8 |
# File 'lib/ghostwriter/writer.rb', line 6 def heading_marker @heading_marker end |
#link_base ⇒ Object (readonly)
Returns the value of attribute link_base.
6 7 8 |
# File 'lib/ghostwriter/writer.rb', line 6 def link_base @link_base end |
#ol_marker ⇒ Object (readonly)
Returns the value of attribute ol_marker.
6 7 8 |
# File 'lib/ghostwriter/writer.rb', line 6 def ol_marker @ol_marker end |
#table_column ⇒ Object (readonly)
Returns the value of attribute table_column.
6 7 8 |
# File 'lib/ghostwriter/writer.rb', line 6 def table_column @table_column end |
#table_corner ⇒ Object (readonly)
Returns the value of attribute table_corner.
6 7 8 |
# File 'lib/ghostwriter/writer.rb', line 6 def table_corner @table_corner end |
#table_row ⇒ Object (readonly)
Returns the value of attribute table_row.
6 7 8 |
# File 'lib/ghostwriter/writer.rb', line 6 def table_row @table_row end |
#ul_marker ⇒ Object (readonly)
Returns the value of attribute ul_marker.
6 7 8 |
# File 'lib/ghostwriter/writer.rb', line 6 def ul_marker @ul_marker end |
Instance Method Details
#textify(html) ⇒ Object
Strips HTML down to plain text.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ghostwriter/writer.rb', line 29 def textify(html) doc = Nokogiri::HTML(html.gsub(/\s+/, ' ')) doc.search('style, script').remove replace_anchors(doc) replace_images(doc) simple_replace(doc, '*[role="presentation"]', "\n") replace_headers(doc) replace_lists(doc) replace_tables(doc) simple_replace(doc, 'hr', "\n----------\n\n") simple_replace(doc, 'br', "\n") simple_replace(doc, 'p', "\n\n") normalize_lines(doc) end |