gmi-web/tokenize.js

20 lines
439 B
JavaScript
Raw Normal View History

2021-01-28 21:03:30 +00:00
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);
};