|
| 1 | +const test = require("tape") |
| 2 | +const { markdownToHtml } = require("./utils") |
| 3 | +const expandableImages = require("../src/expandableImages") |
| 4 | + |
| 5 | +test("plain images are not converted to span with data attributes", (t) => { |
| 6 | + t.plan(1) |
| 7 | + const markdown = "" |
| 8 | + const expected = '<p><img src="https://example.com/image.png" alt="plain image"></p>' |
| 9 | + |
| 10 | + const rendered = markdownToHtml(markdown, expandableImages) |
| 11 | + t.equal(rendered, expected) |
| 12 | +}) |
| 13 | + |
| 14 | +test("expandable images are converted to span with data attributes", (t) => { |
| 15 | + t.plan(1) |
| 16 | + const markdown = "Check out this cool  dog!" |
| 17 | + const expected = |
| 18 | + '<p>Check out this cool <span data-url="https://example.com/image.png" data-alt="" class="expandable-image"></span> dog!</p>' |
| 19 | + |
| 20 | + const rendered = markdownToHtml(markdown, expandableImages) |
| 21 | + t.equal(rendered, expected) |
| 22 | +}) |
| 23 | + |
| 24 | +test("expandable image with alt text are converted to span with data attributes", (t) => { |
| 25 | + t.plan(1) |
| 26 | + const markdown = |
| 27 | + "Check out this cool  dog!" |
| 28 | + const expected = |
| 29 | + '<p>Check out this cool <span data-url="https://example.com/image.png" data-alt="image of a dog" class="expandable-image">image of a dog</span> dog!</p>' |
| 30 | + |
| 31 | + const rendered = markdownToHtml(markdown, expandableImages) |
| 32 | + t.equal(rendered, expected) |
| 33 | +}) |
| 34 | + |
| 35 | +test("'expandable' anywhere but the end of the alt text does not make it expandable", (t) => { |
| 36 | + t.plan(1) |
| 37 | + const markdown = "" |
| 38 | + const expected = |
| 39 | + '<p><img src="https://example.com/image.png" alt="expandable image"></p>' |
| 40 | + |
| 41 | + const rendered = markdownToHtml(markdown, expandableImages) |
| 42 | + t.equal(rendered, expected) |
| 43 | +}) |
| 44 | + |
| 45 | +test("'expandable' flag at the end of the alt text handles 'expandable' elsewhere in the alt text", (t) => { |
| 46 | + t.plan(1) |
| 47 | + const markdown = |
| 48 | + "Check out this cool  dog!" |
| 49 | + const expected = |
| 50 | + '<p>Check out this cool <span data-url="https://example.com/image.png" data-alt="expandable image of a dog" class="expandable-image">expandable image of a dog</span> dog!</p>' |
| 51 | + |
| 52 | + const rendered = markdownToHtml(markdown, expandableImages) |
| 53 | + t.equal(rendered, expected) |
| 54 | +}) |
0 commit comments