@mdream/js 1.1.2 → 1.2.2
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/dist/_chunks/parse.mjs
CHANGED
|
@@ -10,6 +10,14 @@ function resolveUrl(url, origin) {
|
|
|
10
10
|
}
|
|
11
11
|
return url;
|
|
12
12
|
}
|
|
13
|
+
function isAutolinkUri(s) {
|
|
14
|
+
if (!(s.startsWith("http://") || s.startsWith("https://") || s.startsWith("ftp://") || s.startsWith("mailto:"))) return false;
|
|
15
|
+
for (let i = 0; i < s.length; i++) {
|
|
16
|
+
const c = s.charCodeAt(i);
|
|
17
|
+
if (c === 32 || c === 60 || c === 62 || c === 10 || c === 13 || c === 9) return false;
|
|
18
|
+
}
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
13
21
|
function isInsideTableCell(node) {
|
|
14
22
|
return (node.depthMap[32] || 0) > 0 || (node.depthMap[31] || 0) > 0;
|
|
15
23
|
}
|
|
@@ -201,6 +209,24 @@ const tagHandlers = {
|
|
|
201
209
|
const href = resolveUrl(node.attributes?.href || "", state.options?.origin);
|
|
202
210
|
let title = node.attributes?.title;
|
|
203
211
|
if (state.lastContentCache === title) title = "";
|
|
212
|
+
if (!title && isAutolinkUri(href)) {
|
|
213
|
+
const buf = state.buffer;
|
|
214
|
+
let i = buf.length - 1;
|
|
215
|
+
let textLen = 0;
|
|
216
|
+
while (i >= 0) {
|
|
217
|
+
const entry = buf[i];
|
|
218
|
+
if (entry === "[") break;
|
|
219
|
+
textLen += entry.length;
|
|
220
|
+
i--;
|
|
221
|
+
}
|
|
222
|
+
if (i >= 0 && textLen === href.length && buf.slice(i + 1).join("") === href) {
|
|
223
|
+
buf.length = i;
|
|
224
|
+
const auto = `<${href}>`;
|
|
225
|
+
buf.push(auto);
|
|
226
|
+
state.lastContentCache = auto;
|
|
227
|
+
return "";
|
|
228
|
+
}
|
|
229
|
+
}
|
|
204
230
|
return title ? `](${href} "${title}")` : `](${href})`;
|
|
205
231
|
},
|
|
206
232
|
collapsesInnerWhiteSpace: true,
|
|
@@ -596,6 +622,7 @@ function buildTagOverrideHandlers(overrides) {
|
|
|
596
622
|
if (override.enter !== void 0) {
|
|
597
623
|
const enterStr = override.enter;
|
|
598
624
|
handler.enter = () => enterStr;
|
|
625
|
+
handler.literalEnter = true;
|
|
599
626
|
}
|
|
600
627
|
if (override.exit !== void 0) {
|
|
601
628
|
const exitStr = override.exit;
|
|
@@ -197,7 +197,7 @@ function createMarkdownProcessor(options = {}, resolvedPlugins = [], tagOverride
|
|
|
197
197
|
state.lastTextNode = void 0;
|
|
198
198
|
}
|
|
199
199
|
}
|
|
200
|
-
if (output[0]?.[0] && eventType === 0 && lastChar && needsSpacing(lastChar, output[0][0], state)) {
|
|
200
|
+
if (output[0]?.[0] && eventType === 0 && !node.tagHandler?.literalEnter && lastChar && needsSpacing(lastChar, output[0][0], state)) {
|
|
201
201
|
state.buffer.push(" ");
|
|
202
202
|
state.lastContentCache = " ";
|
|
203
203
|
}
|
package/dist/_chunks/src.mjs
CHANGED
|
@@ -164,18 +164,37 @@ function cleanEmptyLinks(md) {
|
|
|
164
164
|
}
|
|
165
165
|
return result;
|
|
166
166
|
}
|
|
167
|
+
function isAutolinkUri(s) {
|
|
168
|
+
if (!(s.startsWith("http://") || s.startsWith("https://") || s.startsWith("ftp://") || s.startsWith("mailto:"))) return false;
|
|
169
|
+
for (let i = 0; i < s.length; i++) {
|
|
170
|
+
const c = s.charCodeAt(i);
|
|
171
|
+
if (c === 32 || c === 60 || c === 62 || c === 10 || c === 13 || c === 9) return false;
|
|
172
|
+
}
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
167
175
|
function cleanRedundantLinks(md) {
|
|
168
176
|
const len = md.length;
|
|
169
177
|
let result = "";
|
|
170
178
|
let i = 0;
|
|
171
179
|
while (i < len) {
|
|
172
|
-
|
|
180
|
+
const code = md.charCodeAt(i);
|
|
181
|
+
if (code === 91) {
|
|
173
182
|
const link = parseLink(md, i);
|
|
174
183
|
if (link && link.text === link.url) {
|
|
175
184
|
result += link.text;
|
|
176
185
|
i = link.end;
|
|
177
186
|
continue;
|
|
178
187
|
}
|
|
188
|
+
} else if (code === 60) {
|
|
189
|
+
const close = md.indexOf(">", i + 1);
|
|
190
|
+
if (close !== -1) {
|
|
191
|
+
const inner = md.slice(i + 1, close);
|
|
192
|
+
if (isAutolinkUri(inner)) {
|
|
193
|
+
result += inner;
|
|
194
|
+
i = close + 1;
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
179
198
|
}
|
|
180
199
|
result += md[i];
|
|
181
200
|
i++;
|
package/dist/_chunks/types.d.mts
CHANGED
|
@@ -289,6 +289,12 @@ interface TagHandler {
|
|
|
289
289
|
isInline?: boolean;
|
|
290
290
|
spacing?: readonly [number, number];
|
|
291
291
|
excludesTextNodes?: boolean;
|
|
292
|
+
/**
|
|
293
|
+
* When true, the `enter` string is emitted verbatim without synthesizing a
|
|
294
|
+
* separating space before it. Set for user-supplied tagOverride enter
|
|
295
|
+
* strings so markers like `^`/`~` attach to adjacent content (issue #93).
|
|
296
|
+
*/
|
|
297
|
+
literalEnter?: boolean;
|
|
292
298
|
}
|
|
293
299
|
interface TailwindContext {
|
|
294
300
|
hidden?: boolean;
|
package/package.json
CHANGED