From 452c59b5bf098c78a533f80509b4520c78786c9f Mon Sep 17 00:00:00 2001 From: Ryan Driscoll Date: Thu, 23 Oct 2025 10:18:29 -0600 Subject: [PATCH 1/3] test: add tests for expandableImages --- test/expandableImages.test.js | 54 +++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 test/expandableImages.test.js diff --git a/test/expandableImages.test.js b/test/expandableImages.test.js new file mode 100644 index 0000000..e1dfe39 --- /dev/null +++ b/test/expandableImages.test.js @@ -0,0 +1,54 @@ +const test = require("tape") +const { markdownToHtml } = require("./utils") +const expandableImages = require("../src/expandableImages") + +test("plain image markdown is converted to a regular img element", (t) => { + t.plan(1) + const markdown = "![plain image](https://example.com/image.png)" + const expected = '

plain image

' + + const rendered = markdownToHtml(markdown, expandableImages) + t.equal(rendered, expected) +}) + +test("expandable image markdown is converted to a span with a data-url attribute", (t) => { + t.plan(1) + const markdown = "Check out this cool ![expandable](https://example.com/image.png) dog!" + const expected = + '

Check out this cool dog!

' + + const rendered = markdownToHtml(markdown, expandableImages) + t.equal(rendered, expected) +}) + +test("expandable image markdown with alt text is converted to a span with a data-url attribute and alt text content", (t) => { + t.plan(1) + const markdown = + "Check out this cool ![image of a dog expandable](https://example.com/image.png) dog!" + const expected = + '

Check out this cool image of a dog dog!

' + + const rendered = markdownToHtml(markdown, expandableImages) + t.equal(rendered, expected) +}) + +test("'expandable' anywhere but the end of the alt text does not make it expandable", (t) => { + t.plan(1) + const markdown = "![expandable image](https://example.com/image.png)" + const expected = + '

expandable image

' + + const rendered = markdownToHtml(markdown, expandableImages) + t.equal(rendered, expected) +}) + +test("'expandable' flag at the end of the alt text handles 'expandable' elsewhere in the alt text", (t) => { + t.plan(1) + const markdown = + "Check out this cool ![expandable image of a dog expandable](https://example.com/image.png) dog!" + const expected = + '

Check out this cool expandable image of a dog dog!

' + + const rendered = markdownToHtml(markdown, expandableImages) + t.equal(rendered, expected) +}) From 1dd5309f8841f5cf49938c3ab32079496805baa5 Mon Sep 17 00:00:00 2001 From: Ryan Driscoll Date: Tue, 28 Oct 2025 09:40:05 -0600 Subject: [PATCH 2/3] fix: replace string method substr with slice --- src/expandableImages.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/expandableImages.js b/src/expandableImages.js index 68c417c..d528dd1 100644 --- a/src/expandableImages.js +++ b/src/expandableImages.js @@ -30,7 +30,8 @@ module.exports = function expandableImages() { link.children = [ { type: "text", - value: link.alt.substr(0, -1 * "expandable".length).trim() + // using slice instead of regular expression for speed! + value: link.alt.slice(0, -1 * "expandable".length).trim() } ]; } From 491a3b7d58219aabb55779c7959c67b98c18c3ae Mon Sep 17 00:00:00 2001 From: Ryan Driscoll Date: Tue, 28 Oct 2025 09:42:51 -0600 Subject: [PATCH 3/3] chore: version bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e2d0e33..25abb96 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@code-dot-org/remark-plugins", - "version": "2.0.0", + "version": "2.0.1", "description": "Library of all Remark plugins we use", "main": "src/index.js", "files": [