mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +01:00 
			
		
		
		
	fix(export/markdown): proper language tag for Nginx
This commit is contained in:
		| @@ -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,17 +3,26 @@ 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", () => { |  | ||||||
|  |     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`\ |             const html = trimIndentation`\ | ||||||
|                 <p>A diff:</p> |                 <p>A diff:</p> | ||||||
|             <pre><code class="language-text-x-diff">Hello |                 <pre><code class="${a}">Hello | ||||||
|                 -world |                 -world | ||||||
|                 +worldy |                 +worldy | ||||||
|                 </code></pre>`; |                 </code></pre>`; | ||||||
|             const expected = trimIndentation`\ |             const expected = trimIndentation`\ | ||||||
|                 A diff: |                 A diff: | ||||||
|  |  | ||||||
|             \`\`\`diff |                 \`\`\`${b} | ||||||
|                 Hello |                 Hello | ||||||
|                 -world |                 -world | ||||||
|                 +worldy |                 +worldy | ||||||
| @@ -21,24 +30,7 @@ describe("Markdown export", () => { | |||||||
|                 \`\`\``; |                 \`\`\``; | ||||||
|  |  | ||||||
|             expect(markdownExportService.toMarkdown(html)).toBe(expected); |             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", () => { |     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); | ||||||
|     } |     } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user