Skip to content

Commit

Permalink
Fix replace function
Browse files Browse the repository at this point in the history
  • Loading branch information
7PH committed Dec 6, 2023
1 parent 33f5659 commit 4dc5406
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions utils/tex.ts
Original file line number Diff line number Diff line change
@@ -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;
}
Expand Down

0 comments on commit 4dc5406

Please sign in to comment.