Forgot password?
 Create new account
View 113|Reply 0

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

[Copy link]

3147

Threads

8493

Posts

610K

Credits

Credits
66163
QQ

Show all posts

hbghlyj Posted at 2022-12-28 05:08:38 |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|Leisure Math Forum

2025-4-20 22:28 GMT+8

Powered by Discuz!

× Quick Reply To Top Return to the list