Class: PublishingPlatformMarkdown::Document

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, options = {}) ⇒ Document

Returns a new instance of Document.



18
19
20
21
22
23
24
25
# File 'lib/publishing_platform_markdown.rb', line 18

def initialize(source, options = {})
  options = options.dup.deep_symbolize_keys
  @source = source ? source.dup : ""

  @allowed_elements = options.delete(:allowed_elements) || []
  @options = { sanitize: true,
               syntax_highlighter: nil }.merge(options)
end

Class Method Details

.to_html(source, options = {}) ⇒ Object



14
15
16
# File 'lib/publishing_platform_markdown.rb', line 14

def self.to_html(source, options = {})
  new(source, options).to_html
end

Instance Method Details

#to_htmlObject



27
28
29
30
31
32
33
34
# File 'lib/publishing_platform_markdown.rb', line 27

def to_html
  @to_html ||= if @options[:sanitize]
                 HtmlSanitizer.new(kramdown_doc.to_html)
                              .sanitize(allowed_elements: @allowed_elements)
               else
                 kramdown_doc.to_html
               end
end