@anydigital/eleventy-bricks 0.22.0 → 0.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -3
- package/package.json +1 -1
- package/src/markdown.js +17 -1
- package/src/markdown.test.js +10 -10
package/README.md
CHANGED
|
@@ -275,9 +275,9 @@ Before transformation:
|
|
|
275
275
|
After transformation:
|
|
276
276
|
|
|
277
277
|
```html
|
|
278
|
-
<a href="https://github.com/anydigital/eleventy-bricks" target="_blank">
|
|
278
|
+
<a href="https://github.com/anydigital/eleventy-bricks" class="whitespace-nowrap" target="_blank">
|
|
279
279
|
<i><img src="https://www.google.com/s2/favicons?domain=github.com&sz=32" /></i>
|
|
280
|
-
|
|
280
|
+
<span>/anydigital/eleventy-bricks</span>
|
|
281
281
|
</a>
|
|
282
282
|
```
|
|
283
283
|
|
|
@@ -288,7 +288,9 @@ After transformation:
|
|
|
288
288
|
- Removes the trailing slash from the display text
|
|
289
289
|
- Only applies if at least 3 characters remain after removing the domain (to avoid showing favicons for bare domain links)
|
|
290
290
|
- Uses Google's favicon service at `https://www.google.com/s2/favicons?domain=DOMAIN&sz=32`
|
|
291
|
-
- Adds `target="_blank"` to the transformed links
|
|
291
|
+
- Adds `target="_blank"` to the transformed links (only if not already present)
|
|
292
|
+
- Adds `whitespace-nowrap` class to the link
|
|
293
|
+
- Wraps the link text in a `<span>` element
|
|
292
294
|
- The favicon is wrapped in an `<i>` tag for easy styling
|
|
293
295
|
|
|
294
296
|
**Styling:**
|
package/package.json
CHANGED
package/src/markdown.js
CHANGED
|
@@ -92,7 +92,23 @@ export function cleanLinkText(linkText, domain) {
|
|
|
92
92
|
* @returns {string} The HTML string
|
|
93
93
|
*/
|
|
94
94
|
export function buildFaviconLink(attrs, domain, text) {
|
|
95
|
-
|
|
95
|
+
let updatedAttrs = attrs;
|
|
96
|
+
|
|
97
|
+
// Check if attrs already contains a class attribute
|
|
98
|
+
if (/class\s*=\s*["']/.test(attrs)) {
|
|
99
|
+
// Append whitespace-nowrap to existing class
|
|
100
|
+
updatedAttrs = attrs.replace(/class\s*=\s*["']([^"']*)["']/i, 'class="$1 whitespace-nowrap"');
|
|
101
|
+
} else {
|
|
102
|
+
// Add new class attribute
|
|
103
|
+
updatedAttrs = attrs + ' class="whitespace-nowrap"';
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Check if attrs already contains a target attribute
|
|
107
|
+
if (!/target\s*=/.test(attrs)) {
|
|
108
|
+
updatedAttrs = updatedAttrs + ' target="_blank"';
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return `<a ${updatedAttrs}><i><img src="https://www.google.com/s2/favicons?domain=${domain}&sz=32"></i><span>${text}</span></a>`;
|
|
96
112
|
}
|
|
97
113
|
|
|
98
114
|
/**
|
package/src/markdown.test.js
CHANGED
|
@@ -233,7 +233,7 @@ describe("buildFaviconLink", () => {
|
|
|
233
233
|
const result = buildFaviconLink('href="https://example.com/docs"', "example.com", "/docs");
|
|
234
234
|
assert.equal(
|
|
235
235
|
result,
|
|
236
|
-
'<a href="https://example.com/docs" target="_blank"><i><img src="https://www.google.com/s2/favicons?domain=example.com&sz=32"></i>/docs</a>',
|
|
236
|
+
'<a href="https://example.com/docs" class="whitespace-nowrap" target="_blank"><i><img src="https://www.google.com/s2/favicons?domain=example.com&sz=32"></i><span>/docs</span></a>',
|
|
237
237
|
);
|
|
238
238
|
});
|
|
239
239
|
|
|
@@ -241,7 +241,7 @@ describe("buildFaviconLink", () => {
|
|
|
241
241
|
const result = buildFaviconLink('href="https://example.com" class="link"', "example.com", "text");
|
|
242
242
|
assert.equal(
|
|
243
243
|
result,
|
|
244
|
-
'<a href="https://example.com" class="link" target="_blank"><i><img src="https://www.google.com/s2/favicons?domain=example.com&sz=32"></i>text</a>',
|
|
244
|
+
'<a href="https://example.com" class="link whitespace-nowrap" target="_blank"><i><img src="https://www.google.com/s2/favicons?domain=example.com&sz=32"></i><span>text</span></a>',
|
|
245
245
|
);
|
|
246
246
|
});
|
|
247
247
|
|
|
@@ -259,13 +259,13 @@ describe("buildFaviconLink", () => {
|
|
|
259
259
|
const result = buildFaviconLink('href="https://github.com/repo"', "github.com", "/repo");
|
|
260
260
|
assert.equal(
|
|
261
261
|
result,
|
|
262
|
-
'<a href="https://github.com/repo" target="_blank"><i><img src="https://www.google.com/s2/favicons?domain=github.com&sz=32"></i>/repo</a>',
|
|
262
|
+
'<a href="https://github.com/repo" class="whitespace-nowrap" target="_blank"><i><img src="https://www.google.com/s2/favicons?domain=github.com&sz=32"></i><span>/repo</span></a>',
|
|
263
263
|
);
|
|
264
264
|
});
|
|
265
265
|
|
|
266
266
|
it("should preserve link text as provided", () => {
|
|
267
267
|
const result = buildFaviconLink('href="https://example.com"', "example.com", "custom text");
|
|
268
|
-
assert.match(result,
|
|
268
|
+
assert.match(result, /><span>custom text<\/span><\/a>$/);
|
|
269
269
|
});
|
|
270
270
|
});
|
|
271
271
|
|
|
@@ -279,7 +279,7 @@ describe("transformLink", () => {
|
|
|
279
279
|
);
|
|
280
280
|
assert.match(
|
|
281
281
|
result,
|
|
282
|
-
/<i><img src="https:\/\/www\.google\.com\/s2\/favicons\?domain=example\.com&sz=32"><\/i>\/docs
|
|
282
|
+
/<i><img src="https:\/\/www\.google\.com\/s2\/favicons\?domain=example\.com&sz=32"><\/i><span>\/docs<\/span>/,
|
|
283
283
|
);
|
|
284
284
|
});
|
|
285
285
|
|
|
@@ -325,7 +325,7 @@ describe("transformLink", () => {
|
|
|
325
325
|
"http://example.com/docs",
|
|
326
326
|
"http://example.com/docs",
|
|
327
327
|
);
|
|
328
|
-
assert.match(result, /<i><img[^>]*><\/i>\/docs
|
|
328
|
+
assert.match(result, /<i><img[^>]*><\/i><span>\/docs<\/span>/);
|
|
329
329
|
});
|
|
330
330
|
|
|
331
331
|
it("should work with https:// protocol", () => {
|
|
@@ -335,7 +335,7 @@ describe("transformLink", () => {
|
|
|
335
335
|
"https://example.com/docs",
|
|
336
336
|
"https://example.com/docs",
|
|
337
337
|
);
|
|
338
|
-
assert.match(result, /<i><img[^>]*><\/i>\/docs
|
|
338
|
+
assert.match(result, /<i><img[^>]*><\/i><span>\/docs<\/span>/);
|
|
339
339
|
});
|
|
340
340
|
|
|
341
341
|
it("should handle longer paths correctly", () => {
|
|
@@ -345,7 +345,7 @@ describe("transformLink", () => {
|
|
|
345
345
|
"https://example.com/path/to/document",
|
|
346
346
|
"https://example.com/path/to/document",
|
|
347
347
|
);
|
|
348
|
-
assert.match(result, /<i><img[^>]*><\/i>\/path\/to\/document
|
|
348
|
+
assert.match(result, /<i><img[^>]*><\/i><span>\/path\/to\/document<\/span>/);
|
|
349
349
|
});
|
|
350
350
|
|
|
351
351
|
it("should not transform when linkText doesn't look like URL", () => {
|
|
@@ -366,7 +366,7 @@ describe("transformLink", () => {
|
|
|
366
366
|
"https://example.com/docs",
|
|
367
367
|
"example.com/docs",
|
|
368
368
|
);
|
|
369
|
-
assert.match(result, /<i><img[^>]*><\/i>\/docs
|
|
369
|
+
assert.match(result, /<i><img[^>]*><\/i><span>\/docs<\/span>/);
|
|
370
370
|
});
|
|
371
371
|
|
|
372
372
|
it("should handle malformed URLs by returning original match", () => {
|
|
@@ -528,7 +528,7 @@ describe("replaceLinksInHtml", () => {
|
|
|
528
528
|
const result = replaceLinksInHtml(html, transformLink);
|
|
529
529
|
// transformLink should add favicon for plain URL links
|
|
530
530
|
assert.match(result, /<img src="https:\/\/www\.google\.com\/s2\/favicons\?domain=example\.com&sz=32">/);
|
|
531
|
-
assert.match(result,
|
|
531
|
+
assert.match(result, /<span>\/docs<\/span><\/a>/);
|
|
532
532
|
});
|
|
533
533
|
|
|
534
534
|
it("should not transform custom link text when using transformLink", () => {
|