Class: Bridgetown::Converters::Markdown
- Inherits:
-
Bridgetown::Converter
- Object
- Plugin
- Bridgetown::Converter
- Bridgetown::Converters::Markdown
- Defined in:
- lib/bridgetown-core/converters/markdown.rb,
lib/bridgetown-core/converters/markdown/kramdown_parser.rb
Overview
Markdown converter. For more info on converters see https://bridgetownrb.com/docs/plugins/converters/
Defined Under Namespace
Classes: KramdownParser
Instance Method Summary collapse
-
#convert(content, convertible = nil) ⇒ Object
Logic to do the content conversion.
-
#get_processor ⇒ Object
RuboCop does not allow reader methods to have names starting with
get_
To ensure compatibility, this check has been disabled on this method. -
#initialize(config = {}) ⇒ Markdown
constructor
A new instance of Markdown.
- #setup ⇒ Object
-
#third_party_processors ⇒ Object
Public: A list of processors that you provide via plugins.
-
#valid_processors ⇒ Object
Public: Provides you with a list of processors comprised of the ones we support internally and the ones that you have provided to us.
Methods inherited from Bridgetown::Converter
#determine_template_engine, input, #inspect, #line_start, #matches, #output_ext, support_slots, supports_slots?, template_engine
Methods included from Prioritizable
Constructor Details
#initialize(config = {}) ⇒ Markdown
Returns a new instance of Markdown.
10 11 12 13 14 |
# File 'lib/bridgetown-core/converters/markdown.rb', line 10 def initialize(config = {}) super self.class.input @config["markdown_ext"].split(",") end |
Instance Method Details
#convert(content, convertible = nil) ⇒ Object
Logic to do the content conversion.
content - String content of file (without front matter).
Returns a String of the converted content.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/bridgetown-core/converters/markdown.rb', line 66 def convert(content, convertible = nil) setup if @cache @cache.getset(content) do @parser.convert(content) end else output = @parser.convert(content) if convertible && @parser.respond_to?(:extractions) convertible.data.markdown_extractions = @parser.extractions end output end end |
#get_processor ⇒ Object
RuboCop does not allow reader methods to have names starting with get_
To ensure compatibility, this check has been disabled on this method
rubocop:disable Naming/AccessorMethodName
37 38 39 40 41 42 43 |
# File 'lib/bridgetown-core/converters/markdown.rb', line 37 def get_processor case @config["markdown"].downcase when "kramdown" then KramdownParser.new(@config) else custom_processor end end |
#setup ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/bridgetown-core/converters/markdown.rb', line 16 def setup return if @setup ||= false unless (@parser = get_processor) Bridgetown.logger.error "Markdown processor:", "#{@config["markdown"].inspect} \ is not a valid Markdown processor." Bridgetown.logger.error "", "Available processors are: #{valid_processors.join(", ")}" Bridgetown.logger.error "" raise Errors::FatalException, "Invalid Markdown processor given: #{@config["markdown"]}" end unless @config.cache_markdown == false || @config.kramdown.input == "GFMExtractions" @cache = Bridgetown::Cache.new("Bridgetown::Converters::Markdown") end @setup = true end |
#third_party_processors ⇒ Object
Public: A list of processors that you provide via plugins.
Returns an array of symbols
57 58 59 |
# File 'lib/bridgetown-core/converters/markdown.rb', line 57 def third_party_processors self.class.constants - [:KramdownParser, :PRIORITIES] end |
#valid_processors ⇒ Object
Public: Provides you with a list of processors comprised of the ones we support internally and the ones that you have provided to us
Returns an array of symbols.
50 51 52 |
# File 'lib/bridgetown-core/converters/markdown.rb', line 50 def valid_processors [:kramdown] + third_party_processors end |