Skip to content

feat(core): collect code blocks as block slots - #1068

Merged
hryhoriiK97 merged 3 commits into
mainfrom
feat/code-renderers-core
Nov 2, 2026
Merged

hryhoriiK97 merged 3 commits into
mainfrom
feat/code-renderers-core

Conversation

@eszlamczyk

@eszlamczyk eszlamczyk commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

What/Why?

First step of the code block renderers stack.

This PR adds a code block kind to the C++ block slot collector, so the rest of the stack can replace code blocks with React renderers.

  • A fenced or indented code block becomes a slot carrying its language and code. This applies at the root, in a blockquote or in an admonition, but not inside a list. The slot id hashes only the language, so it stays the same while the code streams in and after the fence closes.
  • The streaming filter holds an open fence back until its opening line ends. That way the language is complete before the block shows and never changes while it's open. As a side effect, native code blocks appear one chunk later than before.
  • Each kind now fills its own slot fields and identity through a fill function, replacing the shared url/text/title path. The collector also sets BlockSlot::node and records the last code block in document order, so a host can tell which slot an open fence belongs to.
  • The TurboModule skips code slots for now, until the hosts can place them.

Testing

  • New cases in block_slots_test.cpp (collection, placement, id stability while code streams) and streaming_filter_test.cpp (open fence held until its opening line ends).
  • Updated the block_slot_ids.txt fixture.
  • No visible change in the app yet, because code slots are skipped.

PR Checklist

  • Code compiles and runs on iOS
  • Code compiles and runs on Android
  • Updated documentation/README if applicable
  • Ran example app to verify changes
  • E2E tests are passing
  • Required E2E tests have been added (if applicable)

@eszlamczyk
eszlamczyk added this pull request to stack #1071 October 23, 2026 08:06
@eszlamczyk
eszlamczyk marked this pull request as ready for review October 23, 2026 13:46
Adds a `code` block kind: every fenced or indented code block at root, in a
blockquote or in an admonition (not in a list) is a slot carrying its
`language` and `code`. The id hashes the language alone, so a fence keeps its
id while its code streams in and when it closes.

The streaming filter now holds back an open fence until its opening line
ends, so the info string has finished arriving before the fence shows and its
language never changes while it is open. Native code blocks appear one chunk
later than before.

A kind now fills its own slot fields and identity instead of everything going
through url/text/title. The collector also sets `BlockSlot::node` and records
the last code block in document order, so a host can tell which slot an open
fence belongs to.

The TurboModule skips code slots until the hosts can place them.
The empty line after a final newline counted as a line outside the quote,
so a quoted or admonition fence read as closed every time a line ended and
open again mid-line. A blank last line now leaves the fence open.

Adds isSlotComplete, so the hosts read which code slot is still streaming
from core instead of comparing lastCodeBlock themselves.
A slot's kind-specific fields are now one alternative of a variant, so a
code slot no longer carries an empty url, alt text and title, and the kind
can't disagree with the fields filled in.
@hryhoriiK97
hryhoriiK97 force-pushed the feat/code-renderers-core branch from 99a3689 to 6be83d2 Compare November 2, 2026 15:34
@hryhoriiK97
hryhoriiK97 merged commit b051a25 into main Nov 2, 2026
20 of 21 checks passed
@hryhoriiK97
hryhoriiK97 deleted the feat/code-renderers-core branch November 2, 2026 17:50
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