@lobehub/ui 2.8.6 → 2.9.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/es/Markdown/markdown.style.js +16 -15
- package/es/Markdown/plugins/remarkBr.d.ts +6 -0
- package/es/Markdown/plugins/remarkBr.js +104 -0
- package/es/hooks/useMarkdown/fixMarkdownEmphasisSpacing.d.ts +1 -0
- package/es/hooks/useMarkdown/fixMarkdownEmphasisSpacing.js +244 -0
- package/es/hooks/useMarkdown/useMarkdownComponents.js +7 -1
- package/es/hooks/useMarkdown/useMarkdownRemarkPlugins.js +5 -3
- package/es/hooks/useMarkdown/utils.d.ts +0 -8
- package/es/hooks/useMarkdown/utils.js +2 -70
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12, _templateObject13, _templateObject14, _templateObject15, _templateObject16, _templateObject17;
|
|
1
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12, _templateObject13, _templateObject14, _templateObject15, _templateObject16, _templateObject17, _templateObject18;
|
|
2
2
|
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
3
3
|
import { createStyles } from 'antd-style';
|
|
4
4
|
var IGNORE_CLASSNAME = '.ignore-markdown-style';
|
|
@@ -18,21 +18,22 @@ export var useStyles = createStyles(function (_ref, _ref2) {
|
|
|
18
18
|
var a = css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n a:not(", " a) {\n color: ", ";\n\n &:hover {\n color: ", ";\n }\n }\n "])), IGNORE_CLASSNAME, token.colorInfoText, token.colorInfoHover);
|
|
19
19
|
var blockquote = css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n blockquote:not(", " blockquote) {\n margin-block: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n margin-inline: 0;\n padding-block: 0;\n padding-inline: 1em;\n border-inline-start: solid 4px ", ";\n\n color: ", ";\n }\n "])), IGNORE_CLASSNAME, token.colorBorder, token.colorTextSecondary);
|
|
20
20
|
var code = css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n code:not(", " code) {\n &:not(:has(span)) {\n display: inline;\n\n margin-inline: 0.25em;\n padding-block: 0.2em;\n padding-inline: 0.4em;\n border: 1px solid var(--lobe-markdown-border-color);\n border-radius: 0.25em;\n\n font-family: ", ";\n font-size: 0.875em;\n line-height: 1;\n word-break: break-word;\n white-space: break-spaces;\n\n background: ", ";\n }\n }\n "])), IGNORE_CLASSNAME, token.fontFamilyCode, token.colorFillSecondary);
|
|
21
|
-
var
|
|
22
|
-
var
|
|
23
|
-
var
|
|
24
|
-
var
|
|
25
|
-
var
|
|
26
|
-
var
|
|
27
|
-
var
|
|
28
|
-
var
|
|
29
|
-
var
|
|
30
|
-
var
|
|
31
|
-
var
|
|
32
|
-
var
|
|
33
|
-
var
|
|
21
|
+
var del = css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n del:not(", " del) {\n color: ", ";\n text-decoration: line-through;\n }\n "])), IGNORE_CLASSNAME, token.colorTextDescription);
|
|
22
|
+
var details = css(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n details:not(", " details) {\n margin-block: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n padding-block: 0.75em;\n padding-inline: 1em;\n border-radius: calc(var(--lobe-markdown-border-radius) * 1px);\n\n background: ", ";\n box-shadow: 0 0 0 1px var(--lobe-markdown-border-color);\n\n summary {\n cursor: pointer;\n display: flex;\n align-items: center;\n list-style: none;\n\n &::before {\n content: '';\n\n position: absolute;\n inset-inline-end: 1.25em;\n transform: rotateZ(-45deg);\n\n display: block;\n\n width: 0.4em;\n height: 0.4em;\n border-block-end: 1.5px solid ", ";\n border-inline-end: 1.5px solid ", ";\n\n font-family: ", ";\n\n transition: transform 200ms ", ";\n }\n }\n\n &[open] {\n summary {\n padding-block-end: 0.75em;\n border-block-end: 1px dashed ", ";\n\n &::before {\n transform: rotateZ(45deg);\n }\n }\n }\n }\n "])), IGNORE_CLASSNAME, token.colorFillTertiary, token.colorTextSecondary, token.colorTextSecondary, token.fontFamily, token.motionEaseOut, token.colorBorder);
|
|
23
|
+
var header = css(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["\n h1:not(", " h1),\n h2:not(", " h2),\n h3:not(", " h3),\n h4:not(", " h4),\n h5:not(", " h5),\n h6:not(", " h6) {\n margin-block: max(\n calc(var(--lobe-markdown-header-multiple) * var(--lobe-markdown-margin-multiple) * 0.4em),\n var(--lobe-markdown-font-size)\n );\n font-weight: bold;\n line-height: 1.25;\n }\n\n h1:not(", " h1) {\n font-size: calc(\n var(--lobe-markdown-font-size) * (1 + 1.5 * var(--lobe-markdown-header-multiple))\n );\n }\n\n h2:not(", " h2) {\n font-size: calc(\n var(--lobe-markdown-font-size) * (1 + var(--lobe-markdown-header-multiple))\n );\n }\n\n h3:not(", " h3) {\n font-size: calc(\n var(--lobe-markdown-font-size) * (1 + 0.5 * var(--lobe-markdown-header-multiple))\n );\n }\n\n h4:not(", " h4) {\n font-size: calc(\n var(--lobe-markdown-font-size) * (1 + 0.25 * var(--lobe-markdown-header-multiple))\n );\n }\n\n h5:not(", " h5),\n h6:not(", " h6) {\n font-size: calc(var(--lobe-markdown-font-size) * 1);\n }\n "])), IGNORE_CLASSNAME, IGNORE_CLASSNAME, IGNORE_CLASSNAME, IGNORE_CLASSNAME, IGNORE_CLASSNAME, IGNORE_CLASSNAME, IGNORE_CLASSNAME, IGNORE_CLASSNAME, IGNORE_CLASSNAME, IGNORE_CLASSNAME, IGNORE_CLASSNAME, IGNORE_CLASSNAME);
|
|
24
|
+
var hr = css(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["\n hr:not(", " hr) {\n width: 100%;\n margin-block: calc(var(--lobe-markdown-margin-multiple) * 1.5em);\n border-color: ", ";\n border-style: dashed;\n border-width: 1px;\n border-block-start: none;\n border-inline-start: none;\n border-inline-end: none;\n }\n "])), IGNORE_CLASSNAME, token.colorBorder);
|
|
25
|
+
var img = css(_templateObject9 || (_templateObject9 = _taggedTemplateLiteral(["\n img:not(", " img) {\n max-width: 100%;\n }\n\n > img,\n > p > img {\n margin-block: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n border-radius: calc(var(--lobe-markdown-border-radius) * 1px);\n box-shadow: 0 0 0 1px var(--lobe-markdown-border-color);\n }\n "])), IGNORE_CLASSNAME);
|
|
26
|
+
var kbd = css(_templateObject10 || (_templateObject10 = _taggedTemplateLiteral(["\n kbd:not(", " kbd) {\n cursor: default;\n\n display: inline-block;\n\n min-width: 1em;\n margin-inline: 0.25em;\n padding-block: 0.2em;\n padding-inline: 0.4em;\n border: 1px solid ", ";\n border-radius: 0.25em;\n\n font-family: ", ";\n font-size: 0.875em;\n font-weight: 500;\n line-height: 1;\n text-align: center;\n\n background: ", ";\n }\n "])), IGNORE_CLASSNAME, token.colorBorderSecondary, token.fontFamily, token.colorBgLayout);
|
|
27
|
+
var list = css(_templateObject11 || (_templateObject11 = _taggedTemplateLiteral(["\n li:not(", " li) {\n margin-block: calc(var(--lobe-markdown-margin-multiple) * 0.33em);\n\n p {\n display: inline;\n }\n }\n\n ul:not(", " ul),\n ol:not(", " ol) {\n margin-block: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n margin-inline-start: 1em;\n padding-inline-start: 0;\n list-style-position: outside;\n\n > ul,\n > ol {\n margin-block: 0;\n }\n\n > li {\n margin-inline-start: 1em;\n }\n }\n\n ol:not(", " ol) {\n list-style: auto;\n }\n\n ul:not(", " ul) {\n list-style-type: none;\n\n > li {\n &::before {\n content: '-';\n display: inline-block;\n margin-inline: -1em 0.5em;\n opacity: 0.5;\n }\n }\n }\n "])), IGNORE_CLASSNAME, IGNORE_CLASSNAME, IGNORE_CLASSNAME, IGNORE_CLASSNAME, IGNORE_CLASSNAME);
|
|
28
|
+
var p = css(_templateObject12 || (_templateObject12 = _taggedTemplateLiteral(["\n p:not(", " kbd) {\n margin-block: 4px;\n line-height: var(--lobe-markdown-line-height);\n letter-spacing: 0.02em;\n\n &:not(:first-child) {\n margin-block-start: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n }\n\n &:not(:last-child) {\n margin-block-end: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n }\n }\n "])), IGNORE_CLASSNAME);
|
|
29
|
+
var pre = css(_templateObject13 || (_templateObject13 = _taggedTemplateLiteral(["\n pre {\n font-size: calc(var(--lobe-markdown-font-size) * 0.85);\n }\n "])));
|
|
30
|
+
var strong = css(_templateObject14 || (_templateObject14 = _taggedTemplateLiteral(["\n strong:not(", " strong) {\n font-weight: 600;\n }\n "])), IGNORE_CLASSNAME);
|
|
31
|
+
var svg = css(_templateObject15 || (_templateObject15 = _taggedTemplateLiteral(["\n svg:not(", " svg) {\n line-height: 1;\n }\n "])), IGNORE_CLASSNAME);
|
|
32
|
+
var table = css(_templateObject16 || (_templateObject16 = _taggedTemplateLiteral(["\n table:not(", " table) {\n unicode-bidi: isolate;\n overflow: auto hidden;\n display: block;\n border-spacing: 0;\n border-collapse: collapse;\n\n box-sizing: border-box;\n width: max-content;\n max-width: 100%;\n margin-block: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n border-radius: calc(var(--lobe-markdown-border-radius) * 1px);\n\n text-align: start;\n text-indent: initial;\n text-wrap: pretty;\n word-break: auto-phrase;\n overflow-wrap: break-word;\n\n background: ", ";\n box-shadow: 0 0 0 1px var(--lobe-markdown-border-color);\n\n code {\n word-break: break-word;\n }\n\n thead {\n background: ", ";\n }\n\n tr {\n box-shadow: 0 1px 0 var(--lobe-markdown-border-color);\n }\n\n th,\n td {\n min-width: 120px;\n padding-block: 0.75em;\n padding-inline: 1em;\n text-align: start;\n }\n }\n "])), IGNORE_CLASSNAME, token.colorFillQuaternary, token.colorFillQuaternary);
|
|
33
|
+
var video = css(_templateObject17 || (_templateObject17 = _taggedTemplateLiteral(["\n > video:not(", " video),\n > p:not(", " p) > video {\n margin-block: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n border-radius: calc(var(--lobe-markdown-border-radius) * 1px);\n box-shadow: 0 0 0 1px var(--lobe-markdown-border-color);\n }\n\n video:not(", " video) {\n max-width: 100%;\n }\n "])), IGNORE_CLASSNAME, IGNORE_CLASSNAME, IGNORE_CLASSNAME);
|
|
34
|
+
var gfm = css(_templateObject18 || (_templateObject18 = _taggedTemplateLiteral(["\n .markdown-alert {\n margin-block: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n padding-inline-start: 1em;\n border-inline-start: solid 4px ", ";\n\n > p {\n margin-block-start: 0 !important;\n }\n }\n\n .markdown-alert > :first-child {\n margin-block-start: 0;\n }\n\n .markdown-alert > :last-child {\n margin-block-end: 0;\n }\n\n .markdown-alert-note {\n border-inline-start-color: ", ";\n }\n\n .markdown-alert-tip {\n border-inline-start-color: ", ";\n }\n\n .markdown-alert-important {\n border-inline-start-color: ", ";\n }\n\n .markdown-alert-warning {\n border-inline-start-color: ", ";\n }\n\n .markdown-alert-caution {\n border-inline-start-color: ", ";\n }\n\n .markdown-alert-title {\n display: flex;\n align-items: center;\n margin-block-end: 0.5em !important;\n font-weight: 500;\n }\n\n .markdown-alert-note .markdown-alert-title {\n color: ", ";\n fill: ", ";\n }\n\n .markdown-alert-tip .markdown-alert-title {\n color: ", ";\n fill: ", ";\n }\n\n .markdown-alert-important .markdown-alert-title {\n color: ", ";\n fill: ", ";\n }\n\n .markdown-alert-warning .markdown-alert-title {\n color: ", ";\n fill: ", ";\n }\n\n .markdown-alert-caution .markdown-alert-title {\n color: ", ";\n fill: ", ";\n }\n\n .octicon {\n overflow: visible !important;\n display: inline-block;\n margin-inline-end: 0.5em;\n vertical-align: text-bottom;\n }\n\n .task-list-item {\n &::before {\n display: none !important;\n }\n\n input[type='checkbox'] {\n margin-block: 0 0.25em;\n margin-inline: -1.6em 0.2em;\n vertical-align: middle;\n }\n\n input[type='checkbox']:dir(rtl) {\n margin: 0 -1.6em 0.25em 0.2em;\n }\n }\n\n /* Style the footnotes section. */\n\n .footnotes {\n margin-block-start: calc(var(--lobe-markdown-margin-multiple) * 1em);\n font-size: smaller;\n color: #8b949e;\n\n #footnote-label {\n display: none;\n }\n\n > ol {\n margin: 0 !important;\n }\n }\n\n .sr-only {\n position: absolute;\n\n overflow: hidden;\n\n width: 1px;\n height: 1px;\n padding: 0;\n border: 0;\n\n word-wrap: normal;\n\n clip: rect(0, 0, 0, 0);\n }\n\n sup:has(a[aria-describedby='footnote-label']) {\n margin-inline: 2px;\n vertical-align: super !important;\n\n [data-footnote-ref] {\n display: inline-block;\n\n width: 16px;\n height: 16px;\n border-radius: 4px;\n\n font-family: ", ";\n font-size: 10px;\n color: ", " !important;\n text-align: center;\n\n background: ", ";\n }\n }\n "])), token.colorBorder, token.colorInfo, token.colorSuccess, token.purple, token.colorWarning, token.colorError, token.colorInfo, token.colorInfo, token.colorSuccess, token.colorSuccess, token.purple, token.purple, token.colorWarning, token.colorWarning, token.colorError, token.colorError, token.fontFamilyCode, token.colorTextSecondary, token.colorFillSecondary);
|
|
34
35
|
return {
|
|
35
36
|
root: __root,
|
|
36
|
-
variant: cx(a, blockquote, code, details, header, hr, img, kbd, list, p, pre, strong, svg, table, video, gfm)
|
|
37
|
+
variant: cx(a, blockquote, code, del, details, header, hr, img, kbd, list, p, pre, strong, svg, table, video, gfm)
|
|
37
38
|
};
|
|
38
39
|
});
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
4
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
5
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
6
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
7
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
8
|
+
import { visit } from 'unist-util-visit';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Remark plugin to handle <br> and <br/> tags in markdown text
|
|
12
|
+
* This plugin converts <br> and <br/> tags to proper HTML elements
|
|
13
|
+
* without requiring allowHtml to be enabled
|
|
14
|
+
*/
|
|
15
|
+
export var remarkBr = function remarkBr() {
|
|
16
|
+
return function (tree) {
|
|
17
|
+
// First try to process html nodes that might contain ONLY br tags
|
|
18
|
+
visit(tree, 'html', function (node, index, parent) {
|
|
19
|
+
if (!node.value || typeof node.value !== 'string') return;
|
|
20
|
+
|
|
21
|
+
// Only handle standalone br tags, not complex HTML containing br tags
|
|
22
|
+
var brRegex = /^\s*<\s*br\s*\/?>\s*$/gi;
|
|
23
|
+
if (brRegex.test(node.value)) {
|
|
24
|
+
// Replace the html node with a break node
|
|
25
|
+
parent.children.splice(index, 1, {
|
|
26
|
+
type: 'break'
|
|
27
|
+
});
|
|
28
|
+
return index;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// Also process text nodes
|
|
33
|
+
visit(tree, 'text', function (node) {
|
|
34
|
+
var index = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
35
|
+
var parent = arguments.length > 2 ? arguments[2] : undefined;
|
|
36
|
+
if (!node.value || typeof node.value !== 'string') return;
|
|
37
|
+
|
|
38
|
+
// Check if the text contains <br> or <br/> tags
|
|
39
|
+
var brRegex = /<\s*br\s*\/?>/gi;
|
|
40
|
+
if (!brRegex.test(node.value)) return;
|
|
41
|
+
|
|
42
|
+
// Reset regex lastIndex for split operation
|
|
43
|
+
brRegex.lastIndex = 0;
|
|
44
|
+
|
|
45
|
+
// Split the text by br tags, but keep the matched tags
|
|
46
|
+
var parts = [];
|
|
47
|
+
var matches = [];
|
|
48
|
+
var lastIndex = 0;
|
|
49
|
+
var match;
|
|
50
|
+
while ((match = brRegex.exec(node.value)) !== null) {
|
|
51
|
+
// Add text before the match
|
|
52
|
+
if (match.index > lastIndex) {
|
|
53
|
+
parts.push(node.value.slice(lastIndex, match.index));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Store the matched br tag
|
|
57
|
+
matches.push(match[0]);
|
|
58
|
+
lastIndex = match.index + match[0].length;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Add remaining text after the last match
|
|
62
|
+
if (lastIndex < node.value.length) {
|
|
63
|
+
parts.push(node.value.slice(lastIndex));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Create new nodes
|
|
67
|
+
var newNodes = [];
|
|
68
|
+
var _iterator = _createForOfIteratorHelper(parts.entries()),
|
|
69
|
+
_step;
|
|
70
|
+
try {
|
|
71
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
72
|
+
var _step$value = _slicedToArray(_step.value, 2),
|
|
73
|
+
i = _step$value[0],
|
|
74
|
+
part = _step$value[1];
|
|
75
|
+
// Add text node if not empty
|
|
76
|
+
if (part) {
|
|
77
|
+
newNodes.push({
|
|
78
|
+
type: 'text',
|
|
79
|
+
value: part
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Add br element if we have a corresponding match
|
|
84
|
+
if (i < matches.length) {
|
|
85
|
+
newNodes.push({
|
|
86
|
+
type: 'break'
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Replace the original text node with the new nodes
|
|
92
|
+
} catch (err) {
|
|
93
|
+
_iterator.e(err);
|
|
94
|
+
} finally {
|
|
95
|
+
_iterator.f();
|
|
96
|
+
}
|
|
97
|
+
if (newNodes.length > 0) {
|
|
98
|
+
var _parent$children;
|
|
99
|
+
(_parent$children = parent.children).splice.apply(_parent$children, [index, 1].concat(newNodes));
|
|
100
|
+
return index + newNodes.length - 1; // Skip the newly added nodes
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function fixMarkdownEmphasisSpacing(text: string): string;
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
function splitInlineCode(text) {
|
|
2
|
+
var segments = [];
|
|
3
|
+
var currentPos = 0;
|
|
4
|
+
|
|
5
|
+
// 匹配行内代码,支持多个反引号
|
|
6
|
+
var inlineCodeRegex = /(`+)([^`]*?)\1/g;
|
|
7
|
+
var match;
|
|
8
|
+
while ((match = inlineCodeRegex.exec(text)) !== null) {
|
|
9
|
+
// 添加代码前的普通文本
|
|
10
|
+
if (match.index > currentPos) {
|
|
11
|
+
segments.push({
|
|
12
|
+
content: text.slice(currentPos, match.index),
|
|
13
|
+
isCode: false
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// 添加行内代码
|
|
18
|
+
segments.push({
|
|
19
|
+
content: match[0],
|
|
20
|
+
isCode: true
|
|
21
|
+
});
|
|
22
|
+
currentPos = match.index + match[0].length;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// 添加最后剩余的普通文本
|
|
26
|
+
if (currentPos < text.length) {
|
|
27
|
+
segments.push({
|
|
28
|
+
content: text.slice(currentPos),
|
|
29
|
+
isCode: false
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return segments;
|
|
33
|
+
}
|
|
34
|
+
function applyEmphasisFixes(text) {
|
|
35
|
+
var result = text;
|
|
36
|
+
|
|
37
|
+
// Step 1: Remove trailing spaces inside emphasis markers
|
|
38
|
+
var removeInternalSpaces = [
|
|
39
|
+
// 处理 **bold** 格式(两个星号)- 只处理一个空格
|
|
40
|
+
{
|
|
41
|
+
pattern: /(\*\*)([^\n*]+?)( )(\*\*)/g,
|
|
42
|
+
replacement: '$1$2$4'
|
|
43
|
+
},
|
|
44
|
+
// 处理 __bold__ 格式(两个下划线)- 只处理一个空格
|
|
45
|
+
{
|
|
46
|
+
pattern: /(__)([^\n_]+?)( )(__)/g,
|
|
47
|
+
replacement: '$1$2$4'
|
|
48
|
+
},
|
|
49
|
+
// 处理 ~~strikethrough~~ 格式(删除线)- 只处理一个空格
|
|
50
|
+
{
|
|
51
|
+
pattern: /(~~)([^\n~]+?)( )(~~)/g,
|
|
52
|
+
replacement: '$1$2$4'
|
|
53
|
+
},
|
|
54
|
+
// 处理单个 * 格式 - 只处理一个空格,使用更精确的边界匹配
|
|
55
|
+
{
|
|
56
|
+
pattern: /(^|[^\w*])(\*(?!\*))([^\n*]+?)( )(\*(?!\*))/g,
|
|
57
|
+
replacement: '$1$2$3$5'
|
|
58
|
+
},
|
|
59
|
+
// 处理单个 _ 格式 - 只处理一个空格,使用更精确的边界匹配
|
|
60
|
+
{
|
|
61
|
+
pattern: /(^|\W)(_(?!_))([^\n_]+?)( )(_(?!_))/g,
|
|
62
|
+
replacement: '$1$2$3$5'
|
|
63
|
+
}];
|
|
64
|
+
result = removeInternalSpaces.reduce(function (text, _ref) {
|
|
65
|
+
var pattern = _ref.pattern,
|
|
66
|
+
replacement = _ref.replacement;
|
|
67
|
+
return text.replace(pattern, replacement);
|
|
68
|
+
}, result);
|
|
69
|
+
|
|
70
|
+
// Step 2: Add space after closing emphasis markers when followed by symbols/punctuation/Chinese characters
|
|
71
|
+
// Define emphasis patterns
|
|
72
|
+
var emphasisPatterns = [
|
|
73
|
+
// ** (bold)
|
|
74
|
+
{
|
|
75
|
+
markerChar: '*',
|
|
76
|
+
pattern: /(\*\*)([^\n*]*?)(\*\*)(\S)/g
|
|
77
|
+
},
|
|
78
|
+
// __ (bold)
|
|
79
|
+
{
|
|
80
|
+
markerChar: '_',
|
|
81
|
+
pattern: /(__)([^\n_]*?)(__)(\S)/g
|
|
82
|
+
},
|
|
83
|
+
// * (italic) - need to avoid matching **
|
|
84
|
+
{
|
|
85
|
+
markerChar: '*',
|
|
86
|
+
pattern: /(\*(?!\*))([^\n*]*?)(\*(?!\*))(\S)/g
|
|
87
|
+
},
|
|
88
|
+
// _ (italic) - need to avoid matching __
|
|
89
|
+
{
|
|
90
|
+
markerChar: '_',
|
|
91
|
+
pattern: /(_(?!_))([^\n_]*?)(_(?!_))(\S)/g
|
|
92
|
+
},
|
|
93
|
+
// ~~ (strikethrough)
|
|
94
|
+
{
|
|
95
|
+
markerChar: '~',
|
|
96
|
+
pattern: /(~~)([^\n~]*?)(~~)(\S)/g
|
|
97
|
+
}];
|
|
98
|
+
|
|
99
|
+
// Apply space after closing markers for each emphasis type
|
|
100
|
+
for (var _i = 0, _emphasisPatterns = emphasisPatterns; _i < _emphasisPatterns.length; _i++) {
|
|
101
|
+
var pattern = _emphasisPatterns[_i].pattern;
|
|
102
|
+
result = result.replaceAll(pattern, function (match, start, content, end, nextChar) {
|
|
103
|
+
// Check if the content ends with a symbol/punctuation (like :, :, etc.)
|
|
104
|
+
var lastChar = content.slice(-1);
|
|
105
|
+
var isSymbolOrPunctuation = /[!"#$%&'()*+,./:;<=>?@[\\\]^_`{|}~、。《》【】!(),:;?{|}-]/.test(lastChar);
|
|
106
|
+
|
|
107
|
+
// If content ends with symbol/punctuation and next character is not whitespace, add space
|
|
108
|
+
if (isSymbolOrPunctuation && nextChar && !/\s/.test(nextChar)) {
|
|
109
|
+
return start + content + end + ' ' + nextChar;
|
|
110
|
+
}
|
|
111
|
+
return match;
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Step 3: Add space before opening emphasis markers when preceded by non-whitespace and first char is symbol/punctuation
|
|
116
|
+
var beforeEmphasisPatterns = [
|
|
117
|
+
// ** (bold)
|
|
118
|
+
{
|
|
119
|
+
markerChar: '*',
|
|
120
|
+
pattern: /(\S)(\*\*)([^\n*]*?)(\*\*)/g
|
|
121
|
+
},
|
|
122
|
+
// __ (bold)
|
|
123
|
+
{
|
|
124
|
+
markerChar: '_',
|
|
125
|
+
pattern: /(\S)(__)([^\n_]*?)(__)/g
|
|
126
|
+
},
|
|
127
|
+
// * (italic) - need to avoid matching **
|
|
128
|
+
{
|
|
129
|
+
markerChar: '*',
|
|
130
|
+
pattern: /(\S)(\*(?!\*))([^\n*]*?)(\*(?!\*))/g
|
|
131
|
+
},
|
|
132
|
+
// _ (italic) - need to avoid matching __
|
|
133
|
+
{
|
|
134
|
+
markerChar: '_',
|
|
135
|
+
pattern: /(\S)(_(?!_))([^\n_]*?)(_(?!_))/g
|
|
136
|
+
},
|
|
137
|
+
// ~~ (strikethrough)
|
|
138
|
+
{
|
|
139
|
+
markerChar: '~',
|
|
140
|
+
pattern: /(\S)(~~)([^\n~]*?)(~~)/g
|
|
141
|
+
}];
|
|
142
|
+
|
|
143
|
+
// Apply space before opening markers for each emphasis type
|
|
144
|
+
for (var _i2 = 0, _beforeEmphasisPatter = beforeEmphasisPatterns; _i2 < _beforeEmphasisPatter.length; _i2++) {
|
|
145
|
+
var _pattern = _beforeEmphasisPatter[_i2].pattern;
|
|
146
|
+
result = result.replaceAll(_pattern, function (match, prevChar, start, content, end) {
|
|
147
|
+
// Check if the content starts with a symbol/punctuation (like :, :, ", (, etc.)
|
|
148
|
+
var firstChar = content.charAt(0);
|
|
149
|
+
var isSymbolOrPunctuation = /[!"#$%&'()*+,./:;<=>?@[\\\]^_`{|}~、。《》【】!(),:;?{|}-]/.test(firstChar);
|
|
150
|
+
|
|
151
|
+
// If previous character is not whitespace and content starts with symbol/punctuation, add space before
|
|
152
|
+
if (prevChar && !/\s/.test(prevChar) && isSymbolOrPunctuation) {
|
|
153
|
+
return prevChar + ' ' + start + content + end;
|
|
154
|
+
}
|
|
155
|
+
return match;
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Step 4: Re-run step 2 after step 3 to handle cases where both before and after spaces are needed
|
|
160
|
+
for (var _i3 = 0, _emphasisPatterns2 = emphasisPatterns; _i3 < _emphasisPatterns2.length; _i3++) {
|
|
161
|
+
var _pattern2 = _emphasisPatterns2[_i3].pattern;
|
|
162
|
+
result = result.replaceAll(_pattern2, function (match, start, content, end, nextChar) {
|
|
163
|
+
// Check if the content ends with a symbol/punctuation (like :, :, etc.)
|
|
164
|
+
var lastChar = content.slice(-1);
|
|
165
|
+
var isSymbolOrPunctuation = /[!"#$%&'()*+,./:;<=>?@[\\\]^_`{|}~、。《》【】!(),:;?{|}-]/.test(lastChar);
|
|
166
|
+
|
|
167
|
+
// If content ends with symbol/punctuation and next character is not whitespace, add space
|
|
168
|
+
if (isSymbolOrPunctuation && nextChar && !/\s/.test(nextChar)) {
|
|
169
|
+
return start + content + end + ' ' + nextChar;
|
|
170
|
+
}
|
|
171
|
+
return match;
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
return result;
|
|
175
|
+
}
|
|
176
|
+
function splitMarkdownWithAllCodeTypes(text) {
|
|
177
|
+
var segments = [];
|
|
178
|
+
var lines = text.split('\n');
|
|
179
|
+
var currentSegment = '';
|
|
180
|
+
var isInCodeBlock = false;
|
|
181
|
+
var codeBlockType = null; // 'fenced' | 'indented'
|
|
182
|
+
|
|
183
|
+
for (var i = 0; i < lines.length; i++) {
|
|
184
|
+
var line = lines[i];
|
|
185
|
+
|
|
186
|
+
// 检查围栏代码块的开始/结束
|
|
187
|
+
var fencedCodeMatch = line.match(/^(\s*)(```|~~~)/);
|
|
188
|
+
if (fencedCodeMatch && !isInCodeBlock) {
|
|
189
|
+
// 开始围栏代码块
|
|
190
|
+
if (currentSegment) {
|
|
191
|
+
segments.push({
|
|
192
|
+
content: currentSegment,
|
|
193
|
+
isCode: false
|
|
194
|
+
});
|
|
195
|
+
currentSegment = '';
|
|
196
|
+
}
|
|
197
|
+
isInCodeBlock = true;
|
|
198
|
+
codeBlockType = 'fenced';
|
|
199
|
+
currentSegment = line + (i < lines.length - 1 ? '\n' : '');
|
|
200
|
+
} else if (fencedCodeMatch && isInCodeBlock && codeBlockType === 'fenced') {
|
|
201
|
+
// 结束围栏代码块
|
|
202
|
+
currentSegment += line + (i < lines.length - 1 ? '\n' : '');
|
|
203
|
+
segments.push({
|
|
204
|
+
content: currentSegment,
|
|
205
|
+
isCode: true
|
|
206
|
+
});
|
|
207
|
+
currentSegment = '';
|
|
208
|
+
isInCodeBlock = false;
|
|
209
|
+
codeBlockType = null;
|
|
210
|
+
} else if (isInCodeBlock) {
|
|
211
|
+
// 在代码块内部
|
|
212
|
+
currentSegment += line + (i < lines.length - 1 ? '\n' : '');
|
|
213
|
+
} else {
|
|
214
|
+
// 普通行,但需要检查行内代码
|
|
215
|
+
currentSegment += line + (i < lines.length - 1 ? '\n' : '');
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// 处理最后的片段
|
|
220
|
+
if (currentSegment) {
|
|
221
|
+
segments.push({
|
|
222
|
+
content: currentSegment,
|
|
223
|
+
isCode: isInCodeBlock
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// 进一步处理行内代码
|
|
228
|
+
return segments.flatMap(function (segment) {
|
|
229
|
+
if (segment.isCode) {
|
|
230
|
+
return [segment];
|
|
231
|
+
}
|
|
232
|
+
return splitInlineCode(segment.content);
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
export function fixMarkdownEmphasisSpacing(text) {
|
|
236
|
+
// 更完善的代码块识别,包括缩进代码块
|
|
237
|
+
var segments = splitMarkdownWithAllCodeTypes(text);
|
|
238
|
+
return segments.map(function (segment) {
|
|
239
|
+
if (segment.isCode) {
|
|
240
|
+
return segment.content;
|
|
241
|
+
}
|
|
242
|
+
return applyEmphasisFixes(segment.content);
|
|
243
|
+
}).join('');
|
|
244
|
+
}
|
|
@@ -80,15 +80,21 @@ export var useMarkdownComponents = function useMarkdownComponents() {
|
|
|
80
80
|
}, stableComponentProps), componentProps === null || componentProps === void 0 ? void 0 : componentProps.pre), props));
|
|
81
81
|
};
|
|
82
82
|
}, [animated, enableMermaid, fullFeaturedCodeBlock, stableComponentProps, componentProps === null || componentProps === void 0 ? void 0 : componentProps.pre]);
|
|
83
|
+
var memoBr = useMemo(function () {
|
|
84
|
+
return function () {
|
|
85
|
+
return /*#__PURE__*/_jsx("br", {});
|
|
86
|
+
};
|
|
87
|
+
}, []);
|
|
83
88
|
var memoComponents = useMemo(function () {
|
|
84
89
|
return {
|
|
85
90
|
a: memoA,
|
|
91
|
+
br: memoBr,
|
|
86
92
|
img: memoImg,
|
|
87
93
|
pre: memoPre,
|
|
88
94
|
section: memoSection,
|
|
89
95
|
video: memoVideo
|
|
90
96
|
};
|
|
91
|
-
}, [memoA, memoImg, memoVideo, memoPre, memoSection]);
|
|
97
|
+
}, [memoA, memoBr, memoImg, memoVideo, memoPre, memoSection]);
|
|
92
98
|
return useMemo(function () {
|
|
93
99
|
return _objectSpread(_objectSpread({}, memoComponents), components);
|
|
94
100
|
}, [memoComponents, components]);
|
|
@@ -12,6 +12,7 @@ import remarkGfm from 'remark-gfm';
|
|
|
12
12
|
import remarkMath from 'remark-math';
|
|
13
13
|
import { useMarkdownContext } from "../../Markdown/components/MarkdownProvider";
|
|
14
14
|
import { remarkCustomFootnotes } from "../../Markdown/plugins/footnote";
|
|
15
|
+
import { remarkBr } from "../../Markdown/plugins/remarkBr";
|
|
15
16
|
export var useMarkdownRemarkPlugins = function useMarkdownRemarkPlugins() {
|
|
16
17
|
var _useMarkdownContext = useMarkdownContext(),
|
|
17
18
|
enableLatex = _useMarkdownContext.enableLatex,
|
|
@@ -20,13 +21,14 @@ export var useMarkdownRemarkPlugins = function useMarkdownRemarkPlugins() {
|
|
|
20
21
|
remarkPlugins = _useMarkdownContext$r === void 0 ? [] : _useMarkdownContext$r,
|
|
21
22
|
_useMarkdownContext$r2 = _useMarkdownContext.remarkPluginsAhead,
|
|
22
23
|
remarkPluginsAhead = _useMarkdownContext$r2 === void 0 ? [] : _useMarkdownContext$r2,
|
|
23
|
-
variant = _useMarkdownContext.variant
|
|
24
|
+
variant = _useMarkdownContext.variant,
|
|
25
|
+
allowHtml = _useMarkdownContext.allowHtml;
|
|
24
26
|
var isChatMode = variant === 'chat';
|
|
25
27
|
var memoPlugins = useMemo(function () {
|
|
26
|
-
return [[remarkGfm, {
|
|
28
|
+
return [!allowHtml && remarkBr, [remarkGfm, {
|
|
27
29
|
singleTilde: false
|
|
28
30
|
}], enableLatex && remarkMath, enableCustomFootnotes && remarkCustomFootnotes, isChatMode && remarkBreaks].filter(Boolean);
|
|
29
|
-
}, [isChatMode, enableLatex, enableCustomFootnotes]);
|
|
31
|
+
}, [allowHtml, isChatMode, enableLatex, enableCustomFootnotes]);
|
|
30
32
|
return useMemo(function () {
|
|
31
33
|
return [].concat(_toConsumableArray(remarkPluginsAhead), _toConsumableArray(memoPlugins), _toConsumableArray(remarkPlugins));
|
|
32
34
|
}, [remarkPlugins, memoPlugins, remarkPluginsAhead]);
|
|
@@ -10,14 +10,6 @@ export declare const contentCache: Map<string, string>;
|
|
|
10
10
|
* @param value The processed content to store
|
|
11
11
|
*/
|
|
12
12
|
export declare const addToCache: (key: string, value: string) => void;
|
|
13
|
-
/**
|
|
14
|
-
* Fixes markdown bold syntax by adding space after closing bold markers
|
|
15
|
-
* when followed by non-space characters after symbols
|
|
16
|
-
*
|
|
17
|
-
* @param text The markdown text to process
|
|
18
|
-
* @returns The text with fixed bold syntax
|
|
19
|
-
*/
|
|
20
|
-
export declare function fixMarkdownBold(text: string): string;
|
|
21
13
|
/**
|
|
22
14
|
* Transforms citation references in the format [n] to markdown links
|
|
23
15
|
*
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { fixMarkdownEmphasisSpacing } from "./fixMarkdownEmphasisSpacing";
|
|
1
2
|
import { preprocessLaTeX } from "./latex";
|
|
2
3
|
|
|
3
4
|
// Cache configuration
|
|
@@ -24,75 +25,6 @@ export var addToCache = function addToCache(key, value) {
|
|
|
24
25
|
contentCache.set(key, value);
|
|
25
26
|
};
|
|
26
27
|
|
|
27
|
-
/**
|
|
28
|
-
* Fixes markdown bold syntax by adding space after closing bold markers
|
|
29
|
-
* when followed by non-space characters after symbols
|
|
30
|
-
*
|
|
31
|
-
* @param text The markdown text to process
|
|
32
|
-
* @returns The text with fixed bold syntax
|
|
33
|
-
*/
|
|
34
|
-
export function fixMarkdownBold(text) {
|
|
35
|
-
var asteriskCount = 0;
|
|
36
|
-
var boldMarkerCount = 0;
|
|
37
|
-
var result = '';
|
|
38
|
-
var inCodeBlock = false;
|
|
39
|
-
var inInlineCode = false;
|
|
40
|
-
for (var i = 0; i < text.length; i++) {
|
|
41
|
-
var char = text[i];
|
|
42
|
-
|
|
43
|
-
// Handle code blocks
|
|
44
|
-
if (text.slice(i, i + 3) === '```') {
|
|
45
|
-
inCodeBlock = !inCodeBlock;
|
|
46
|
-
result += '```';
|
|
47
|
-
i += 2;
|
|
48
|
-
continue;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Handle inline code
|
|
52
|
-
if (char === '`') {
|
|
53
|
-
inInlineCode = !inInlineCode;
|
|
54
|
-
result += '`';
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Process asterisks only if not in code
|
|
59
|
-
if (char === '*' && !inInlineCode && !inCodeBlock) {
|
|
60
|
-
asteriskCount++;
|
|
61
|
-
if (asteriskCount === 2) {
|
|
62
|
-
boldMarkerCount++;
|
|
63
|
-
}
|
|
64
|
-
if (asteriskCount > 2) {
|
|
65
|
-
result += char;
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// Add space before opening bold marker if needed
|
|
70
|
-
if (asteriskCount === 2 && boldMarkerCount % 2 === 1) {
|
|
71
|
-
var nextChar = i + 1 < text.length ? text[i + 1] : '';
|
|
72
|
-
var isNextCharSymbol = /(?:[!-\/:-@\[-`\{-~\xA1-\xA9\xAB\xAC\xAE-\xB1\xB4\xB6-\xB8\xBB\xBF\xD7\xF7\u02C2-\u02C5\u02D2-\u02DF\u02E5-\u02EB\u02ED\u02EF-\u02FF\u0375\u037E\u0384\u0385\u0387\u03F6\u0482\u055A-\u055F\u0589\u058A\u058D-\u058F\u05BE\u05C0\u05C3\u05C6\u05F3\u05F4\u0606-\u060F\u061B\u061D-\u061F\u066A-\u066D\u06D4\u06DE\u06E9\u06FD\u06FE\u0700-\u070D\u07F6-\u07F9\u07FE\u07FF\u0830-\u083E\u085E\u0888\u0964\u0965\u0970\u09F2\u09F3\u09FA\u09FB\u09FD\u0A76\u0AF0\u0AF1\u0B70\u0BF3-\u0BFA\u0C77\u0C7F\u0C84\u0D4F\u0D79\u0DF4\u0E3F\u0E4F\u0E5A\u0E5B\u0F01-\u0F17\u0F1A-\u0F1F\u0F34\u0F36\u0F38\u0F3A-\u0F3D\u0F85\u0FBE-\u0FC5\u0FC7-\u0FCC\u0FCE-\u0FDA\u104A-\u104F\u109E\u109F\u10FB\u1360-\u1368\u1390-\u1399\u1400\u166D\u166E\u169B\u169C\u16EB-\u16ED\u1735\u1736\u17D4-\u17D6\u17D8-\u17DB\u1800-\u180A\u1940\u1944\u1945\u19DE-\u19FF\u1A1E\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B6A\u1B74-\u1B7E\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E\u1C7F\u1CC0-\u1CC7\u1CD3\u1FBD\u1FBF-\u1FC1\u1FCD-\u1FCF\u1FDD-\u1FDF\u1FED-\u1FEF\u1FFD\u1FFE\u2010-\u2027\u2030-\u205E\u207A-\u207E\u208A-\u208E\u20A0-\u20C0\u2100\u2101\u2103-\u2106\u2108\u2109\u2114\u2116-\u2118\u211E-\u2123\u2125\u2127\u2129\u212E\u213A\u213B\u2140-\u2144\u214A-\u214D\u214F\u218A\u218B\u2190-\u2426\u2440-\u244A\u249C-\u24E9\u2500-\u2775\u2794-\u2B73\u2B76-\u2B95\u2B97-\u2BFF\u2CE5-\u2CEA\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E5D\u2E80-\u2E99\u2E9B-\u2EF3\u2F00-\u2FD5\u2FF0-\u2FFF\u3001-\u3004\u3008-\u3020\u3030\u3036\u3037\u303D-\u303F\u309B\u309C\u30A0\u30FB\u3190\u3191\u3196-\u319F\u31C0-\u31E3\u31EF\u3200-\u321E\u322A-\u3247\u3250\u3260-\u327F\u328A-\u32B0\u32C0-\u33FF\u4DC0-\u4DFF\uA490-\uA4C6\uA4FE\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA700-\uA716\uA720\uA721\uA789\uA78A\uA828-\uA82B\uA836-\uA839\uA874-\uA877\uA8CE\uA8CF\uA8F8-\uA8FA\uA8FC\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF\uAA5C-\uAA5F\uAA77-\uAA79\uAADE\uAADF\uAAF0\uAAF1\uAB5B\uAB6A\uAB6B\uABEB\uFB29\uFBB2-\uFBC2\uFD3E-\uFD4F\uFDCF\uFDFC-\uFDFF\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE66\uFE68-\uFE6B\uFF01-\uFF0F\uFF1A-\uFF20\uFF3B-\uFF40\uFF5B-\uFF65\uFFE0-\uFFE6\uFFE8-\uFFEE\uFFFC\uFFFD]|\uD800[\uDD00-\uDD02\uDD37-\uDD3F\uDD79-\uDD89\uDD8C-\uDD8E\uDD90-\uDD9C\uDDA0\uDDD0-\uDDFC\uDF9F\uDFD0]|\uD801\uDD6F|\uD802[\uDC57\uDC77\uDC78\uDD1F\uDD3F\uDE50-\uDE58\uDE7F\uDEC8\uDEF0-\uDEF6\uDF39-\uDF3F\uDF99-\uDF9C]|\uD803[\uDEAD\uDF55-\uDF59\uDF86-\uDF89]|\uD804[\uDC47-\uDC4D\uDCBB\uDCBC\uDCBE-\uDCC1\uDD40-\uDD43\uDD74\uDD75\uDDC5-\uDDC8\uDDCD\uDDDB\uDDDD-\uDDDF\uDE38-\uDE3D\uDEA9]|\uD805[\uDC4B-\uDC4F\uDC5A\uDC5B\uDC5D\uDCC6\uDDC1-\uDDD7\uDE41-\uDE43\uDE60-\uDE6C\uDEB9\uDF3C-\uDF3F]|\uD806[\uDC3B\uDD44-\uDD46\uDDE2\uDE3F-\uDE46\uDE9A-\uDE9C\uDE9E-\uDEA2\uDF00-\uDF09]|\uD807[\uDC41-\uDC45\uDC70\uDC71\uDEF7\uDEF8\uDF43-\uDF4F\uDFD5-\uDFF1\uDFFF]|\uD809[\uDC70-\uDC74]|\uD80B[\uDFF1\uDFF2]|\uD81A[\uDE6E\uDE6F\uDEF5\uDF37-\uDF3F\uDF44\uDF45]|\uD81B[\uDE97-\uDE9A\uDFE2]|\uD82F[\uDC9C\uDC9F]|\uD833[\uDF50-\uDFC3]|\uD834[\uDC00-\uDCF5\uDD00-\uDD26\uDD29-\uDD64\uDD6A-\uDD6C\uDD83\uDD84\uDD8C-\uDDA9\uDDAE-\uDDEA\uDE00-\uDE41\uDE45\uDF00-\uDF56]|\uD835[\uDEC1\uDEDB\uDEFB\uDF15\uDF35\uDF4F\uDF6F\uDF89\uDFA9\uDFC3]|\uD836[\uDC00-\uDDFF\uDE37-\uDE3A\uDE6D-\uDE74\uDE76-\uDE83\uDE85-\uDE8B]|\uD838[\uDD4F\uDEFF]|\uD83A[\uDD5E\uDD5F]|\uD83B[\uDCAC\uDCB0\uDD2E\uDEF0\uDEF1]|\uD83C[\uDC00-\uDC2B\uDC30-\uDC93\uDCA0-\uDCAE\uDCB1-\uDCBF\uDCC1-\uDCCF\uDCD1-\uDCF5\uDD0D-\uDDAD\uDDE6-\uDE02\uDE10-\uDE3B\uDE40-\uDE48\uDE50\uDE51\uDE60-\uDE65\uDF00-\uDFFF]|\uD83D[\uDC00-\uDED7\uDEDC-\uDEEC\uDEF0-\uDEFC\uDF00-\uDF76\uDF7B-\uDFD9\uDFE0-\uDFEB\uDFF0]|\uD83E[\uDC00-\uDC0B\uDC10-\uDC47\uDC50-\uDC59\uDC60-\uDC87\uDC90-\uDCAD\uDCB0\uDCB1\uDD00-\uDE53\uDE60-\uDE6D\uDE70-\uDE7C\uDE80-\uDE88\uDE90-\uDEBD\uDEBF-\uDEC5\uDECE-\uDEDB\uDEE0-\uDEE8\uDEF0-\uDEF8\uDF00-\uDF92\uDF94-\uDFCA])/.test(nextChar);
|
|
73
|
-
if (isNextCharSymbol) {
|
|
74
|
-
// 已经向 result 写入了第一个 '*',先删掉它,然后输出 ' **'
|
|
75
|
-
result = result.slice(0, -1) + ' **';
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Add space after closing bold marker if needed
|
|
81
|
-
if (asteriskCount === 2 && boldMarkerCount % 2 === 0) {
|
|
82
|
-
var prevChar = i > 0 ? text[i - 2] : '';
|
|
83
|
-
var isPrevCharSymbol = /(?:[!-\/:-@\[-`\{-~\xA1-\xA9\xAB\xAC\xAE-\xB1\xB4\xB6-\xB8\xBB\xBF\xD7\xF7\u02C2-\u02C5\u02D2-\u02DF\u02E5-\u02EB\u02ED\u02EF-\u02FF\u0375\u037E\u0384\u0385\u0387\u03F6\u0482\u055A-\u055F\u0589\u058A\u058D-\u058F\u05BE\u05C0\u05C3\u05C6\u05F3\u05F4\u0606-\u060F\u061B\u061D-\u061F\u066A-\u066D\u06D4\u06DE\u06E9\u06FD\u06FE\u0700-\u070D\u07F6-\u07F9\u07FE\u07FF\u0830-\u083E\u085E\u0888\u0964\u0965\u0970\u09F2\u09F3\u09FA\u09FB\u09FD\u0A76\u0AF0\u0AF1\u0B70\u0BF3-\u0BFA\u0C77\u0C7F\u0C84\u0D4F\u0D79\u0DF4\u0E3F\u0E4F\u0E5A\u0E5B\u0F01-\u0F17\u0F1A-\u0F1F\u0F34\u0F36\u0F38\u0F3A-\u0F3D\u0F85\u0FBE-\u0FC5\u0FC7-\u0FCC\u0FCE-\u0FDA\u104A-\u104F\u109E\u109F\u10FB\u1360-\u1368\u1390-\u1399\u1400\u166D\u166E\u169B\u169C\u16EB-\u16ED\u1735\u1736\u17D4-\u17D6\u17D8-\u17DB\u1800-\u180A\u1940\u1944\u1945\u19DE-\u19FF\u1A1E\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B6A\u1B74-\u1B7E\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E\u1C7F\u1CC0-\u1CC7\u1CD3\u1FBD\u1FBF-\u1FC1\u1FCD-\u1FCF\u1FDD-\u1FDF\u1FED-\u1FEF\u1FFD\u1FFE\u2010-\u2027\u2030-\u205E\u207A-\u207E\u208A-\u208E\u20A0-\u20C0\u2100\u2101\u2103-\u2106\u2108\u2109\u2114\u2116-\u2118\u211E-\u2123\u2125\u2127\u2129\u212E\u213A\u213B\u2140-\u2144\u214A-\u214D\u214F\u218A\u218B\u2190-\u2426\u2440-\u244A\u249C-\u24E9\u2500-\u2775\u2794-\u2B73\u2B76-\u2B95\u2B97-\u2BFF\u2CE5-\u2CEA\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E5D\u2E80-\u2E99\u2E9B-\u2EF3\u2F00-\u2FD5\u2FF0-\u2FFF\u3001-\u3004\u3008-\u3020\u3030\u3036\u3037\u303D-\u303F\u309B\u309C\u30A0\u30FB\u3190\u3191\u3196-\u319F\u31C0-\u31E3\u31EF\u3200-\u321E\u322A-\u3247\u3250\u3260-\u327F\u328A-\u32B0\u32C0-\u33FF\u4DC0-\u4DFF\uA490-\uA4C6\uA4FE\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA700-\uA716\uA720\uA721\uA789\uA78A\uA828-\uA82B\uA836-\uA839\uA874-\uA877\uA8CE\uA8CF\uA8F8-\uA8FA\uA8FC\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF\uAA5C-\uAA5F\uAA77-\uAA79\uAADE\uAADF\uAAF0\uAAF1\uAB5B\uAB6A\uAB6B\uABEB\uFB29\uFBB2-\uFBC2\uFD3E-\uFD4F\uFDCF\uFDFC-\uFDFF\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE66\uFE68-\uFE6B\uFF01-\uFF0F\uFF1A-\uFF20\uFF3B-\uFF40\uFF5B-\uFF65\uFFE0-\uFFE6\uFFE8-\uFFEE\uFFFC\uFFFD]|\uD800[\uDD00-\uDD02\uDD37-\uDD3F\uDD79-\uDD89\uDD8C-\uDD8E\uDD90-\uDD9C\uDDA0\uDDD0-\uDDFC\uDF9F\uDFD0]|\uD801\uDD6F|\uD802[\uDC57\uDC77\uDC78\uDD1F\uDD3F\uDE50-\uDE58\uDE7F\uDEC8\uDEF0-\uDEF6\uDF39-\uDF3F\uDF99-\uDF9C]|\uD803[\uDEAD\uDF55-\uDF59\uDF86-\uDF89]|\uD804[\uDC47-\uDC4D\uDCBB\uDCBC\uDCBE-\uDCC1\uDD40-\uDD43\uDD74\uDD75\uDDC5-\uDDC8\uDDCD\uDDDB\uDDDD-\uDDDF\uDE38-\uDE3D\uDEA9]|\uD805[\uDC4B-\uDC4F\uDC5A\uDC5B\uDC5D\uDCC6\uDDC1-\uDDD7\uDE41-\uDE43\uDE60-\uDE6C\uDEB9\uDF3C-\uDF3F]|\uD806[\uDC3B\uDD44-\uDD46\uDDE2\uDE3F-\uDE46\uDE9A-\uDE9C\uDE9E-\uDEA2\uDF00-\uDF09]|\uD807[\uDC41-\uDC45\uDC70\uDC71\uDEF7\uDEF8\uDF43-\uDF4F\uDFD5-\uDFF1\uDFFF]|\uD809[\uDC70-\uDC74]|\uD80B[\uDFF1\uDFF2]|\uD81A[\uDE6E\uDE6F\uDEF5\uDF37-\uDF3F\uDF44\uDF45]|\uD81B[\uDE97-\uDE9A\uDFE2]|\uD82F[\uDC9C\uDC9F]|\uD833[\uDF50-\uDFC3]|\uD834[\uDC00-\uDCF5\uDD00-\uDD26\uDD29-\uDD64\uDD6A-\uDD6C\uDD83\uDD84\uDD8C-\uDDA9\uDDAE-\uDDEA\uDE00-\uDE41\uDE45\uDF00-\uDF56]|\uD835[\uDEC1\uDEDB\uDEFB\uDF15\uDF35\uDF4F\uDF6F\uDF89\uDFA9\uDFC3]|\uD836[\uDC00-\uDDFF\uDE37-\uDE3A\uDE6D-\uDE74\uDE76-\uDE83\uDE85-\uDE8B]|\uD838[\uDD4F\uDEFF]|\uD83A[\uDD5E\uDD5F]|\uD83B[\uDCAC\uDCB0\uDD2E\uDEF0\uDEF1]|\uD83C[\uDC00-\uDC2B\uDC30-\uDC93\uDCA0-\uDCAE\uDCB1-\uDCBF\uDCC1-\uDCCF\uDCD1-\uDCF5\uDD0D-\uDDAD\uDDE6-\uDE02\uDE10-\uDE3B\uDE40-\uDE48\uDE50\uDE51\uDE60-\uDE65\uDF00-\uDFFF]|\uD83D[\uDC00-\uDED7\uDEDC-\uDEEC\uDEF0-\uDEFC\uDF00-\uDF76\uDF7B-\uDFD9\uDFE0-\uDFEB\uDFF0]|\uD83E[\uDC00-\uDC0B\uDC10-\uDC47\uDC50-\uDC59\uDC60-\uDC87\uDC90-\uDCAD\uDCB0\uDCB1\uDD00-\uDE53\uDE60-\uDE6D\uDE70-\uDE7C\uDE80-\uDE88\uDE90-\uDEBD\uDEBF-\uDEC5\uDECE-\uDEDB\uDEE0-\uDEE8\uDEF0-\uDEF8\uDF00-\uDF92\uDF94-\uDFCA])/.test(prevChar);
|
|
84
|
-
result += i + 1 < text.length && text[i + 1] !== ' ' && isPrevCharSymbol ? '* ' : '*';
|
|
85
|
-
} else {
|
|
86
|
-
result += '*';
|
|
87
|
-
}
|
|
88
|
-
} else {
|
|
89
|
-
result += char;
|
|
90
|
-
asteriskCount = 0;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return result;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
28
|
/**
|
|
97
29
|
* Transforms citation references in the format [n] to markdown links
|
|
98
30
|
*
|
|
@@ -212,5 +144,5 @@ export var preprocessContent = function preprocessContent(str) {
|
|
|
212
144
|
if (enableCustomFootnotes) {
|
|
213
145
|
content = transformCitations(content, citationsLength);
|
|
214
146
|
}
|
|
215
|
-
return
|
|
147
|
+
return fixMarkdownEmphasisSpacing(content);
|
|
216
148
|
};
|