Forgot password?
 Register account
View 156|Reply 0

把<sup>和<sub>转换为^和_

[Copy link]

3157

Threads

7925

Posts

610K

Credits

Credits
64218
QQ

Show all posts

hbghlyj Posted 2022-12-28 05:08 |Read mode
PEG.js把<sup>⋯</sup>转换为^{⋯}
  1. start = tail:sup* t:text{
  2.         return tail.join("")+t;
  3.       }  
  4. sup = t1:text "<sup>" t2:start "</sup>"{
  5.       return t1+"^{"+t2+"}";
  6.     }
  7. text = [^<]*
Copy the Code
例子
1<sup>1<sup>2<sup>2</sup></sup>1</sup>3<sup>3</sup>3
输出
1^{1^{2^{2}}1}3^{3}3


加入<sub>⋯</sub>
  1. start = tail:(sup/sub)* t:text{
  2.         return tail.join("")+t;
  3.       }  
  4. sup = t1:text "<sup>" t2:start "</sup>"{
  5.       return t1+"^{"+t2+"}";
  6.     }
  7. sub = t1:text "<sub>" t2:start "</sub>"{
  8.       return t1+"_{"+t2+"}";
  9.     }
  10. text = [^<]*
Copy the Code
例子
1<sub>1<sup>2<sub>2</sub></sup>1</sub>3<sub>3</sub>3
输出
1_{1^{2_{2}}1}3_{3}3

Related threads

Mobile version|Discuz Math Forum

2025-6-6 15:53 GMT+8

Powered by Discuz!

× Quick Reply To Top Edit