'How can I access un-rendered (markdown) content in Jekyll with liquid tags?

From reading the documentation Jekyll's template data one might think that the way to access un-rendered content would be page.content; but as far as I can tell, this is providing the content of the post as already rendered by the markdown parser.

I need a solution that accesses the raw (original markdown) content directly, rather than simply trying to convert the html back to markdown.

Background on use case

My use case is the following: I use the pandoc plugin to render markdown for my Jekyll site, using the 'mathjax' option to get pretty equations. However, mathjax requires javascript, so these do not display in the RSS feed, which I generate by looping over page.content like so:

 {% for post in site.posts %}
 <entry>
   <title>{{ post.title }}</title>
   <link href="{{ site.production_url }}{{ post.url }}"/>
   <updated>{{ post.date | date_to_xmlschema }}</updated>
   <id>{{ site.production_url }}{{ post.id }}</id>
   <content type="html">{{ post.content | xml_escape }}</content>
 </entry>
 {% endfor %}

As the xml_escape filter implies, post.content here appears in html. If I could get the raw content (imagine post.contentraw or such existed) then I could easily add a filter that would use pandoc with the "webtex" option to generate images for equations when parsing the RSS feed, e.g:

require 'pandoc-ruby'
module TextFilter
  def webtex(input)
    PandocRuby.new(input, "webtex").to_html
  end
end
Liquid::Template.register_filter(TextFilter)

But as I get content with the equations already rendered in html+mathjax instead of the raw markdown, I'm stuck. Converting back to markdown doesn't help, since it doesn't convert the mathjax (simply garbles it).

Any suggestions? Surely there's a way to call the raw markdown instead?



Solution 1:[1]

I ended up renaming my .md file to .html so they don't get rendered by the MarkDown renderer.

Solution 2:[2]

This should work.

# frozen_string_literal: true

module RawContent
  class Generator < Jekyll::Generator
    def generate(site)
      site.posts.docs.each do |post|
        post.data['raw_content'] = post.content
      end
    end
  end
end

Solution 3:[3]

Try using page.content!

For example,

---
layout: default
---

Markdown source:
<pre>
{{ page.content }}
</pre>

Rendered HTML
{{ content }}

See the Jekyll documentation's section on Liquid variables.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 FaXilifresh
Solution 2 Soptq
Solution 3