Skip to content

Fix serializing inline code containing backticks#9899

Draft
pmario wants to merge 2 commits into
TiddlyWiki:masterfrom
pmario:fix-serialize-codeinline-backticks
Draft

Fix serializing inline code containing backticks#9899
pmario wants to merge 2 commits into
TiddlyWiki:masterfrom
pmario:fix-serialize-codeinline-backticks

Conversation

@pmario

@pmario pmario commented Jul 2, 2026

Copy link
Copy Markdown
Member

This PR fixes #9898 and contains a new test

This PR:

  • Usees double backtick delimiters when the code text contains a backtick. Previously a`b came back as ab`, 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.

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.
@netlify

netlify Bot commented Jul 2, 2026

Copy link
Copy Markdown

Deploy Preview for tiddlywiki-previews ready!

Name Link
🔨 Latest commit 91727e3
🔍 Latest deploy log https://app.netlify.com/projects/tiddlywiki-previews/deploys/6a468e82abe2fb000841c2c0
😎 Deploy Preview https://deploy-preview-9899--tiddlywiki-previews.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown

Confirmed: pmario has already signed the Contributor License Agreement (see contributing.md)

@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown

⚠️ Change Note Status

This PR appears to contain code changes but doesn't include a change note.

Please add a change note by creating a .tid file in editions/tw5.com/tiddlers/releasenotes/<version>/

📚 Documentation: Release Notes and Changes

💡 Note: If this is a documentation-only change, you can ignore this message.

Comment thread plugins/tiddlywiki/wikitext-serialize/rules/codeinline.js Outdated
Co-authored-by: Saq Imtiaz <saq.imtiaz@gmail.com>
@Jermolene

Copy link
Copy Markdown
Member

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

@Jermolene

Copy link
Copy Markdown
Member

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.

@saqimtiaz

Copy link
Copy Markdown
Member

@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:
<div title="""This is my "title".""">Hello</div>

@pmario

pmario commented Jul 8, 2026

Copy link
Copy Markdown
Member Author

@pmario pmario mentioned this pull request Jul 8, 2026
@pmario

pmario commented Jul 8, 2026

Copy link
Copy Markdown
Member Author

@saqimtiaz - perfect hit: <div title="""This is my "title".""">Hello</div> actually hits a gap.

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.

@pmario

pmario commented Jul 8, 2026

Copy link
Copy Markdown
Member Author

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.

@linonetwo

Copy link
Copy Markdown
Contributor

I must missing many Escaping scenarios. I only focused on getting WYSIWYG editor working. Please help fill these edge cases.

@pmario

pmario commented Jul 12, 2026

Copy link
Copy Markdown
Member Author

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.

<<<
text

<<<<
more text
<<<<

<<<

and

<<<<
text

<<<
more text
<<<

<<<<

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.

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

Successfully merging this pull request may close these issues.

[Report] Plugin wikitext-serialize corrupts inline code that contains a backtick

4 participants