Class: Bridgetown::Converters::Markdown::KramdownParser

Inherits:
Object
  • Object
show all
Defined in:
lib/bridgetown-core/converters/markdown/kramdown_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ KramdownParser

Returns a new instance of KramdownParser.



74
75
76
77
78
79
80
# File 'lib/bridgetown-core/converters/markdown/kramdown_parser.rb', line 74

def initialize(config)
  @config = config["kramdown"] || {}
  @config["syntax_highlighter"] ||= config["highlighter"] || "rouge"
  @config["syntax_highlighter_opts"] ||= {}
  @config["syntax_highlighter_opts"]["guess_lang"] = @config["guess_lang"]
  require_relative "../../kramdown/parser/gfm" if @config["input"] == "GFM"
end

Instance Attribute Details

#extractionsObject (readonly)

Returns the value of attribute extractions.



72
73
74
# File 'lib/bridgetown-core/converters/markdown/kramdown_parser.rb', line 72

def extractions
  @extractions
end

Instance Method Details

#convert(content) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
# File 'lib/bridgetown-core/converters/markdown/kramdown_parser.rb', line 82

def convert(content)
  document = Kramdown::BridgetownDocument.new(content, @config)
  html_output = document.to_html
  if @config["show_warnings"]
    document.warnings.each do |warning|
      Bridgetown.logger.warn "Kramdown warning:", warning
    end
  end
  @extractions = document.root.options[:extractions] # could be nil
  html_output
end