@bscotch/blork-shared
Advanced tools
Comparing version 0.12.0 to 0.13.0
@@ -13,3 +13,5 @@ export interface InlineMarkdownOptions { | ||
allowHtml?: boolean; | ||
/** If a link includes an origin, but not this one, render it as an anchor with target=_blank */ | ||
linkOutIfNotOrigin?: string; | ||
}): string; | ||
//# sourceMappingURL=markdown.d.ts.map |
@@ -55,6 +55,17 @@ import { escapeHtml } from './html.js'; | ||
} | ||
// Replace Markdown links with HTML links | ||
html = html.replace(/\[([^\]]*?)\]\(([^)]*?)\)/g, `<a href="$2">$1</a>`); | ||
const mdUrlPattern = /\[(?<content>[^\]]*?)\]\((?<url>[^)]*?)\)/g; | ||
const matches = html.matchAll(mdUrlPattern); | ||
for (const match of matches) { | ||
const { content, url } = match.groups; | ||
let anchorReplacement = `<a href="${url}"`; | ||
if (options.linkOutIfNotOrigin && | ||
url.match(/^https?:/) && | ||
!url.startsWith(options.linkOutIfNotOrigin)) { | ||
anchorReplacement += ` target="_blank"`; | ||
} | ||
anchorReplacement += `>${content}</a>`; | ||
html = html.replaceAll(match[0], anchorReplacement); | ||
} | ||
return html + `</span>`; | ||
} | ||
//# sourceMappingURL=markdown.js.map |
{ | ||
"name": "@bscotch/blork-shared", | ||
"version": "0.12.0", | ||
"version": "0.13.0", | ||
"description": "Client and shared utilities for Blork projects.", | ||
@@ -5,0 +5,0 @@ "keywords": [], |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
451772
7269