LoginSignup
1
1

More than 5 years have passed since last update.

grunt-contrib-jadeでmarkdownフィルタを使う

Posted at

grunt-contrib-jadeと一緒にmarked, supermarked, markdown-js, markdownのいずれか一つをインストールするだけ。

Terminal
$ npm install grunt-contrib-jade marked
Gruntfile.coffee
module.exports = (grunt) ->

  grunt.initConfig

    jade:
      compile:
        files: [
          dest: './'
          expand: true
          ext: '.html'
          flatten: true
          src: '*.jade'
        ]

  grunt.loadNpmTasks 'grunt-contrib-jade'

  return

あとはフィルタを指定してMarkdownで書くと、フィルタの部分がMarkdownで解釈され、出力される。

index.jade
doctype 5

:markdown
  # h1

  aaa

      $ echo 1
Terminal
$ grunt jade
index.html
<!DOCTYPE html><h1 id="h1">h1</h1>
<p>aaa</p>
<pre><code>$ echo 1</code></pre>

あとincludeでもMarkdownが使えるみたい。これもmarkedなどがインストールされていないとコンパイルできない。

index.jade
doctype 5

include aaa.md

ちなみに、ちゃんと拡張子を指定して書かないと(include aaaと拡張子を省略すると)aaa.jadeと解釈されてしまうので注意が必要。

aaa.md
# aaa

## bbb

    $ echo 1
index.html
<!DOCTYPE html><h1 id="aaa">aaa</h1>
<h2 id="bbb">bbb</h2>
<pre><code>$ echo 1</code></pre>

Jade便利だなー。

1
1
0

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
  3. You can use dark theme
What you can do with signing up
1
1