Skip to content

Instantly share code, notes, and snippets.

@tadfmac
Last active Sep 2, 2016
Embed
What would you like to do?
指定path配下にある readme.mdをindex.htmlに変換
/*
markdown->html化
Usage : node out.js <対象path>
※<対象path>配下に設置してある readme.mdを再帰的にindex.htmlに変換します。
※<対象path>/github.css を適用します。
あらかじめ node.js、 pandocのインストールを行っておいてください
*/
var fs = require('fs');
var execSync = require('child_process').execSync;
var cssname = "github.css";
var rootpath = process.argv[2]; // 対象path
function readpath(path,depth){
fs.readdir(path,function(err,files){
if(files.length != 0){
for(var cnt=0;cnt < files.length; cnt++){
console.dir(files[cnt]);
var checkpath = path+'/'+files[cnt];
if(fs.statSync(checkpath).isDirectory()){
readpath(checkpath,depth+1);
}
if(files[cnt] == 'readme.md'){
var htmlpath = 'index.html';
var csspstr = cssname;
if(depth > 0){
for(var cnt2=0;cnt2 < depth;cnt2++){
csspstr = "../"+csspstr;
}
}else{
csspstr = "./"+csspstr;
}
console.log("css:"+csspstr);
var param = "pandoc readme.md -s --self-contained -t html5 -c "+csspstr+" -o index.html";
execSync(param,{cwd:path});
}
}
}
});
}
readpath(rootpath,0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment