From 4dc5406a118516e8e716bb05faba89d2b719a2fe Mon Sep 17 00:00:00 2001 From: 7PH Date: Wed, 6 Dec 2023 18:41:35 +0100 Subject: [PATCH] Fix replace function --- utils/tex.ts | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/utils/tex.ts b/utils/tex.ts index c336ebd..3c81bfd 100644 --- a/utils/tex.ts +++ b/utils/tex.ts @@ -1,27 +1,28 @@ const REPLACE_TABLE = ` -\dashfillcolor gray -\domsubgridwidth 0.25pt -\domsubgridcolor lightgray -\domgridwidth 0.75pt -\domgridcolor darkgray -\domlinewidth 1.25pt -\domlinecolor black -\domaxewidth 1pt -\domaxecolor black -\domfigurewidth 1.25pt -\domfigurecolor black -\domfigurefill lightgray -\domsolidewidth 1.25pt -\domsolidecolor black -\domsolidefill lightgray -\domtableaucolor black -\domtableauwidth 1.25pt -\domtableaufill lightgray -\txtbox \ovalnum`.trim().split('\n').map(line => line.split('\t')); +\\dashfillcolor gray +\\domsubgridwidth 0.25pt +\\domsubgridcolor lightgray +\\domgridwidth 0.75pt +\\domgridcolor darkgray +\\domlinewidth 1.25pt +\\domlinecolor black +\\domaxewidth 1pt +\\domaxecolor black +\\domfigurewidth 1.25pt +\\domfigurecolor black +\\domfigurefill lightgray +\\domsolidewidth 1.25pt +\\domsolidecolor black +\\domsolidefill lightgray +\\domtableaucolor black +\\domtableauwidth 1.25pt +\\domtableaufill lightgray +\\txtbox \\ovalnum`.trim().split('\n').map(line => line.split('\t')); export function migrateTex(tex: string) { - for (const [old, new_] of REPLACE_TABLE) { - tex = tex.replace(new RegExp(`\\\\${old}`, 'g'), new_); + for (const [old, new_] of REPLACE_TABLE) { + const escaped = old.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'); + tex = tex.replace(new RegExp(escaped, 'g'), new_); } return tex; }