LoginSignup
5
5

More than 5 years have passed since last update.

コマンドラインで、Jade => HTML変換するワンライナー

Last updated at Posted at 2016-02-19

CLIでクリップボード上のJadeをHTMLに変換する。

毎度Web上( http://jade-lang.com/ )に変換しに行くのが少々だるいので、CLIで変換できるワンライナーを仕込んでみた。更に楽したいからクリップボードの内容を置き換える様にしておきました。jade2htmlとかにしてalias貼っておくとなお良。
Jadeで作ったAngular DirectiveのtemplateをJSXとかに変換していくときとかに使ってください。

必要な道具

$ pip install jsbeautifier

コマンド

$ pbpaste | jade | js-beautify -f - --html | pbcopy

Example

入力

doctype html
html(lang="en")
  head
    title= pageTitle
    script(type='text/javascript').
      if (foo) {
         bar(1 + 5)
      }
  body
    h1 Jade - node template engine
    #container.col
      if youAreUsingJade
        p You are amazing
      else
        p Get on it!
      p.
        Jade is a terse and simple
        templating language with a
        strong focus on performance
        and powerful features.

出力

<!DOCTYPE html>
<html lang="en">

<head>
    <title></title>
    <script type="text/javascript">
        if (foo) {
            bar(1 + 5)
        }
    </script>
</head>

<body>
    <h1>Jade - node template engine</h1>
    <div id="container" class="col">
        <p>Get on it!</p>
        <p>Jade is a terse and simple templating language with a strong focus on performance and powerful features.</p>
    </div>
</body>

</html>


メモ

ここの記事で--stdin オプション使えるよって書いてたんだけど、なくなってた。代わりに-f -としてファイルオプションに-ハイフンを渡すとstdinから出力を使える様に変わってた。

5
5
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
5
5