You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
devdocs/lib/docs/core/parser.rb

29 lines
490 B

require 'nokogiri'
module Docs
class Parser
def initialize(content)
@content = content
end
def html
@html ||= document? ? parse_as_document : parse_as_fragment
end
private
def document?
@content =~ /\A\s*<!doctype/i
end
def parse_as_document
document = Nokogiri::HTML.parse @content, nil, 'UTF-8'
document.at_css 'body'
end
def parse_as_fragment
Nokogiri::HTML.fragment @content, 'UTF-8'
end
end
end