|
|
|
|
@ -3,42 +3,34 @@ import markdownExportService from "./md.js";
|
|
|
|
|
import { trimIndentation } from "../../../spec/support/utils.js";
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
Hello
|
|
|
|
|
-world
|
|
|
|
|
+worldy
|
|
|
|
|
|
|
|
|
|
\`\`\``;
|
|
|
|
|
|
|
|
|
|
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("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="${a}">Hello
|
|
|
|
|
-world
|
|
|
|
|
+worldy
|
|
|
|
|
</code></pre>`;
|
|
|
|
|
const expected = trimIndentation`\
|
|
|
|
|
A diff:
|
|
|
|
|
|
|
|
|
|
\`\`\`${b}
|
|
|
|
|
Hello
|
|
|
|
|
-world
|
|
|
|
|
+worldy
|
|
|
|
|
|
|
|
|
|
\`\`\``;
|
|
|
|
|
|
|
|
|
|
expect(markdownExportService.toMarkdown(html)).toBe(expected);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("removes auto tag for code blocks", () => {
|
|
|
|
|
|