Fix svelte special chars escaping problem #401
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem description
<&{are special characters in svelte syntax. Therefore, you can't write a doc content like4<5. To fix this problem, we were escaping those characters with their respective html codes (lt;{) in our python code using regexes. These regexs were slow, which was fixed in #373 and #394. However, there were still some errorsSolution
Fix it at markdown/mdsvex AST level using a custom remark plugin
AST Playground
Description of the custom remark plugin
When AST tree is being traversed, if a node type is "text" (rather than "html"), then escape
<&{with<&{. This solution works great! The only catch is that we lost the full capability of svelte syntax.{4+5}will be evaluated as string{4+5}rather than js compute statement of9. I think it is fine since we dont't have any inline js compute statements in the docs mdx files. Usage of custom components (such as<Tip>, <Question>) should still work as expectedAs a side effect, this PR should also decrease the build time since we are removing a lot regex checks in python and using already done AST tree traversal in mdsvex
todo: