Skip to content

Preview: fixes for word splitting and escaping issues - #28

Draft
imphil wants to merge 3 commits into
sou1118:mainfrom
imphil:fix/raw-text
Draft

imphil wants to merge 3 commits into
sou1118:mainfrom
imphil:fix/raw-text

Conversation

@imphil

@imphil imphil commented Sep 12, 2026

Copy link
Copy Markdown

When diffing documents I found some areas that need improvements, mostly around splitting (or not splitting) text chunks.

I'm doing the changes as individual PRs to make reviewing easier, but this PR already gives an overview of what's coming.

escape_content had no case for backslash, so it escaped the backslash of an
escape sequence that was already in the source: `\]` became `\\]`, a literal
backslash followed by a bare `]` that closes the caller's content block early.
Copy escape sequences through whole instead.
Tokenizing `\]` as two tokens lets the diff cut between them. The backslash
is then left at the end of the unchanged text, where it escapes the `#` of
the call written next to it, so "\[x\] [grp]" against "\[x\]" renders as

    \[x\#diff-deleted[\] \[grp]]

and Typst prints the call itself to the page instead of striking the deleted
words through. The character the backslash guarded is loose markup on the
other side of the cut.

Treat an escape sequence as one atomic token, like `#func[...]` and `@ref`.
Raw text is literal, so a diff call written between the backticks is printed
to the page as characters instead of being run:

    `#diff-deleted[ttIdx]#diff-added[tpIdx]`

Treat a raw element as one atomic token, like `#func[...]` and `@ref`, so the
diff wraps it whole rather than reaching inside it, and copy raw through
escaping untouched: inside backticks a `]` does not close the caller's content
block and a backslash is not an escape, so escaping there is both needless and
puts stray characters on the page.

The cost is that a changed raw span is now replaced whole rather than diffed
word by word, since any finer granularity means writing a diff call between
the backticks.
@coderabbitai

coderabbitai Bot commented Sep 12, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant