Skip to content

Instantly share code, notes, and snippets.

@na2hiro
Forked from anonymous/ParanoiaViewer.js
Created December 17, 2012 18:21
Show Gist options
  • Save na2hiro/4320572 to your computer and use it in GitHub Desktop.
Save na2hiro/4320572 to your computer and use it in GitHub Desktop.
var Iconv = require("iconv").Iconv, conv = new Iconv('shift_jis','UTF-8//TRANSLIT//IGNORE');
var fs = require("fs");
var filename = process.argv[2];
if(!filename) throw "need argument";
fs.readFile(filename, function (err, data) {
if (err) throw err;
var output="";
conv.convert(data).toString().split("¥n").forEach(function(line){
var elems = line.split('","');
if(elems.length<3) return;
var color = elems[3].match(/{#([0-9A-F]{6}):.*}/);
var size = elems[3].match(/{(¥d+):.*}/);
var comment = elems[3].replace(/{#([0-9A-F]{6}):(.*)}/, "$2").replace(/{¥d+:(.*)}/, "$1");
console.log(elems[1], comment, elems[4], color?"#"+color[1]:"", size?size[1]+"px":"")
var style="";
if(color) style+="color:#"+color[1]+";";
if(size) style+="font-size:"+size[1]+"px;";
output+="<div style='"+style+"'>"+elems[1]+"> "+comment+"<time>"+elems[4]+"</time>"+"</div>"
//console.log(line);
});
fs.writeFile("output.html", "<style>time{font-size:smaller;color:#cccccc;margin-left:0.8ex;}</style>"+output);
//console.log(output)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment