Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toString でエスケープをちゃんとする #154

Open
rinsuki opened this issue Jan 6, 2025 · 1 comment
Open

toString でエスケープをちゃんとする #154

rinsuki opened this issue Jan 6, 2025 · 1 comment

Comments

@rinsuki
Copy link

rinsuki commented Jan 6, 2025

ASTを手で作る (例えば: mfmjs.TEXT("**text**")) と、toString後にparseした際に意図しない文字列になることがあるが、これを避けたい。

例:

mfmjs.parse(mfmjs.toString(mfmjs.TEXT("**a**")))
// 現在の挙動
[
  {
    type: "bold",
    children: [ { type: "text", props: { text: "a" } } ]
  }
]
// 期待する挙動
[ { type: "text", props: { text: "**a**" } } ]

これをちゃんとやると、ついでに AST から PLAIN を TEXT に統合する形で廃止できるはず (<plain> は使うし内部的には使われるとしても)

context: misskey-dev/misskey#15217 (comment) (←のissueを実際に当該コメントの方針でやるかはともかく、botなどで便利なので存在するべき)

@rinsuki
Copy link
Author

rinsuki commented Jan 6, 2025

たぶん text.replaceAll(/[\[\]*<]/g, "<plain>$1</plain>") みたいなノリ + PLAIN と TEXT を AST 上で統合で概ね達成できる (100%ちゃんとやろうとすると #22 とかがblockerになるが、まあ全くされないよりかはそれなりにエスケープされたほうが良い)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant