mirror of
https://github.com/jekyll/jekyll.git
synced 2026-04-28 03:01:03 -04:00
Compare commits
4 Commits
liquid5
...
pull/markd
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b0c591a3f2 | ||
|
|
167af4552b | ||
|
|
3cc4bef2e6 | ||
|
|
4785f6f71f |
@@ -39,6 +39,8 @@ Metrics/MethodLength:
|
||||
Max: 20
|
||||
Severity: error
|
||||
Metrics/ModuleLength:
|
||||
Exclude:
|
||||
- lib/jekyll/filters.rb
|
||||
Max: 240
|
||||
Metrics/ParameterLists:
|
||||
Max: 4
|
||||
|
||||
@@ -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:
|
||||
|
||||
35
lib/jekyll/converters/markdown/inline.rb
Normal file
35
lib/jekyll/converters/markdown/inline.rb
Normal 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
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user