Merge pull request #4323 from pathawks/smartypants

Merge pull request 4323
This commit is contained in:
jekyllbot 2016-01-09 16:19:43 -08:00
commit 15eaefa337
3 changed files with 73 additions and 0 deletions

View File

@ -0,0 +1,34 @@
class Kramdown::Parser::SmartyPants < Kramdown::Parser::Kramdown
def initialize(source, options)
super
@block_parsers = [:block_html]
@span_parsers = [:smart_quotes, :html_entity, :typographic_syms, :span_html]
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) 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.

View File

@ -31,6 +31,34 @@ 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
context "smartify filter" do
should "convert quotes and typographic characters" 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 "escapes special characters when configured to do so" do
kramdown = JekyllFilter.new({:kramdown => {:entity_output => :symbolic}})
assert_equal "&ldquo;This filter&rsquo;s test&hellip;&rdquo;", kramdown.smartify(%q{"This filter's test..."})
end
should "convert HTML entities to unicode characters" do
assert_equal "", @filter.smartify("&rsquo;")
assert_equal "", @filter.smartify("&ldquo;")
end
should "allow raw HTML passthrough" do
assert_equal "Span HTML is <em>not</em> escaped", @filter.smartify("Span HTML is <em>not</em> escaped")
assert_equal "<div>Block HTML is not escaped</div>", @filter.smartify("<div>Block HTML is not escaped</div>")
end
should "escape special characters" do
assert_equal "3 &lt; 4", @filter.smartify("3 < 4")
assert_equal "5 &gt; 4", @filter.smartify("5 > 4")
assert_equal "This &amp; that", @filter.smartify("This & that")
end
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