Add smartify filter
This commit is contained in:
parent
7eefa0ffd7
commit
acb2263f51
|
|
@ -0,0 +1,34 @@
|
||||||
|
class Kramdown::Parser::SmartyPants < Kramdown::Parser::Kramdown
|
||||||
|
def initialize(source, options)
|
||||||
|
super
|
||||||
|
@block_parsers = []
|
||||||
|
@span_parsers = [:smart_quotes, :html_entity, :typographic_syms, :escaped_chars]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
module Jekyll
|
||||||
|
module Converters
|
||||||
|
class SmartyPants < Converter
|
||||||
|
safe true
|
||||||
|
priority :low
|
||||||
|
|
||||||
|
def initialize(config)
|
||||||
|
Jekyll::External.require_with_graceful_fail "kramdown"
|
||||||
|
@config = config["kramdown"].dup || {}
|
||||||
|
@config[:input] = :SmartyPants
|
||||||
|
end
|
||||||
|
|
||||||
|
def matches(_)
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
|
def output_ext(_)
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def convert(content)
|
||||||
|
Kramdown::Document.new(content, @config).to_html.chomp
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -15,6 +15,17 @@ module Jekyll
|
||||||
converter.convert(input)
|
converter.convert(input)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Convert a Markdown string into HTML output.
|
||||||
|
#
|
||||||
|
# input - The Markdown String to convert.
|
||||||
|
#
|
||||||
|
# Returns the HTML formatted String.
|
||||||
|
def smartify(input)
|
||||||
|
site = @context.registers[:site]
|
||||||
|
converter = site.find_converter_instance(Jekyll::Converters::SmartyPants)
|
||||||
|
converter.convert(input)
|
||||||
|
end
|
||||||
|
|
||||||
# Convert a Sass string into CSS output.
|
# Convert a Sass string into CSS output.
|
||||||
#
|
#
|
||||||
# input - The Sass String to convert.
|
# input - The Sass String to convert.
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,11 @@ class TestFilters < JekyllUnitTest
|
||||||
assert_equal "<p>something <strong>really</strong> simple</p>\n", @filter.markdownify("something **really** simple")
|
assert_equal "<p>something <strong>really</strong> simple</p>\n", @filter.markdownify("something **really** simple")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "smartify with simple string" do
|
||||||
|
assert_equal "SmartyPants is *not* Markdown", @filter.smartify("SmartyPants is *not* Markdown")
|
||||||
|
assert_equal "“This filter’s test…”", @filter.smartify(%q{"This filter's test..."})
|
||||||
|
end
|
||||||
|
|
||||||
should "sassify with simple string" do
|
should "sassify with simple string" do
|
||||||
assert_equal "p {\n color: #123456; }\n", @filter.sassify("$blue:#123456\np\n color: $blue")
|
assert_equal "p {\n color: #123456; }\n", @filter.sassify("$blue:#123456\np\n color: $blue")
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue