Skip to content

Instantly share code, notes, and snippets.

@phaer
Created June 11, 2011 19:11
Show Gist options
  • Save phaer/1020852 to your computer and use it in GitHub Desktop.
Save phaer/1020852 to your computer and use it in GitHub Desktop.
Raw tag for jekyll. Keeps liquid from parsing text betweeen {% raw %} and {% endraw %}
module Jekyll
class RawTag < Liquid::Block
def parse(tokens)
@nodelist ||= []
@nodelist.clear
while token = tokens.shift
if token =~ FullToken
if block_delimiter == $1
end_tag
return
end
end
@nodelist << token if not token.empty?
end
end
end
end
Liquid::Template.register_tag('raw', Jekyll::RawTag)
@phaer
Copy link
Author

phaer commented Jun 13, 2011

titanous added it to shopify's liquid fork and wrote a test for it: https://github.com/Shopify/liquid/blob/4087a94d881c53b803f1d682db7e4676a6f4d714/test/lib/liquid/tags/raw_test.rb

require 'test_helper'

class RawTest < Test::Unit::TestCase
include Liquid

  def test_tag_in_raw
    assert_template_result '{% comment %} test {% endcomment %}',
                           '{% raw %}{% comment %} test {% endcomment %}{% endraw %}'
  end

  def test_output_in_raw
    assert_template_result '{{ test }}',
                           '{% raw %}{{ test }}{% endraw %}'
  end
end

Thanks!

@marcysutton
Copy link

Does this work with Sass in Jekyll 2x?

@xoyabc
Copy link

xoyabc commented Jun 20, 2018

jekyll/jekyll#6217

<div no-ui-slider
     slider-options="{{ optionsWithoutStart }}"
     ng-model="sliderPositions"></div>

@JonnoFTW
Copy link

JonnoFTW commented Nov 6, 2018

I get an error using this when trying to run locally:

$ sudo jekyll serve
Configuration file: /scratch/Dropbox/jonnoftw.github.com/_config.yml
            Source: /scratch/Dropbox/jonnoftw.github.com
       Destination: /scratch/Dropbox/jonnoftw.github.com/_site
 Incremental build: disabled. Enable with --incremental
      Generating... 
  Liquid Exception: uninitialized constant Jekyll::RawTag::FullToken in /scratch/Dropbox/jonnoftw.github.com/_posts/2018-08-29-distributed-hyperparameter-optimisation-with-kerashyperashyperopt.md
jekyll 3.8.5 | Error:  uninitialized constant Jekyll::RawTag::FullToken

@Stratus3D
Copy link

I get the same error as @JonnoFTW after upgrading to Jekyll 3. My guess is the class name in Jekyll or Liquid changed.

@phaer
Copy link
Author

phaer commented Jun 30, 2019

This gist is a bit over 8 years old, which is quite some time in software development. Please take the discussion to liquid and see if it's still supported there. I've long stopped using liquid as well as jekyll myself.

@Stratus3D
Copy link

Turned out Jekyll 3 has the raw tag built in, so this code isn't needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment