Class: Turndown::Converter
- Inherits:
-
Object
- Object
- Turndown::Converter
- Defined in:
- lib/turndown/converter.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Instance Method Summary collapse
- #add_rule(name, filter:, replacement:, append: nil) ⇒ Object
- #convert(input) ⇒ Object
- #escape(string) ⇒ Object
-
#initialize(options = {}) ⇒ Converter
constructor
A new instance of Converter.
- #keep(filter) ⇒ Object
- #remove(filter) ⇒ Object
- #use(plugin) ⇒ Object
Constructor Details
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/turndown/converter.rb', line 5 def @options end |
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
5 6 7 |
# File 'lib/turndown/converter.rb', line 5 def rules @rules end |
Instance Method Details
#add_rule(name, filter:, replacement:, append: nil) ⇒ Object
33 34 35 36 |
# File 'lib/turndown/converter.rb', line 33 def add_rule(name, filter:, replacement:, append: nil) rules.add(name, Rule.new(filter: filter, replacement: replacement, append: append)) self end |
#convert(input) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/turndown/converter.rb', line 13 def convert(input) raise TypeError, "#{input} is not a string, or an element/document/fragment node." unless can_convert?(input) return "" if input == "" output = process(RootNode.build(input, )) post_process(output) end |
#escape(string) ⇒ Object
48 49 50 |
# File 'lib/turndown/converter.rb', line 48 def escape(string) Utilities.escape_markdown(string) end |
#keep(filter) ⇒ Object
38 39 40 41 |
# File 'lib/turndown/converter.rb', line 38 def keep(filter) rules.keep(filter) self end |
#remove(filter) ⇒ Object
43 44 45 46 |
# File 'lib/turndown/converter.rb', line 43 def remove(filter) rules.remove(filter) self end |
#use(plugin) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/turndown/converter.rb', line 21 def use(plugin) if plugin.is_a?(Array) plugin.each { |entry| use(entry) } elsif plugin.respond_to?(:call) plugin.call(self) else raise TypeError, "plugin must be a callable or an Array of callables" end self end |