diff --git a/src/core/markdown.js b/src/core/markdown.js index 30d52ade52..0f1f36b385 100644 --- a/src/core/markdown.js +++ b/src/core/markdown.js @@ -37,6 +37,19 @@ class Renderer extends marked.Renderer { return html.replace("
", `
`);
   }
 
+  image(href, title, text) {
+    if (!title) {
+      return super.image(href, title, text);
+    }
+    const html = String.raw;
+    return html`
+      
+ ${text} +
${title}
+
+ `; + } + /** * @param {string} infoString */ diff --git a/tests/spec/core/markdown-spec.js b/tests/spec/core/markdown-spec.js index 61eb5849d1..c720877dd7 100644 --- a/tests/spec/core/markdown-spec.js +++ b/tests/spec/core/markdown-spec.js @@ -576,6 +576,44 @@ function getAnswer() { }); }); + it("renders image as
if title is present", async () => { + const body = ` + ## pass + +
+ + ![img alt](regular-img.png) + ![figure alt](figure.png "This is figcaption") +
+ `; + const ops = makeStandardOps({ format: "markdown" }, body); + ops.abstract = null; + const doc = await makeRSDoc(ops); + + const [img, figure] = doc.querySelectorAll( + "#test > p > img, #test > figure" + ); + expect(img).toBeTruthy(); + expect(figure).toBeTruthy(); + + expect(img.localName).toBe("img"); + expect(img.getAttribute("src")).toBe("regular-img.png"); + expect(img.getAttribute("alt")).toBe("img alt"); + expect(img.getAttribute("title")).toBeNull(); + expect(img.querySelector("figcaption")).toBeNull(); + + expect(figure.localName).toBe("figure"); + const figImg = figure.querySelector("img"); + expect(figImg).not.toBeNull(); + expect(figImg.getAttribute("src")).toBe("figure.png"); + expect(figImg.getAttribute("alt")).toBe("figure alt"); + expect(figImg.getAttribute("title")).toBeNull(); + const figCaption = figure.querySelector("figcaption"); + expect(figCaption).not.toBeNull(); + expect(figCaption.textContent).toContain("This is figcaption"); + expect(figCaption.textContent).not.toContain("figure alt"); + }); + it("retains heading order with generated sections", async () => { const body = `