Skip to content

Commit

Permalink
Merge branch 'main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
thooyork committed Jun 16, 2023
2 parents 2473ae6 + e66a7ce commit 3b0a72b
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 17 deletions.
6 changes: 4 additions & 2 deletions common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@
},
"dependencies": {
"dompurify": "^3.0.1",
"highlight.js": "^11.7.0",
"highlight.js": "^11.8.0",
"jsdom": "^22.0.0",
"marked": "^5.0.2",
"marked-highlight": "^2.0.1",
"marked-mangle": "^1.0.1",
"node-fetch": "^3.3.1",
"pako": "2.1.0",
"sha.js": "^2.4.11"
},
"devDependencies": {
"@types/dompurify": "^3.0.0",
"@types/jsdom": "^21.1.0",
"@types/marked": "^4.0.7",
"@types/marked": "^5.0.0",
"@types/node": "^18.16.10",
"@types/node-fetch": "^2.6.2",
"@types/pako": "^2.0.0",
Expand Down
18 changes: 12 additions & 6 deletions common/src/markdown-converter-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Buffer } from "buffer";
import { DOMPurifyI } from "dompurify";
import highlightjs from "highlight.js";
import { marked } from "marked";
import { markedHighlight } from "marked-highlight";
import { mangle } from "marked-mangle";
import pako from "pako";

/**
Expand Down Expand Up @@ -84,8 +86,6 @@ export abstract class MarkdownConverter {
const res = Buffer.from(compressed).toString("base64").replace(/\+/g, "-").replace(/\//g, "_");
token.text = await fetchTextFromUrl(`${MarkdownConverter.KROKI_SERVICE_URL}/${diagramType.id}/svg/${res}`);
}
} else if (token.type === "image") {
token.href = "";
}
},
};
Expand All @@ -108,6 +108,15 @@ export abstract class MarkdownConverter {
},
});
marked.use(MarkdownConverter.rendererExtension);
marked.use(
markedHighlight({
highlight: function (code: string, lang: string) {
return highlightjs.highlightAuto(code).value;
},
}),
);
marked.use(mangle());
marked.use({ headerIds: false });
}

private f: ImageHashToUrlFunction | undefined;
Expand All @@ -116,11 +125,8 @@ export abstract class MarkdownConverter {
this.f = imgHashToUrl;
return marked
.parse(input, {
highlight: function (code, lang) {
return highlightjs.highlightAuto(code).value;
},
async: true,
}) //
})
.then((parsedInput) =>
this.dompurify.sanitize(parsedInput, {
// Allowed tags and attributes inside markdown
Expand Down
1 change: 1 addition & 0 deletions common/src/types/markedhighlight.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module "marked-highlight";
1 change: 1 addition & 0 deletions common/src/types/markedmangle.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module "marked-mangle";
7 changes: 5 additions & 2 deletions common/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@
"baseUrl": ".",
"paths": {
"@common/*": ["./src/*"]
}
},
},
"include": [
"./src/**/*.ts",
]
],
"ts-node": {
"files": true
}
}
30 changes: 24 additions & 6 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@types/cors": "^2.8.12",
"@types/express": "^4.17.14",
"@types/jsdom": "^21.1.0",
"@types/marked": "^4.0.7",
"@types/marked": "^5.0.0",
"@types/multer": "^1.4.7",
"@types/node": "^18.16.10",
"@types/node-fetch": "^2.6.2",
Expand Down

0 comments on commit 3b0a72b

Please sign in to comment.