|
1 | | -import { assertEquals } from "https://deno.land/std@0.178.0/testing/asserts.ts"; |
2 | | -import { DOMParser } from "https://deno.land/x/[email protected].35-alpha/deno-dom-wasm.ts"; |
| 1 | +import { assertEquals } from "https://deno.land/std@0.211.0/assert/assert_equals.ts"; |
| 2 | +import { DOMParser } from "https://deno.land/x/[email protected].43/deno-dom-wasm.ts"; |
3 | 3 | import { render, Renderer } from "../mod.ts"; |
4 | 4 |
|
5 | 5 | Deno.test("Basic markdown", async () => { |
@@ -106,3 +106,105 @@ Deno.test( |
106 | 106 | assertEquals(html, expected); |
107 | 107 | }, |
108 | 108 | ); |
| 109 | + |
| 110 | +Deno.test("Iframe rendering", () => { |
| 111 | + const markdown = |
| 112 | + 'Here is an iframe:\n\n<iframe src="https://example.com" width="300" height="200"></iframe>'; |
| 113 | + const expected = |
| 114 | + `<p>Here is an iframe:</p>\n<iframe src="https://example.com" width="300" height="200"></iframe>`; |
| 115 | + |
| 116 | + const html = render(markdown, { allowIframes: true }); |
| 117 | + assertEquals(html, expected); |
| 118 | +}); |
| 119 | + |
| 120 | +Deno.test("Iframe rendering disabled", () => { |
| 121 | + const markdown = |
| 122 | + 'Here is an iframe:\n\n<iframe src="https://example.com" width="300" height="200"></iframe>'; |
| 123 | + const expectedWithoutIframe = `<p>Here is an iframe:</p>\n`; |
| 124 | + |
| 125 | + const html = render(markdown); |
| 126 | + assertEquals(html, expectedWithoutIframe); |
| 127 | +}); |
| 128 | + |
| 129 | +Deno.test("Media URL transformation", () => { |
| 130 | + const markdown = "\n\n"; |
| 131 | + const mediaBaseUrl = "https://cdn.example.com/"; |
| 132 | + const expected = |
| 133 | + `<p><img src="https://cdn.example.com/image.jpg" alt="Image" /></p>\n<p><img src="https://cdn.example.com/video.mp4" alt="Video" /></p>\n`; |
| 134 | + |
| 135 | + const html = render(markdown, { mediaBaseUrl: mediaBaseUrl }); |
| 136 | + assertEquals(html, expected); |
| 137 | +}); |
| 138 | + |
| 139 | +Deno.test("Media URL transformation without base URL", () => { |
| 140 | + const markdown = "\n\n"; |
| 141 | + const expectedWithoutTransformation = |
| 142 | + `<p><img src="image.jpg" alt="Image" /></p>\n<p><img src="video.mp4" alt="Video" /></p>\n`; |
| 143 | + |
| 144 | + const html = render(markdown); |
| 145 | + assertEquals(html, expectedWithoutTransformation); |
| 146 | +}); |
| 147 | + |
| 148 | +Deno.test("Media URL transformation with invalid URL", () => { |
| 149 | + const markdown = ""; |
| 150 | + const mediaBaseUrl = "this is an invalid url"; |
| 151 | + const expected = `<p><img alt="Image" /></p>\n`; |
| 152 | + |
| 153 | + const html = render(markdown, { mediaBaseUrl: mediaBaseUrl }); |
| 154 | + assertEquals(html, expected); |
| 155 | +}); |
| 156 | + |
| 157 | +Deno.test("Inline rendering", () => { |
| 158 | + const markdown = "My [Deno](https://deno.land) Blog"; |
| 159 | + const expected = |
| 160 | + `My <a href="https://deno.land" rel="noopener noreferrer">Deno</a> Blog`; |
| 161 | + |
| 162 | + const html = render(markdown, { inline: true }); |
| 163 | + assertEquals(html, expected); |
| 164 | +}); |
| 165 | + |
| 166 | +Deno.test("Inline rendering false", () => { |
| 167 | + const markdown = "My [Deno](https://deno.land) Blog"; |
| 168 | + const expected = |
| 169 | + `<p>My <a href="https://deno.land" rel="noopener noreferrer">Deno</a> Blog</p>\n`; |
| 170 | + |
| 171 | + const html = render(markdown, { inline: false }); |
| 172 | + assertEquals(html, expected); |
| 173 | +}); |
| 174 | + |
| 175 | +Deno.test("Link URL resolution with base URL", () => { |
| 176 | + const markdown = "[Test Link](/path/to/resource)"; |
| 177 | + const baseUrl = "https://example.com/"; |
| 178 | + const expected = |
| 179 | + `<p><a href="https://example.com/path/to/resource" rel="noopener noreferrer">Test Link</a></p>\n`; |
| 180 | + |
| 181 | + const html = render(markdown, { baseUrl: baseUrl }); |
| 182 | + assertEquals(html, expected); |
| 183 | +}); |
| 184 | + |
| 185 | +Deno.test("Link URL resolution without base URL", () => { |
| 186 | + const markdown = "[Test Link](/path/to/resource)"; |
| 187 | + const expected = |
| 188 | + `<p><a href="/path/to/resource" rel="noopener noreferrer">Test Link</a></p>\n`; |
| 189 | + |
| 190 | + const html = render(markdown); |
| 191 | + assertEquals(html, expected); |
| 192 | +}); |
| 193 | + |
| 194 | +Deno.test("Link URL resolution with invalid URL and base URL", () => { |
| 195 | + const markdown = "[Test Link](/path/to/resource)"; |
| 196 | + const baseUrl = "this is an invalid url"; |
| 197 | + const expected = |
| 198 | + `<p><a href="/path/to/resource" rel="noopener noreferrer">Test Link</a></p>\n`; |
| 199 | + |
| 200 | + const html = render(markdown, { baseUrl: baseUrl }); |
| 201 | + assertEquals(html, expected); |
| 202 | +}); |
| 203 | + |
| 204 | +Deno.test("Math rendering in code block", () => { |
| 205 | + const markdown = "```math\ny = mx + b\n```"; |
| 206 | + const expected = Deno.readTextFileSync("./test/fixtures/codeMath.html"); |
| 207 | + |
| 208 | + const html = render(markdown, { allowMath: true }); |
| 209 | + assertEquals(html, expected); |
| 210 | +}); |
0 commit comments