gmi-web/tokenize.js
Talon Poole b383f03f94 RC
2021-01-29 23:59:12 +00:00

18 lines
481 B
JavaScript

const GMI_EXT = /\.gmi$/;
const GMI_REGEX = require("./gmi.regex");
const tokenize = (exports.tokenize = (file) =>
JSON.stringify(
file.contents
.toString("utf8")
.split("\n")
.map((line) => GMI_REGEX.exec(line).groups),
null,
2
));
module.exports = (file, cb) => {
if (!GMI_EXT.test(file.path)) return cb(null, file);
file.contents = Buffer.from(tokenize(file));
file.path = file.path.replace(GMI_EXT, ".tokens.json");
cb(null, file);
};