Repository navigation
Add a hook for syntax highlighting of code blocks - #24
Merged
Merged
Conversation
Code blocks showed in one color. The parser kept the fence's language, but layout did not use it. The app gives TranscriptTextView.codeHighlighter, or TranscriptText.codeHighlighter(_:), an async function: it gets a code block's text and language and returns colored ranges, with bold or italic. The image store keeps the results, the way it keeps pictures: a code block is drawn in the text color until its colors arrive, and then laid out again. The highlighter runs off the main thread, at most once at a time for each block; the newest text waits for its turn, and texts in between are skipped. While code streams in, a block keeps its newest colors on the text they were made for. The package keeps no dependency: the app supplies the highlighter. Code colors have their own generation in the store, so a new highlighter does not drop images that are loading. Closes #8. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Code blocks showed in one color. The parser kept the fence's language, but layout did not use it.
TranscriptTextView.codeHighlighterandTranscriptText.codeHighlighter(_:)take an async function. It gets a code block's text and the fence's language. It returnsTranscriptCodeHighlights: UTF-16 ranges with aTranscriptColor, and bold or italic if you want them.TranscriptColors, so a highlighter can give a light and a dark value.Closes #8.
Stack
This PR is part of a stack. It is based on #23 (
feature/tag-image), so its diff shows only this change. Merge the stack in order, starting with #17.Tests
swift test: 145 tests pass.🤖 Generated with Claude Code