Skip to content

Code block rewrite - #72

Closed
RensDimmendaal wants to merge 5 commits into
mainfrom
code-block-rewrite
Closed

RensDimmendaal wants to merge 5 commits into
mainfrom
code-block-rewrite

Conversation

@RensDimmendaal

@RensDimmendaal RensDimmendaal commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

aidialog PR #55 preserves notebook directives such as code-fold and code-summary as data-code-fold and data-code-summary attributes on Markdown code fences. This keeps the display settings available without making aidialog decide how code should appear on the page.

This PR adds a code_block callback to mdhtml’s existing rewrite() API. So Octavo can use it to read those attributes and wrap code in a collapsed section with the requested label. Other callers can use the same callback for their own code-block transformations.

@RensDimmendaal
RensDimmendaal marked this pull request as draft September 22, 2026 10:15
@RensDimmendaal
RensDimmendaal marked this pull request as ready for review September 29, 2026 04:02
@jph00

jph00 commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Hey @RensDimmendaal - I refactored the machinery you're using here a bit over the last week, so I think/hope everything you need is now available, without needing this PR.

Code-block transformations are supported through rewrite(src, {'code_block': callback}), including nested blocks in lists and blockquotes. For fenced code, the callback receives info, lang, text, parsed attrs (id, classes, and pairs), plus source and character offsets. It can inspect those attributes and return replacement Markdown. Replacements preserve the orig prefixes and final newline. This provides code-folding transformations without a separate API. (Also, I've now used it to add the GFM fence-info normalization thingie you had.)

Lemme know if I've missed anything you need, or you have any q's.

@jph00 jph00 closed this Oct 7, 2026
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