-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate.js
38 lines (32 loc) · 1.18 KB
/
generate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { promisify } from "util";
import path from "path";
import hljs from "highlight.js";
import fs from "fs";
import hljsDefineAss from "./src/languages/ass.js";
import { dirname } from "path";
import { fileURLToPath } from "url";
const __dirname = dirname(fileURLToPath(import.meta.url));
hljs.registerLanguage("ass", hljsDefineAss);
hljs.debugMode();
const readdir = promisify(fs.readdir);
const readFile = promisify(fs.readFile);
const writeFile = promisify(fs.writeFile);
async function generateSyntaxHighlightingSamples() {
const files = (
await readdir(path.join(__dirname, "test", "markup", "ass"))
).filter(
(f) => !f.includes(".expect.") && (f.endsWith(".ass") || f.endsWith(".ssa"))
);
for (const file of files) {
const filePath = path.join(__dirname, "test", "markup", "ass", file);
const expectedFilePath = filePath.replace(/\.(ass|ssa)$/, ".expect.html");
// get rid of byte order mark
const code = (await readFile(filePath, "utf-8")).trimStart();
const result = hljs.highlight(code, {
language: "ass",
});
const actual = result.value;
await writeFile(expectedFilePath, actual);
}
}
await generateSyntaxHighlightingSamples();