Skip to content

Commit

Permalink
html to md
Browse files Browse the repository at this point in the history
  • Loading branch information
daimor committed Dec 16, 2024
1 parent efa7cf7 commit 88af07a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
5 changes: 4 additions & 1 deletion plugins/cls-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@
"@docusaurus/types": "^3.5.0",
"@docusaurus/utils": "^3.5.0",
"@vscode/codicons": "^0.0.36",
"html-to-jsx-transform": "^1.2.0",
"html-validate": "^8.27.0",
"marked": "^9.1.6",
"marked-smartypants": "^1.1.5"
"marked-smartypants": "^1.1.5",
"node-html-markdown": "^1.3.0",
"node-html-to-jsx": "^1.3.1"
},
"devDependencies": {
"@docusaurus/module-type-aliases": "^3.5.0",
Expand Down
21 changes: 18 additions & 3 deletions plugins/cls-loader/src/plugin/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import { readdir, readFile, writeFile, mkdir } from "fs/promises";
import * as path from "path";
import { ClassReflection } from "../types";

import { htmlToJsx } from "html-to-jsx-transform";
import convert from 'node-html-to-jsx';
import { NodeHtmlMarkdown, NodeHtmlMarkdownOptions } from 'node-html-markdown'


import { HtmlValidate } from "html-validate";

enum ClassMemberType {
Expand Down Expand Up @@ -202,9 +207,19 @@ function reshapeHTML(text) {
if (Array.isArray(text)) {
text = text.join(" ");
}
try {
const md = NodeHtmlMarkdown.translate(text);
return md;
} catch (ex) {
console.error(ex);
}
return text;
// return "```\n" + text + "\n```\n\n"
text = text.replaceAll(/<[^>]*>/gi, "");
text = text.replaceAll("{", "&#123;");
text = text.replaceAll("}", "&#125;");
// text = text.replaceAll("{", "&#123;");
// text = text.replaceAll("}", "&#125;");
// text = text.replaceAll("{", "\\{");
// text = text.replaceAll("}", "\\}");
// text = text.replaceAll(/({|}|\[|\])/g, "\\$1");

text = text.replaceAll(/\<br\s*\/?\>/gi, "<br />");
Expand Down Expand Up @@ -316,7 +331,7 @@ ${reshapeHTML(classDef.Class.description.join(" "))}
export async function generateDocFile(classFile, folder, mdFile) {
await mkdir(folder, { recursive: true });
const mdFileFull = path.join(folder, mdFile);
await writeFile(mdFileFull, await generateDoc(classFile, false));
await writeFile(mdFileFull, await generateDoc(classFile, true));
return mdFileFull;
}

Expand Down

0 comments on commit 88af07a

Please sign in to comment.