Skip to content

Syntax highlighting documentation updates. #277

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bjhess
Copy link
Contributor

@bjhess bjhess commented Mar 24, 2025

Proposed for your consideration. Two things are addressed in here.

First is a function to strip all hljs-* spans from existing code when editing with rhino. This allows CodeBlockLowlight to then properly re- parse the code blocks for highlighting. Without this, the spans do appear in the editor's highlighted code blocks, but some newlines are missing. The missing newlines will be when they are at the end of a line with only whitespace after them. Those newlines get lost in processing if these spans are not first stripped.

Second is for DB storage, decoding the code content before we re- process it for storage. Without decoding first, some HTML entities will get double-encoded.

I also changed the #highlightCodeblocks function to no longer track highlighting with a has-highlighted HTML attribute. In my testing this was leading to the JS sometimes skipping highlighting upon DB storage. I'm not sure why this tracking existed before, whether it was inadvertent double-execution of this function or if it related to not removing spans before reprocessing edited code, which we now do in #stripHljsSpans. I don't think it's necessary, but I could find out I'm wrong.

I adapted this documentation from our Pika.page code. Apologies for any typos/mistakes!

Proposed for your consideration. Two things are addressed in here.

First is a function to strip all hljs-* spans from existing code when
editing with rhino. This allows CodeBlockLowlight to then properly re-
parse the code blocks for highlighting. Without this, the spans do
appear in the editor's highlighted code blocks, but some newlines are
missing. The missing newlines will be when they are at the end of a line
with only whitespace after them. Those newlines get lost in processing
if these spans are not first stripped.

Second is for DB storage, decoding the code content before we re-
process it for storage. Without decoding first, some HTML entities will
get double-encoded.

I also changed the #highlightCodeblocks function to no longer track
highlighting with a has-highlighted HTML attribute. In my testing this
was leading to the JS sometimes skipping highlighting upon DB storage.
I'm not sure why this tracking existed before, whether it was
inadvertent double-execution of this function or if it related to not
removing spans before reprocessing edited code, which we now do in
#stripHljsSpans. I don't _think_ it's necessary, but I could find out
I'm wrong.

I adapted this documentation from our Pika.page code. Apologies for any
typos/mistakes!
Copy link

changeset-bot bot commented Mar 24, 2025

⚠️ No Changeset found

Latest commit: c47c00e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Mar 24, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
rhino-editor ❌ Failed (Inspect) Mar 24, 2025 4:49pm

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.

2 participants