mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 18:12:29 +08:00
fix(export/markdown): proper language tag for Nginx
This commit is contained in:
parent
09c081fdcf
commit
8c71e6aa90
@ -30,8 +30,11 @@
|
|||||||
* @param strings
|
* @param strings
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export function trimIndentation(strings: TemplateStringsArray) {
|
export function trimIndentation(strings: TemplateStringsArray, ...values: any[]) {
|
||||||
const str = strings.toString();
|
// Combine the strings with the values using interpolation
|
||||||
|
let str = strings.reduce((acc, curr, index) => {
|
||||||
|
return acc + curr + (values[index] !== undefined ? values[index] : '');
|
||||||
|
}, '');
|
||||||
|
|
||||||
// Count the number of spaces on the first line.
|
// Count the number of spaces on the first line.
|
||||||
let numSpaces = 0;
|
let numSpaces = 0;
|
||||||
|
@ -3,42 +3,34 @@ import markdownExportService from "./md.js";
|
|||||||
import { trimIndentation } from "../../../spec/support/utils.js";
|
import { trimIndentation } from "../../../spec/support/utils.js";
|
||||||
|
|
||||||
describe("Markdown export", () => {
|
describe("Markdown export", () => {
|
||||||
it("trims language tag for code blocks", () => {
|
|
||||||
const html = trimIndentation`\
|
|
||||||
<p>A diff:</p>
|
|
||||||
<pre><code class="language-text-x-diff">Hello
|
|
||||||
-world
|
|
||||||
+worldy
|
|
||||||
</code></pre>`;
|
|
||||||
const expected = trimIndentation`\
|
|
||||||
A diff:
|
|
||||||
|
|
||||||
\`\`\`diff
|
it("exports correct language tag for known languages", () => {
|
||||||
Hello
|
const conversionTable = {
|
||||||
-world
|
"language-text-x-nginx-conf": "nginx",
|
||||||
+worldy
|
"language-x-diff": "diff",
|
||||||
|
"language-application-javascript-env-frontend": "javascript",
|
||||||
|
"language-application-javascript-env-backend": "javascript"
|
||||||
|
};
|
||||||
|
|
||||||
\`\`\``;
|
for (const [ a, b ] of Object.entries(conversionTable)) {
|
||||||
|
const html = trimIndentation`\
|
||||||
|
<p>A diff:</p>
|
||||||
|
<pre><code class="${a}">Hello
|
||||||
|
-world
|
||||||
|
+worldy
|
||||||
|
</code></pre>`;
|
||||||
|
const expected = trimIndentation`\
|
||||||
|
A diff:
|
||||||
|
|
||||||
expect(markdownExportService.toMarkdown(html)).toBe(expected);
|
\`\`\`${b}
|
||||||
});
|
Hello
|
||||||
|
-world
|
||||||
|
+worldy
|
||||||
|
|
||||||
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", () => {
|
expect(markdownExportService.toMarkdown(html)).toBe(expected);
|
||||||
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", () => {
|
it("removes auto tag for code blocks", () => {
|
||||||
|
@ -48,6 +48,8 @@ function rewriteLanguageTag(source: string) {
|
|||||||
case "application-javascript-env-frontend":
|
case "application-javascript-env-frontend":
|
||||||
case "application-javascript-env-backend":
|
case "application-javascript-env-backend":
|
||||||
return "javascript";
|
return "javascript";
|
||||||
|
case "text-x-nginx-conf":
|
||||||
|
return "nginx";
|
||||||
default:
|
default:
|
||||||
return source.split("-").at(-1);
|
return source.split("-").at(-1);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user