From df606a1f7bcb32747085972b740c6685ffabcb71 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Wed, 23 Oct 2024 17:19:31 +0800 Subject: feat: add support for full-width digits --- src/dumbyUtils.mjs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/dumbyUtils.mjs') diff --git a/src/dumbyUtils.mjs b/src/dumbyUtils.mjs index 12b5905..2f64e38 100644 --- a/src/dumbyUtils.mjs +++ b/src/dumbyUtils.mjs @@ -1,5 +1,5 @@ import LeaderLine from 'leader-line' -import { insideWindow, insideParent, replaceTextNodes } from './utils' +import { insideWindow, insideParent, replaceTextNodes, full2Half } from './utils' import proj4 from 'proj4' export const coordPattern = /^geo:([-]?[0-9.]+),([-]?[0-9.]+)/ @@ -439,11 +439,13 @@ export const dragForAnchor = (container, range, endOfLeaderLine) => { } export const addGeoSchemeByText = async (node) => { - const coordPatterns = /(-?\d+\.?\d*)([,\x2F\uFF0C])(-?\d+\.?\d*)/ + const digit = '[\\d\\uFF10-\\uFF19]' + const decimal = '[.\\uFF0E]' + const coordPatterns = `(-?${digit}+${decimal}?${digit}*)([,\x2F\uFF0C])(-?${digit}+${decimal}?${digit}*)` const re = new RegExp(coordPatterns, 'g') return replaceTextNodes(node, re, match => { - const [x, y] = [match.at(1), match.at(3)] + const [x, y] = [full2Half(match.at(1)), full2Half(match.at(3))] // Don't process string which can be used as date if (Date.parse(match.at(0) + ' 1990')) return null -- cgit v1.2.3-70-g09d2