diff options
author | Hsieh Chin Fan <pham@topo.tw> | 2024-10-23 17:19:31 +0800 |
---|---|---|
committer | Hsieh Chin Fan <pham@topo.tw> | 2024-10-23 20:50:23 +0800 |
commit | df606a1f7bcb32747085972b740c6685ffabcb71 (patch) | |
tree | f6920b287c0e138f41fc2a3cf6efadcae4e44220 /src/dumbyUtils.mjs | |
parent | 5c02dfcd703c20c304e62a87c0a6796009157d2f (diff) |
feat: add support for full-width digits
Diffstat (limited to 'src/dumbyUtils.mjs')
-rw-r--r-- | src/dumbyUtils.mjs | 8 |
1 files changed, 5 insertions, 3 deletions
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 @@ | |||
1 | import LeaderLine from 'leader-line' | 1 | import LeaderLine from 'leader-line' |
2 | import { insideWindow, insideParent, replaceTextNodes } from './utils' | 2 | import { insideWindow, insideParent, replaceTextNodes, full2Half } from './utils' |
3 | import proj4 from 'proj4' | 3 | import proj4 from 'proj4' |
4 | 4 | ||
5 | export const coordPattern = /^geo:([-]?[0-9.]+),([-]?[0-9.]+)/ | 5 | export const coordPattern = /^geo:([-]?[0-9.]+),([-]?[0-9.]+)/ |
@@ -439,11 +439,13 @@ export const dragForAnchor = (container, range, endOfLeaderLine) => { | |||
439 | } | 439 | } |
440 | 440 | ||
441 | export const addGeoSchemeByText = async (node) => { | 441 | export const addGeoSchemeByText = async (node) => { |
442 | const coordPatterns = /(-?\d+\.?\d*)([,\x2F\uFF0C])(-?\d+\.?\d*)/ | 442 | const digit = '[\\d\\uFF10-\\uFF19]' |
443 | const decimal = '[.\\uFF0E]' | ||
444 | const coordPatterns = `(-?${digit}+${decimal}?${digit}*)([,\x2F\uFF0C])(-?${digit}+${decimal}?${digit}*)` | ||
443 | const re = new RegExp(coordPatterns, 'g') | 445 | const re = new RegExp(coordPatterns, 'g') |
444 | 446 | ||
445 | return replaceTextNodes(node, re, match => { | 447 | return replaceTextNodes(node, re, match => { |
446 | const [x, y] = [match.at(1), match.at(3)] | 448 | const [x, y] = [full2Half(match.at(1)), full2Half(match.at(3))] |
447 | // Don't process string which can be used as date | 449 | // Don't process string which can be used as date |
448 | if (Date.parse(match.at(0) + ' 1990')) return null | 450 | if (Date.parse(match.at(0) + ' 1990')) return null |
449 | 451 | ||