Skip to content

Commit

Permalink
Merge pull request #11 from tenzir/topic/docs-improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
dit7ya authored Aug 31, 2023
2 parents 29497f1 + 9d8c4b0 commit ba9ea63
Show file tree
Hide file tree
Showing 7 changed files with 433 additions and 589 deletions.
127 changes: 85 additions & 42 deletions output.js

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"type": "git",
"url": "https://github.com/tenzir/codemirror-lang-tql.git"
},
"version": "0.3.1",
"version": "0.3.2",
"description": "Tenzir Query Language (TQL) support for CodeMirror",
"scripts": {
"build": "lezer-generator src/syntax.grammar -o src/parser && rollup -c",
Expand All @@ -27,7 +27,9 @@
"@codemirror/autocomplete": "^6.6.0",
"@codemirror/language": "^6.0.0",
"@lezer/highlight": "^1.1.6",
"@lezer/lr": "^1.3.0"
"@lezer/lr": "^1.3.0",
"hastscript": "^8.0.0",
"unist-util-visit": "^5.0.0"
},
"devDependencies": {
"@lezer/generator": "^1.3.0",
Expand Down
75 changes: 75 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 28 additions & 13 deletions scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,57 @@ import path from "path";
import rehypeStringify from "rehype-stringify";
import remarkParse from "remark-parse";
import remarkRehype from "remark-rehype";
import strip from "strip-markdown";
import { remark } from "remark";
import { unified } from "unified";
import { promisify } from "util";
import remarkFlexibleContainers from "remark-flexible-containers";

const readFile = promisify(fs.readFile);
const readDirectory = promisify(fs.readdir);
const writeFile = promisify(fs.writeFile);
const lstat = promisify(fs.lstat);

// TODO: clean up the markdown in detail via remark-format
// TODO: clean up package.json
const processor = unified()
const infoProcessor = unified()
.use(remarkParse)
.use(remarkFlexibleContainers)
.use(remarkRehype, { allowDangerousHtml: true })
.use(rehypeStringify);

const detailProcessor = remark().use(strip);

let output = [];

const processFile = async (filePath) => {
try {
const data = await readFile(filePath, "utf8");
let detail = "";
let lines = data.split("\n");
let detail = undefined;
let infoArr = [];

for (let i = 1; i < lines.length; i++) {
if (lines[i].trim() !== "") {
detail = lines[i].trim();
lines = lines.slice(i + 1);
break;
if (detail == undefined && lines[i].trim() !== "") {
detail = lines[i];
} else if (detail != null) {
infoArr.push(lines[i]);
}
}
let info = `${lines.join("\n")}`;
const file = await processor.process(info);
let info = infoArr.join("\n");

// get relative path to docs from filePath
const docRoute = filePath.split("docs")[1].split(".md")[0];
const docLink = `https://docs.tenzir.com${docRoute}`;

const infoFile = await infoProcessor.process(info);

const detailFile = await detailProcessor.process(detail);

output.push({
label: path.basename(filePath, ".md"),
type: "keyword",
detail: detail,
processedHTML: String(file),
detail: String(detailFile).trim(), // remove trailing whitespace
processedHTML: String(infoFile),
docLink,
});
} catch (err) {
console.error(err);
Expand Down Expand Up @@ -78,7 +93,7 @@ const processDirectory = async (directoryPath, outputPath) => {
await writeFile(
outputPath,
`export const data = ${JSON.stringify(output)};`,
"utf8"
"utf8",
);
} catch (err) {
console.error(err);
Expand Down
4 changes: 3 additions & 1 deletion scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
"rehype-document": "^6.1.0",
"rehype-format": "^4.0.1",
"rehype-stringify": "^9.0.3",
"remark-frontmatter": "^4.0.1",
"remark": "^14.0.3",
"remark-flexible-containers": "^1.0.6",
"remark-parse": "^10.0.2",
"remark-rehype": "^10.1.0",
"strip-markdown": "^5.0.1",
"to-vfile": "^8.0.0",
"unified": "^10.1.2",
"vfile-reporter": "^8.0.0"
Expand Down
Loading

0 comments on commit ba9ea63

Please sign in to comment.