gmi-web/tokenize.js
2021-01-28 23:07:57 +00:00

20 lines
439 B
JavaScript

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