Class: MarkDon::Converter

Inherits:
Object
  • Object
show all
Defined in:
lib/mark_don/converter.rb

Constant Summary collapse

STRIP_TAGS =
%w[script style meta link].freeze

Class Method Summary collapse

Class Method Details

.convert(html) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/mark_don/converter.rb', line 8

def self.convert(html)
  doc = Nokogiri::HTML(html)
  STRIP_TAGS.each { |tag| doc.css(tag).remove }
  doc.css('[data-markdown-ignore]').remove

  root = doc.at('[data-markdown-main]') || doc.at('body') || doc
  ReverseMarkdown.convert(root.inner_html, unknown_tags: :bypass, github_flavored: true).strip
end