18 lines
481 B
JavaScript
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);
|
|
};
|