Skip to content

Instantly share code, notes, and snippets.

@hyuki0000
Created February 22, 2014 07:44
Show Gist options
  • Save hyuki0000/9150132 to your computer and use it in GitHub Desktop.
Save hyuki0000/9150132 to your computer and use it in GitHub Desktop.
An Octopress plugin that renders the given content 'as is'.
# Input:
# {% verbatim tag:p %}
# $$a_1, a_2, a_3, \ldots$$
# {% endverbatim %}
#
# Output:
# <p>$$a_1, a_2, a_3, \ldots$$</p>
#
# Author: Hiroshi Yuki.
# Description: The content between {% verbatim %} and {% endverbatim %} would be rendered 'as is'.
# You can use 'tag' option to wrap the content.
# Purpose: To protect LaTeX (MathJax) content from markdown converter.
require './plugins/raw'
module Jekyll
class VerbatimBlock < Liquid::Block
include TemplateWrapper
def initialize(tag_name, markup, tokens)
@tag = nil
if markup =~ /\s*tag:(\S+)/i
@tag = $1
markup = markup.sub(/\s*tag:(\S+)/i,'')
end
super
end
def render(context)
output = super
content = "<#{@tag}>" if @tag
content += safe_wrap(output)
content += "</#{@tag}>" if @tag
return content
end
end
end
Liquid::Template.register_tag('verbatim', Jekyll::VerbatimBlock)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment