mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-09-25 14:31:33 +08:00
feat(export/md): rewrite JavaScript code block languages
This commit is contained in:
parent
09f36cac00
commit
0e67078256
@ -22,6 +22,24 @@ describe("Markdown export", () => {
|
||||
expect(markdownExportService.toMarkdown(html)).toBe(expected);
|
||||
});
|
||||
|
||||
it("rewrites frontend script JavaScript code block", () => {
|
||||
const html = `<pre><code class="language-application-javascript-env-frontend">Hello</code></pre>`;
|
||||
const expected = trimIndentation`\
|
||||
\`\`\`javascript
|
||||
Hello
|
||||
\`\`\``;
|
||||
expect(markdownExportService.toMarkdown(html)).toBe(expected);
|
||||
});
|
||||
|
||||
it("rewrites backend script JavaScript code block", () => {
|
||||
const html = `<pre><code class="language-application-javascript-env-backend">Hello</code></pre>`;
|
||||
const expected = trimIndentation`\
|
||||
\`\`\`javascript
|
||||
Hello
|
||||
\`\`\``;
|
||||
expect(markdownExportService.toMarkdown(html)).toBe(expected);
|
||||
});
|
||||
|
||||
it("removes auto tag for code blocks", () => {
|
||||
const html = trimIndentation`\
|
||||
<pre><code class="language-text-x-trilium-auto">Hello
|
||||
|
@ -38,11 +38,15 @@ function rewriteLanguageTag(source: string) {
|
||||
return source;
|
||||
}
|
||||
|
||||
if (source === "text-x-trilium-auto") {
|
||||
return "";
|
||||
switch (source) {
|
||||
case "text-x-trilium-auto":
|
||||
return "";
|
||||
case "application-javascript-env-frontend":
|
||||
case "application-javascript-env-backend":
|
||||
return "javascript";
|
||||
default:
|
||||
return source.split("-").at(-1);
|
||||
}
|
||||
|
||||
return source.split("-").at(-1);
|
||||
}
|
||||
|
||||
export default {
|
||||
|
Loading…
x
Reference in New Issue
Block a user