diff --git a/features/highlighting.feature b/features/highlighting.feature index c9f2b00a..09d7af57 100644 --- a/features/highlighting.feature +++ b/features/highlighting.feature @@ -31,3 +31,47 @@ Feature: Syntax Highlighting When I run jekyll build Then I should get a zero exit-status And I should see "RewriteCond" in "_site/index.html" + + Scenario: highlighting an Liquid example + Given I have an "inspect.md" file with content: + """ + --- + title: Inspect Filter + --- + You can inspect a page's attributes with the `inspect` filter. You may enclose the + entire introspection within `
` tags to preserve the formatting:
+    {% highlight html %}
+    
+      {{ page | inspect }}
+    
+ {% endhighlight %} + """ + When I run jekyll build + Then I should get a zero exit-status + And I should see "" in "_site/inspect.html" + And I should see "{{ page | inspect }}" in "_site/inspect.html" + + Scenario: highlighting an included snippet + Given I have an _includes directory + And I have an "_includes/inspector.html" file with content: + """ +
+      {{ page | inspect }}
+    
+ """ + And I have an "inspect.md" file with content: + """ + --- + title: Inspect Filter + --- + You can inspect a page's attributes with the `inspect` filter. You may enclose the + entire introspection within `
` tags to preserve the formatting:
+    {% highlight html %}
+      {% include inspector.html %}
+    {% endhighlight %}
+    """
+    When I run jekyll build
+    Then I should get a zero exit-status
+    And I should see "" in "_site/inspect.html"
+    But I should not see "{{ page | inspect }}" in "_site/inspect.html"
+    But I should see "{% include inspector.html %}" in "_site/inspect.html"
diff --git a/jekyll.gemspec b/jekyll.gemspec
index 65ae9667..5ac0828b 100644
--- a/jekyll.gemspec
+++ b/jekyll.gemspec
@@ -52,6 +52,13 @@ Gem::Specification.new do |s|
       * Our `link` tag now comes with the `relative_url` filter incorporated into it.
         You should no longer prepend `{{ site.baseurl }}` to `{% link foo.md %}`
         For further details: https://github.com/jekyll/jekyll/pull/6727
+
+      * Our `highlight` tag no longer parses Liquid and Liquid-like constructs in the
+        tag's content body. While this means you no longer need to enclose the content
+        within a `{% raw %}{% endraw %}` block, it also means that you can no longer
+        do the following as well:
+        `{% highlight html %}{% include snippet.html %}{% endhighlight %}`
+        For further details: https://github.com/jekyll/jekyll/pull/6821
     ----------------------------------------------------------------------------------
   MSG
 end
diff --git a/lib/jekyll/tags/highlight.rb b/lib/jekyll/tags/highlight.rb
index 51ebe470..a9310b32 100644
--- a/lib/jekyll/tags/highlight.rb
+++ b/lib/jekyll/tags/highlight.rb
@@ -2,7 +2,7 @@
 
 module Jekyll
   module Tags
-    class HighlightBlock < Liquid::Block
+    class HighlightBlock < Liquid::Raw
       include Liquid::StandardFilters
 
       # The regular expression syntax checker. Start with the language specifier.
@@ -28,10 +28,12 @@ module Jekyll
         end
       end
 
+      LEADING_OR_TRAILING_LINE_TERMINATORS = %r!\A(\n|\r)+|(\n|\r)+\z!.freeze
+
       def render(context)
         prefix = context["highlighter_prefix"] || ""
         suffix = context["highlighter_suffix"] || ""
-        code = super.to_s.gsub(%r!\A(\n|\r)+|(\n|\r)+\z!, "")
+        code   = @body.gsub(LEADING_OR_TRAILING_LINE_TERMINATORS, "")
 
         output =
           case context.registers[:site].highlighter
@@ -101,6 +103,8 @@ module Jekyll
         "
"\
         "#{code.chomp}
" end + + def ensure_valid_markup(tag_name, markup, parse_context); end end end end diff --git a/test/test_tags.rb b/test/test_tags.rb index 59cd190d..3c54a7f0 100644 --- a/test/test_tags.rb +++ b/test/test_tags.rb @@ -69,6 +69,30 @@ class TestTags < JekyllUnitTest end end + context "highlight tag" do + setup do + create_post <<~CONTENT + --- + title: This is a test + --- + + This is not yet highlighted + + {% highlight html %} +

{% unregistered_tag %}

+ {{ page | inspect }} + {% endhighlight %} + + This should not be highlighted, right? + CONTENT + end + + should "not parse Liquid constructs in the tag markup" do + assert_match "{% unregistered_tag %}", @result + assert_match "{{ page | inspect }}", @result + end + end + context "highlight tag in unsafe mode" do should "set the no options with just a language name" do tag = highlight_block_with_opts("ruby ")