Skip to content

Commit 79f1265

Browse files
committed
html to md
1 parent efa7cf7 commit 79f1265

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

docusaurus.config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const config: Config = {
5151
],
5252
],
5353
markdown: {
54+
format: 'md',
5455
parseFrontMatter: async (params) => {
5556
// Reuse the default parser
5657
const result = await params.defaultParseFrontMatter(params);

plugins/cls-loader/package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,12 @@
3535
"@docusaurus/types": "^3.5.0",
3636
"@docusaurus/utils": "^3.5.0",
3737
"@vscode/codicons": "^0.0.36",
38+
"html-to-jsx-transform": "^1.2.0",
3839
"html-validate": "^8.27.0",
3940
"marked": "^9.1.6",
40-
"marked-smartypants": "^1.1.5"
41+
"marked-smartypants": "^1.1.5",
42+
"node-html-markdown": "^1.3.0",
43+
"node-html-to-jsx": "^1.3.1"
4144
},
4245
"devDependencies": {
4346
"@docusaurus/module-type-aliases": "^3.5.0",

plugins/cls-loader/src/plugin/classes.ts

+18-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import { readdir, readFile, writeFile, mkdir } from "fs/promises";
22
import * as path from "path";
33
import { ClassReflection } from "../types";
44

5+
import { htmlToJsx } from "html-to-jsx-transform";
6+
import convert from 'node-html-to-jsx';
7+
import { NodeHtmlMarkdown, NodeHtmlMarkdownOptions } from 'node-html-markdown'
8+
9+
510
import { HtmlValidate } from "html-validate";
611

712
enum ClassMemberType {
@@ -202,9 +207,19 @@ function reshapeHTML(text) {
202207
if (Array.isArray(text)) {
203208
text = text.join(" ");
204209
}
210+
try {
211+
const md = NodeHtmlMarkdown.translate(text);
212+
return md;
213+
} catch (ex) {
214+
console.error(ex);
215+
}
216+
return text;
217+
// return "```\n" + text + "\n```\n\n"
205218
text = text.replaceAll(/<[^>]*>/gi, "");
206-
text = text.replaceAll("{", "&#123;");
207-
text = text.replaceAll("}", "&#125;");
219+
// text = text.replaceAll("{", "&#123;");
220+
// text = text.replaceAll("}", "&#125;");
221+
// text = text.replaceAll("{", "\\{");
222+
// text = text.replaceAll("}", "\\}");
208223
// text = text.replaceAll(/({|}|\[|\])/g, "\\$1");
209224

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

0 commit comments

Comments
 (0)