28 lines · 579 B · Ruby
RawDownload
module Docs  class Parser    attr_reader :title, :html     def initialize(content)      @content = content      @html = document? ? parse_as_document : parse_as_fragment    end     private     DOCUMENT_RGX = /\A(?:\s|(?:<!--.*?-->))*<(?:\!doctype|html)/i     def document?      @content =~ DOCUMENT_RGX    end     def parse_as_document      document = Nokogiri::HTML.parse @content, nil, 'UTF-8'      @title = document.at_css('title').try(:content)      document    end     def parse_as_fragment      Nokogiri::HTML.fragment @content, 'UTF-8'    end  endend

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t