Skip to content

Commit cde9c69

Browse files
committed
fix(math): add heuristic to exclude date/time patterns from math classification
1 parent b06e11c commit cde9c69

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/utils/markdown/plugins/math.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ const SUPER_SUB_RE = /\^|_/
131131
const OPS_RE = new RegExp('(?<!\\+)\\+(?!\\+)|[=\\-*/^<>]|\\\\times|\\\\pm|\\\\cdot|\\\\le|\\\\ge|\\\\neq')
132132
const FUNC_CALL_RE = /[A-Z]+\s*\([^)]+\)/i
133133
const WORDS_RE = /\b(?:sin|cos|tan|log|ln|exp|sqrt|frac|sum|lim|int|prod)\b/
134+
// Heuristic to detect common date/time patterns like 2025/9/30 21:37:24 and
135+
// avoid classifying them as math merely because they contain '/' or ':'
136+
const DATE_TIME_RE = /\b\d{4}\/\d{1,2}\/\d{1,2}(?:[ T]\d{1,2}:\d{2}(?::\d{2})?)?\b/
134137

135138
export function isMathLike(s: string) {
136139
if (!s)
@@ -146,6 +149,9 @@ export function isMathLike(s: string) {
146149
const stripped = norm.trim()
147150

148151
// quick bailouts
152+
// If the content looks like a timestamp or date, it's not math.
153+
if (DATE_TIME_RE.test(stripped))
154+
return false
149155
if (stripped.length > 2000)
150156
return true // very long blocks likely math
151157

test/debug/isMathLike.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ it('recognizes \"\\boldsymbol{...}\" as math-like', () => {
77
expect(isMathLike('\\(W\\)')).toBe(false)
88
expect(isMathLike('\\(f^{(k)}(a)\\)')).toBe(true)
99
expect(isMathLike('\\(W^\perp\\)')).toBe(true)
10+
expect(isMathLike('\\(2025/9/30 21:37:24\\)')).toBe(false)
1011
})

0 commit comments

Comments
 (0)