glad-web 1.0.38 → 1.0.39
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/lib/web/claude.js +22 -8
- package/package.json +1 -1
package/lib/web/claude.js
CHANGED
|
@@ -486,15 +486,29 @@
|
|
|
486
486
|
}
|
|
487
487
|
|
|
488
488
|
function inlineMarkdown(text) {
|
|
489
|
+
const protectedSegments = [];
|
|
490
|
+
const protect = value => `\uE000${protectedSegments.push(value) - 1}\uE001`;
|
|
491
|
+
const restore = value => value.replace(/\uE000(\d+)\uE001/g, (_match, index) => protectedSegments[Number(index)] || '');
|
|
492
|
+
const formatText = value => {
|
|
493
|
+
const codeSegments = [];
|
|
494
|
+
const protectCode = code => `\uE002${codeSegments.push(code) - 1}\uE003`;
|
|
495
|
+
const restoreCode = formatted => formatted.replace(/\uE002(\d+)\uE003/g, (_match, index) => codeSegments[Number(index)] || '');
|
|
496
|
+
let formatted = value.replace(/`([^`]+)`/g, (_match, code) => protectCode(`<code>${code}</code>`));
|
|
497
|
+
formatted = formatted.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>');
|
|
498
|
+
formatted = formatted.replace(/(^|[^\p{L}\p{N}_])__([^_\n]+)__(?![\p{L}\p{N}_])/gu, '$1<strong>$2</strong>');
|
|
499
|
+
formatted = formatted.replace(/\*([^*\n]+)\*/g, '<em>$1</em>');
|
|
500
|
+
formatted = formatted.replace(/(^|[^\p{L}\p{N}_])_([^_\n]+)_(?![\p{L}\p{N}_])/gu, '$1<em>$2</em>');
|
|
501
|
+
return restoreCode(formatted);
|
|
502
|
+
};
|
|
503
|
+
|
|
489
504
|
let html = escapeHtml(text || '');
|
|
490
|
-
html = html.replace(/`([^`]+)
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
return html;
|
|
505
|
+
html = html.replace(/`([^`]+)`|!\[([^\]]*)\]\((https?:\/\/[^)\s]+)\)|\[([^\]]+)\]\((https?:\/\/[^)\s]+)\)/g,
|
|
506
|
+
(_match, code, alt, imageUrl, label, linkUrl) => {
|
|
507
|
+
if (code !== undefined) return protect(`<code>${code}</code>`);
|
|
508
|
+
if (imageUrl !== undefined) return protect(`<img src="${imageUrl}" alt="${alt}">`);
|
|
509
|
+
return protect(`<a href="${linkUrl}" target="_blank" rel="noopener noreferrer">${formatText(label)}</a>`);
|
|
510
|
+
});
|
|
511
|
+
return restore(formatText(html));
|
|
498
512
|
}
|
|
499
513
|
|
|
500
514
|
function parseMarkdownFenceOpener(line) {
|