Document converter methods (#7289)

Merge pull request 7289
This commit is contained in:
Grzegorz Kaczorek 2018-10-01 20:37:15 +02:00 committed by jekyllbot
parent 452c1c88d0
commit 55dd39d580
3 changed files with 54 additions and 0 deletions

View File

@ -2,19 +2,37 @@
module Jekyll module Jekyll
module Converters module Converters
# Identify converter. Returns same content as given.
# For more info on converters see https://jekyllrb.com/docs/plugins/converters/
class Identity < Converter class Identity < Converter
safe true safe true
priority :lowest priority :lowest
# Public: Does the given extension match this converter's list of acceptable extensions?
# Takes one argument: the file's extension (including the dot).
#
# ext - The String extension to check (not relevant here)
#
# Returns true since it always matches.
def matches(_ext) def matches(_ext)
true true
end end
# Public: The extension to be given to the output file (including the dot).
#
# ext - The String extension or original file.
#
# Returns The String output file extension.
def output_ext(ext) def output_ext(ext)
ext ext
end end
# Logic to do the content conversion.
#
# content - String content of file (without front matter).
#
# Returns a String of the converted content.
def convert(content) def convert(content)
content content
end end

View File

@ -2,6 +2,8 @@
module Jekyll module Jekyll
module Converters module Converters
# Markdown converter.
# For more info on converters see https://jekyllrb.com/docs/plugins/converters/
class Markdown < Converter class Markdown < Converter
highlighter_prefix "\n" highlighter_prefix "\n"
highlighter_suffix "\n" highlighter_suffix "\n"
@ -61,14 +63,30 @@ module Jekyll
end end
end end
# Does the given extension match this converter's list of acceptable extensions?
# Takes one argument: the file's extension (including the dot).
#
# ext - The String extension to check.
#
# Returns true if it matches, false otherwise.
def matches(ext) def matches(ext)
extname_list.include?(ext.downcase) extname_list.include?(ext.downcase)
end end
# Public: The extension to be given to the output file (including the dot).
#
# ext - The String extension or original file.
#
# Returns The String output file extension.
def output_ext(_ext) def output_ext(_ext)
".html" ".html"
end end
# Logic to do the content conversion.
#
# content - String content of file (without front matter).
#
# Returns a String of the converted content.
def convert(content) def convert(content)
setup setup
@parser.convert(content) @parser.convert(content)

View File

@ -19,6 +19,8 @@ end
module Jekyll module Jekyll
module Converters module Converters
# SmartyPants converter.
# For more info on converters see https://jekyllrb.com/docs/plugins/converters/
class SmartyPants < Converter class SmartyPants < Converter
safe true safe true
priority :low priority :low
@ -29,14 +31,30 @@ module Jekyll
@config[:input] = :SmartyPants @config[:input] = :SmartyPants
end end
# Does the given extension match this converter's list of acceptable extensions?
# Takes one argument: the file's extension (including the dot).
#
# ext - The String extension to check.
#
# Returns true if it matches, false otherwise.
def matches(_) def matches(_)
false false
end end
# Public: The extension to be given to the output file (including the dot).
#
# ext - The String extension or original file.
#
# Returns The String output file extension.
def output_ext(_) def output_ext(_)
nil nil
end end
# Logic to do the content conversion.
#
# content - String content of file (without front matter).
#
# Returns a String of the converted content.
def convert(content) def convert(content)
document = Kramdown::Document.new(content, @config) document = Kramdown::Document.new(content, @config)
html_output = document.to_html.chomp html_output = document.to_html.chomp