LoginSignup
9
9

More than 5 years have passed since last update.

nkfとhtml2jadeで大量のhtmlをpug(jade)に一括変換する

Last updated at Posted at 2016-04-21

リニューアル案件で古いhtmlに修正加える際に必要になりました。

require

ツール 用途
html2jade
nkf(Network Kanji Filter) Shift-JISの場合にのみ必要
rename 拡張子を.jadeから.pugに変換する用
terminal
:terminal

brew install nkf rename
npm install -g html2jade

utf-8に変換後、html2jadeを実行

sjisファイルが文字化けしたので、最初にutf-8に変換しました。
最後にrenameコマンドで拡張子をpugに変換する。
(必要ならpugからhtml出力した際にgulp-endodeなどで再びsjisに戻します。)

terminal
find . -type f -exec nkf -w --overwrite {} \;
html2jade -t --donotencode --noemptypipe ./*.html && find . -name "*jade*" | xargs rename -s .jade .pug

html2jade option

オプション 作用
-d, --double 属性値をダブルクォートで囲う
-o, --outdir <dir> jadeファイルを格納するディレクトリを指定(先に用意しておく必用がある)
-n, --nspaces <n> インデントサイズを指定(初期値は2スペース)
-t, --tabs タブ・インデントにする
--donotencode 特殊文字を実体参照エンコードしない(日本語が使用されているhtmlでは必須オプション)
--bodyless html, body タグを差し込まない
--numeric 数値参照を使用する
-s, --scalate Scalate用シンタックスで生成
--noattrcomma 属性間カンマを省略する
--noemptypipe 空行を要素の内容として"| 〜"に変換する

参考

http://qiita.com/seanchas_t/items/bd024a46115564c69806

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