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
|
||||
* @returns
|
||||
*/
|
||||
export function trimIndentation(strings: TemplateStringsArray) {
|
||||
const str = strings.toString();
|
||||
export function trimIndentation(strings: TemplateStringsArray, ...values: any[]) {
|
||||
// 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.
|
||||
let numSpaces = 0;
|
||||
|
@ -3,17 +3,26 @@ import markdownExportService from "./md.js";
|
||||
import { trimIndentation } from "../../../spec/support/utils.js";
|
||||
|
||||
describe("Markdown export", () => {
|
||||
it("trims language tag for code blocks", () => {
|
||||
|
||||
it("exports correct language tag for known languages", () => {
|
||||
const conversionTable = {
|
||||
"language-text-x-nginx-conf": "nginx",
|
||||
"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="language-text-x-diff">Hello
|
||||
<pre><code class="${a}">Hello
|
||||
-world
|
||||
+worldy
|
||||
</code></pre>`;
|
||||
const expected = trimIndentation`\
|
||||
A diff:
|
||||
|
||||
\`\`\`diff
|
||||
\`\`\`${b}
|
||||
Hello
|
||||
-world
|
||||
+worldy
|
||||
@ -21,24 +30,7 @@ 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", () => {
|
||||
|
@ -48,6 +48,8 @@ function rewriteLanguageTag(source: string) {
|
||||
case "application-javascript-env-frontend":
|
||||
case "application-javascript-env-backend":
|
||||
return "javascript";
|
||||
case "text-x-nginx-conf":
|
||||
return "nginx";
|
||||
default:
|
||||
return source.split("-").at(-1);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user