Avoid duplicated output using highlight tags
While using Rouge and an `highlight` tag, the output was duplicated since the `output` variable in the Liquid tag definition was equal to the highlighter's prefix value and the `<<` method changes its receiver. Therefore, we should simply define an empty string and append the prefix if it is present.
This commit is contained in:
parent
cdeaa154cd
commit
3a610882f6
|
@ -105,6 +105,15 @@ Feature: Site configuration
|
||||||
And I should see "Hello world!" in "_site/index.html"
|
And I should see "Hello world!" in "_site/index.html"
|
||||||
And I should see "class=\"highlight\"" in "_site/index.html"
|
And I should see "class=\"highlight\"" in "_site/index.html"
|
||||||
|
|
||||||
|
Scenario: Rouge renders code block once
|
||||||
|
Given I have a configuration file with "highlighter" set to "rouge"
|
||||||
|
And I have a _posts directory
|
||||||
|
And I have the following post:
|
||||||
|
| title | date | layout | content |
|
||||||
|
| foo | 2014-04-27 11:34 | default | {% highlight text %} test {% endhighlight %} |
|
||||||
|
When I run jekyll build
|
||||||
|
Then I should not see "highlight(.*)highlight" in "_site/2014/04/27/foo.html"
|
||||||
|
|
||||||
Scenario: Set time and no future dated posts
|
Scenario: Set time and no future dated posts
|
||||||
Given I have a _layouts directory
|
Given I have a _layouts directory
|
||||||
And I have a page layout that contains "Page Layout: {{ site.posts.size }} on {{ site.time | date: "%Y-%m-%d" }}"
|
And I have a page layout that contains "Page Layout: {{ site.posts.size }} on {{ site.time | date: "%Y-%m-%d" }}"
|
||||||
|
|
|
@ -165,7 +165,7 @@ Then /^the (.*) directory should not exist$/ do |dir|
|
||||||
end
|
end
|
||||||
|
|
||||||
Then /^I should see "(.*)" in "(.*)"$/ do |text, file|
|
Then /^I should see "(.*)" in "(.*)"$/ do |text, file|
|
||||||
assert_match Regexp.new(text), file_contents(file)
|
assert_match Regexp.new(text, Regexp::MULTILINE), file_contents(file)
|
||||||
end
|
end
|
||||||
|
|
||||||
Then /^I should see exactly "(.*)" in "(.*)"$/ do |text, file|
|
Then /^I should see exactly "(.*)" in "(.*)"$/ do |text, file|
|
||||||
|
@ -173,7 +173,7 @@ Then /^I should see exactly "(.*)" in "(.*)"$/ do |text, file|
|
||||||
end
|
end
|
||||||
|
|
||||||
Then /^I should not see "(.*)" in "(.*)"$/ do |text, file|
|
Then /^I should not see "(.*)" in "(.*)"$/ do |text, file|
|
||||||
assert_no_match Regexp.new(text), file_contents(file)
|
assert_no_match Regexp.new(text, Regexp::MULTILINE), file_contents(file)
|
||||||
end
|
end
|
||||||
|
|
||||||
Then /^I should see escaped "(.*)" in "(.*)"$/ do |text, file|
|
Then /^I should see escaped "(.*)" in "(.*)"$/ do |text, file|
|
||||||
|
|
|
@ -86,8 +86,9 @@ eos
|
||||||
formatter = Rouge::Formatters::HTML.new(line_numbers: linenos, wrap: false)
|
formatter = Rouge::Formatters::HTML.new(line_numbers: linenos, wrap: false)
|
||||||
|
|
||||||
pre = "<pre>#{formatter.format(lexer.lex(code))}</pre>"
|
pre = "<pre>#{formatter.format(lexer.lex(code))}</pre>"
|
||||||
|
output = ""
|
||||||
|
|
||||||
output = context["highlighter_prefix"] || ""
|
output << context["highlighter_prefix"] if context["highlighter_prefix"]
|
||||||
output << "<div class=\"highlight\">"
|
output << "<div class=\"highlight\">"
|
||||||
output << add_code_tags(pre, @lang)
|
output << add_code_tags(pre, @lang)
|
||||||
output << "</div>"
|
output << "</div>"
|
||||||
|
|
Loading…
Reference in New Issue