Fix serializing inline code containing backticks#9899
Conversation
Stop the wikitext-serialize plugin from corrupting inline code that contains a backtick, for example ``a`b`` (fixes TiddlyWiki#9898). * Use double backtick delimiters when the code text contains a backtick. Previously ``a`b`` came back as `a`b`, which reparses as two code runs with changed content. * Serialize an empty code run with double delimiters too, because a bare `` reparses as an opening delimiter and swallows the following siblings. * Add the round trip fixture Serialize/CodeInline covering the issue case, content with a leading backtick, and an empty code run.
✅ Deploy Preview for tiddlywiki-previews ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Confirmed: pmario has already signed the Contributor License Agreement (see contributing.md) |
|
Co-authored-by: Saq Imtiaz <saq.imtiaz@gmail.com>
|
Hi @pmario thanks for this. I think since this affects an experimental plugin rather than the core that we should defer this and give it some more thought. The scope of the fix is narrow and I think we need to explore more general approaches |
|
Hi @pmario on further reflection I think it's going to be hard to properly maintain the wikitext serialiser without tests. We don't currently have tests for any plugin so we would need to figure out the best approach. |
|
@linonetwo could you please take a look at this? Should we be concerned about similar problems in other serialization areas, like literal widget attributes that include the quote character. Eg: |
|
@Jermolene @saqimtiaz ...
I did forget about that. I'll do a review. So "new" eyes go through the test suite. |
|
@saqimtiaz - perfect hit: I am sure there is more to be "hardened". It seems the existing tests are all "friendly". Your test is also friendly because it's valid syntax. First step: We will need to find gaps Second step: I will throw some "nasty critters" in there, with the only goal to "harden" the serialiser code. |
|
Will close that one soon. Will be superseded by a much bigger PR. Adding more tests surfaced more issues. I did not even start with those that intentionally want to break the code. |
|
I must missing many Escaping scenarios. I only focused on getting WYSIWYG editor working. Please help fill these edge cases. |
As I wrote, I do have a local branch with quite some fixes. Not catastrophic but many. And we need a bit of help form the core. The following wikitext produces the exact same AST. So there is absolutely no chance to get the round trip right, without parser help. and That's only one. Lists *, #, ; ... and similar have the same problem. They need a lot of reverse engineering code to get the plain text recreation right. With a bit of parser info the recreations are trivial. I'll post the branch soon. |
This PR fixes #9898 and contains a new test
This PR:
a`bcame back asab`, which reparses as two code runs with changed content.