@mdream/js
Advanced tools
@@ -13,2 +13,10 @@ import { a as NO_SPACING, c as TABLE_ROW_SPACING, g as TagIdMap, i as LIST_ITEM_SPACING, t as BLOCKQUOTE_SPACING } from "./const.mjs"; | ||
| } | ||
| function isAutolinkUri(s) { | ||
| if (!(s.startsWith("http://") || s.startsWith("https://") || s.startsWith("ftp://") || s.startsWith("mailto:"))) return false; | ||
| for (let i = 0; i < s.length; i++) { | ||
| const c = s.charCodeAt(i); | ||
| if (c === 32 || c === 60 || c === 62 || c === 10 || c === 13 || c === 9) return false; | ||
| } | ||
| return true; | ||
| } | ||
| function isInsideTableCell(node) { | ||
@@ -205,2 +213,20 @@ return (node.depthMap[32] || 0) > 0 || (node.depthMap[31] || 0) > 0; | ||
| if (state.lastContentCache === title) title = ""; | ||
| if (!title && isAutolinkUri(href)) { | ||
| const buf = state.buffer; | ||
| let i = buf.length - 1; | ||
| let textLen = 0; | ||
| while (i >= 0) { | ||
| const entry = buf[i]; | ||
| if (entry === "[") break; | ||
| textLen += entry.length; | ||
| i--; | ||
| } | ||
| if (i >= 0 && textLen === href.length && buf.slice(i + 1).join("") === href) { | ||
| buf.length = i; | ||
| const auto = `<${href}>`; | ||
| buf.push(auto); | ||
| state.lastContentCache = auto; | ||
| return ""; | ||
| } | ||
| } | ||
| return title ? `](${href} "${title}")` : `](${href})`; | ||
@@ -207,0 +233,0 @@ }, |
+20
-1
@@ -167,2 +167,10 @@ import "./const.mjs"; | ||
| } | ||
| function isAutolinkUri(s) { | ||
| if (!(s.startsWith("http://") || s.startsWith("https://") || s.startsWith("ftp://") || s.startsWith("mailto:"))) return false; | ||
| for (let i = 0; i < s.length; i++) { | ||
| const c = s.charCodeAt(i); | ||
| if (c === 32 || c === 60 || c === 62 || c === 10 || c === 13 || c === 9) return false; | ||
| } | ||
| return true; | ||
| } | ||
| function cleanRedundantLinks(md) { | ||
@@ -173,3 +181,4 @@ const len = md.length; | ||
| while (i < len) { | ||
| if (md.charCodeAt(i) === 91) { | ||
| const code = md.charCodeAt(i); | ||
| if (code === 91) { | ||
| const link = parseLink(md, i); | ||
@@ -181,2 +190,12 @@ if (link && link.text === link.url) { | ||
| } | ||
| } else if (code === 60) { | ||
| const close = md.indexOf(">", i + 1); | ||
| if (close !== -1) { | ||
| const inner = md.slice(i + 1, close); | ||
| if (isAutolinkUri(inner)) { | ||
| result += inner; | ||
| i = close + 1; | ||
| continue; | ||
| } | ||
| } | ||
| } | ||
@@ -183,0 +202,0 @@ result += md[i]; |
+1
-1
| { | ||
| "name": "@mdream/js", | ||
| "type": "module", | ||
| "version": "1.1.2", | ||
| "version": "1.2.1", | ||
| "description": "JavaScript HTML-to-Markdown engine for mdream. Escape hatch for hooks and edge runtimes.", | ||
@@ -6,0 +6,0 @@ "author": { |
160711
0.87%3561
1.28%