Skip to content

fix: toggle a code block off whatever language it names - #368

Merged
Azganoth merged 1 commit into
mainfrom
bug/toggle-code-block-with-an-info-string
Sep 2, 2026
Merged

fix: toggle a code block off whatever language it names#368
Azganoth merged 1 commit into
mainfrom
bug/toggle-code-block-with-an-info-string

Conversation

@Azganoth

@Azganoth Azganoth commented Sep 2, 2026

Copy link
Copy Markdown
Owner

Summary

Code block run on a fenced block carrying an info string deleted the info string instead of toggling the block off. A block opened by three backticks and ts came back opened by a bare fence, and the language was gone from the file on the next save. The language selects the highlighting the block renders with and Leafdown exposes no control for setting one, so a language lost this way cannot be typed back. The same gesture on a fence with no info string toggled the block off, as the specification already describes.

toggleTextBlockType decides between removing the format and applying it by testing every attribute the call names, and toggleCodeBlock named { language: "" }. A block whose language was anything else failed that test, was treated as not yet a code block, and was rebuilt from the named attributes.

code_block carries language as its only attribute and the schema already defaults it to "", so that argument named nothing the command asks for while doing two jobs it should not have: deciding which blocks the toggle reads as already being code blocks, and overwriting the language of any block that already was one. Removing it settles both. The recognition test then reads the node type alone, and the per-block resolver added under #359 keeps every attribute a command does not name, so an existing block passes through untouched while one that becomes a code block still opens without a language.

Related Issue

Closes #365

Verification

blocks.test.ts gains three tests in its block-formatting group. Two run the toggle over a block opened with ts and a block opened bare, asserting the paragraph the command leaves behind beside the saved bytes, because a toggle that only deleted the info string left a file the language alone tells from the one a working toggle writes. Two of the three fail on the pre-change source; the bare-fence row passes, which is what makes it the guard rather than the fix.

The third covers a path the issue's table does not reach. Code block over a selection holding a paragraph beside a code block wrapped the paragraph and cleared the existing block's ts at the same time. That is the issue's second Done when item and a distinct path from the toggle, and the same argument removal answers it, because the language stops being an attribute the change writes over.

pnpm check:frontend passes, including the corpus round trip. The backend is untouched, so pnpm check:backend was not run.

Not verified: the manual pass over corpus/ in the running application, which covers rendering, interaction, and navigator behavior beyond the automated round trip. The desktop E2E suite was not run locally; its fixtures hold no code block command.

Notes

insertCodeBlock also names { language: "" } and is left as it is. There the attribute names what a created block is given, which is the one job it legitimately has.

docs/specification.md records that a code block's language is content the block carries rather than a format a command asks for. Toggling the same block command removes the marker when applicable needed no change: the specification already described the behavior and the code disagreed with it.

@Azganoth Azganoth added the Bug Something isn't working label Sep 2, 2026
@Azganoth Azganoth self-assigned this Sep 2, 2026
@Azganoth
Azganoth enabled auto-merge (squash) September 2, 2026 17:08
@Azganoth
Azganoth disabled auto-merge September 2, 2026 17:15
@Azganoth
Azganoth merged commit 92b7882 into main Sep 2, 2026
3 checks passed
@Azganoth
Azganoth deleted the bug/toggle-code-block-with-an-info-string branch September 2, 2026 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A code block toggle deletes the info string instead of removing the block

1 participant