Compare commits

...

4 Commits

Author SHA1 Message Date
Pat Hawks
b0c591a3f2 Add Inline Markdown converter 2016-10-27 20:30:32 -05:00
David Stosik
167af4552b Avoid modifying existing test's behavior in my PR 2016-10-24 01:03:53 +09:00
David Stosik
3cc4bef2e6 Fix Rubocop errors 2016-10-24 00:39:09 +09:00
David Stosik
4785f6f71f Provide an "inline" mode to markdownify filter 2016-10-24 00:01:09 +09:00
5 changed files with 69 additions and 2 deletions

View File

@@ -39,6 +39,8 @@ Metrics/MethodLength:
Max: 20
Severity: error
Metrics/ModuleLength:
Exclude:
- lib/jekyll/filters.rb
Max: 240
Metrics/ParameterLists:
Max: 4

View File

@@ -63,6 +63,18 @@ Feature: Embed filters
And the _site directory should exist
And I should see "By <p><em>Obi-wan</em></p>" in "_site/2009/03/27/star-wars.html"
Scenario: Markdownify a given inline string
Given I have a _posts directory
And I have a _layouts directory
And I have the following post:
| title | date | layout | content |
| Star Wars | 2009-03-27 | default | These aren't the droids you're looking for. |
And I have a default layout that contains "By {{ '_Obi-wan_' | markdownify:'inline' }}"
When I run jekyll build
Then I should get a zero exit status
And the _site directory should exist
And I should see "By <em>Obi-wan</em>" in "_site/2009/03/27/star-wars.html"
Scenario: Sort by an arbitrary variable
Given I have a _layouts directory
And I have the following page:

View File

@@ -0,0 +1,35 @@
class Kramdown::Parser::Inline < Kramdown::Parser::Kramdown
def initialize(source, options)
super
@block_parsers = [:block_html].freeze
end
end
module Jekyll
module Converters
class Markdown
class Inline < Converter
safe true
priority :low
def initialize(config)
Jekyll::External.require_with_graceful_fail "kramdown"
@config = config["kramdown"].dup || {}
@config[:input] = :Inline
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
end

View File

@@ -13,9 +13,13 @@ module Jekyll
# input - The Markdown String to convert.
#
# Returns the HTML formatted String.
def markdownify(input)
def markdownify(input, mode = nil)
site = @context.registers[:site]
converter = site.find_converter_instance(Jekyll::Converters::Markdown)
if mode.to_s == "inline"
converter = site.find_converter_instance(Jekyll::Converters::Markdown::Inline)
else
converter = site.find_converter_instance(Jekyll::Converters::Markdown)
end
converter.convert(input.to_s)
end

View File

@@ -57,6 +57,20 @@ class TestFilters < JekyllUnitTest
)
end
should "markdownify with simple string in inline mode" do
assert_equal(
"one <em>simple</em> string",
@filter.markdownify("one _simple_ string", :inline)
)
end
should "markdownify with multi-line string in inline mode" do
assert_equal(
"first line\nsecond line",
@filter.markdownify("first line\n\nsecond line", :inline)
)
end
context "smartify filter" do
should "convert quotes and typographic characters" do
assert_equal(