mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-04 06:10:12 +08:00
Merge remote-tracking branch 'refs/remotes/origin/pr/540' into codex/merge-six-prs
This commit is contained in:
@@ -138,6 +138,7 @@ const ALLOWED_HTML_TAGS = new Set<string>([
|
||||
const HTML_LIKE_TAG_REGEX = /<\/?([A-Za-z][A-Za-z0-9_-]*)\b[^<>]*?\/?>/g;
|
||||
const FENCED_CODE_BLOCK_REGEX = /```[\s\S]*?```/g;
|
||||
const INLINE_CODE_SPAN_REGEX = /`[^`\n]*`/g;
|
||||
const MATH_SPAN_REGEX = /\\\[[\s\S]*?\\\]|\\\([\s\S]*?\\\)|\$\$[\s\S]*?\$\$/g;
|
||||
const PROTECTED_SPAN_REGEX = /```[\s\S]*?```|`[^`\n]*`/g;
|
||||
const PROTECTED_PLACEHOLDER_REGEX = /\u0000PROTECTED_(\d+)\u0000/g;
|
||||
const HTML_ATTR_VALUE = /(?:"[^"]*"|'[^']*'|[^\s"'=<>`]+)/.source;
|
||||
@@ -514,13 +515,16 @@ function linkifyCitationsOutsideCode(content: string): string {
|
||||
FENCED_CODE_BLOCK_REGEX,
|
||||
"FENCED_CODE",
|
||||
);
|
||||
const unwrapped = unwrapBacktickedCitations(fenced.masked);
|
||||
const math = maskProtectedSpans(fenced.masked, MATH_SPAN_REGEX, "MATH");
|
||||
const unwrapped = unwrapBacktickedCitations(math.masked);
|
||||
const inline = maskProtectedSpans(
|
||||
unwrapped,
|
||||
INLINE_CODE_SPAN_REGEX,
|
||||
"INLINE_CODE",
|
||||
);
|
||||
return fenced.restore(inline.restore(linkifyCitations(inline.masked)));
|
||||
return fenced.restore(
|
||||
math.restore(inline.restore(linkifyCitations(inline.masked))),
|
||||
);
|
||||
}
|
||||
|
||||
export function normalizeMarkdownForDisplay(content: string): string {
|
||||
|
||||
@@ -74,6 +74,20 @@ test("normalizeMarkdownForDisplay keeps array indexes inside inline code", () =>
|
||||
assert.equal(normalizeMarkdownForDisplay(input), input);
|
||||
});
|
||||
|
||||
test("normalizeMarkdownForDisplay keeps bracketed vectors inside display math", () => {
|
||||
const input = ["The row for `sat` is:", "", "\\[", "[1, 1, 2]", "\\]"].join(
|
||||
"\n",
|
||||
);
|
||||
assert.equal(normalizeMarkdownForDisplay(input), input);
|
||||
});
|
||||
|
||||
test("normalizeMarkdownForDisplay keeps bracketed vectors inside weighted math", () => {
|
||||
const input = ["\\[", "0.212[1, 1] + 0.212[2, 0] + 0.576[0, 3]", "\\]"].join(
|
||||
"\n",
|
||||
);
|
||||
assert.equal(normalizeMarkdownForDisplay(input), input);
|
||||
});
|
||||
|
||||
test("normalizeMarkdownForDisplay unwraps explicit citation code spans outside code", () => {
|
||||
assert.equal(
|
||||
normalizeMarkdownForDisplay("See `[web-1]` for details."),
|
||||
|
||||
Reference in New Issue
Block a user