Add smartify filter

This commit is contained in:
Pat Hawks 2016-01-07 02:36:24 -08:00
parent 7eefa0ffd7
commit acb2263f51
No known key found for this signature in database
GPG Key ID: F1746FF5F18B3D1B
3 changed files with 50 additions and 0 deletions

View File

@ -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

View File

@ -15,6 +15,17 @@ module Jekyll
converter.convert(input)
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.
#
# input - The Sass String to convert.

View File

@ -31,6 +31,11 @@ class TestFilters < JekyllUnitTest
assert_equal "<p>something <strong>really</strong> simple</p>\n", @filter.markdownify("something **really** simple")
end
should "smartify with simple string" do
assert_equal "SmartyPants is *not* Markdown", @filter.smartify("SmartyPants is *not* Markdown")
assert_equal "“This filters test…”", @filter.smartify(%q{"This filter's test..."})
end
should "sassify with simple string" do
assert_equal "p {\n color: #123456; }\n", @filter.sassify("$blue:#123456\np\n color: $blue")
end