LoginSignup
0

More than 1 year has passed since last update.

posted at

updated at

Jekyllでpostにあるマークダウンをレンダリングなしで出力したい

Jekyllはpostにあるマークダウンを{{ content }}にレンダリングして埋め込んでくれるのですが、このマークダウンをRAWデータとして埋め込みたいときの解決策

調べても出てこなかったので残しておきます。

やり方

なにもしない"無"のレンダラーを自作します。

_pluginsというフォルダを作ります。そこに適当なRubyファイルを作り、以下のコードを打ちます。

_plugins/unrendered.rb
class Jekyll::Converters::Markdown::ProcessorUnrendered
  def initialize(config)
  end
  def convert(content)
    content
  end
end

次に、_config.ymlでこのレンダラーを使うように設定します。

_config.yml
markdown: ProcessorUnrendered

以上です。

注意ですが、Front Matterは出力されません。
つまり、

---
layout: default
---

# Hello
[Google](https://google.com)

というファイルは

# Hello
[Google](https://google.com)

このように出力されます。

何に使うの?

スライド資料を作れるReveal.jsと組み合わせるときに使うといい感じになります。

slide.html
<div class="reveal">
  <div class="slides">
    <section data-markdown data-separator="^\r?\n---\r?\n$" data-separator-vertical="^\r?\n--\r?\n$">
      <script type="text/template">
        {{ content }}
      </script>
    </section>
  </div>
</div>

こんな感じで使う

参考にしたものなど

Markdown Options
公式のやつです。カスタムmarkdownプロセッサについて詳しく書かれています

以上

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
0