Include Markdown and notebook files with scoped references - #65
Open
PiotrCzapla wants to merge 13 commits into
Open
Include Markdown and notebook files with scoped references#65PiotrCzapla wants to merge 13 commits into
PiotrCzapla wants to merge 13 commits into
Conversation
… numbers on request A document's frontmatter `number_headings: legal` (or `decimal`) now drives every exporter when the call gives no scheme: `mdhtml2html` and `mdhtml2typst` read it from the `Mdhtml` result's `meta`, `md2gfm` extracts it from the raw source by the dialect's own rule (new native `frontmatter_meta`), and `viewmd` reads a notebook's frontmatter message through fastcore's `nb_frontmatter` since `dlg2md` fences that raw cell as code. The call argument still wins when both are present. `refs='ids'` (the live-preview mode Solveit renders in) used to skip numbering entirely; a requested scheme now numbers the fragment's headings there too, while nothing numbers automatically without a registry. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Namespace include-local IDs and links while preserving reference types. Give each include its own HTML heading counter and honor unnumbered forms. This prevents repeated exhibit names and numbering schemes from leaking between the consent and its attached forms. Validated with the assembled stock-plan packet and renderer suites: 73 tests passed; 2 checkout-asset tests deselected. The coordinated mdhtml2docx, virgil-templates, and fasttract changes are on branches named board-consent-packet.
Contributor
|
I deleted the private links from this PR - be careful please. I don't understand the jargon being used here. Please try to explain in simple concise terms. |
PiotrCzapla
commented
Sep 9, 2026
PiotrCzapla
commented
Sep 9, 2026
PiotrCzapla
commented
Sep 9, 2026
PiotrCzapla
commented
Sep 9, 2026
PiotrCzapla
commented
Sep 9, 2026
PiotrCzapla
commented
Sep 9, 2026
PiotrCzapla
commented
Sep 9, 2026
PiotrCzapla
commented
Sep 9, 2026
Contributor
Author
LLm didn't have instructions to watch out when publishing to a public repo; you got to the PR before I did. I need to find a better way to review the changes before they go to the public repo. Sorry about that. Thank you for catching that. |
PiotrCzapla
marked this pull request as ready for review
September 9, 2026 21:24
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.
We needed a way to include Markdown in Markdown. Code blocks were perfect for that, but the included documents sometimes had clashing section names. We could fix all the clashes, but I thought it would be better to do it programmatically in mdhtml, as clashes in reference IDs are hard to notice when an include is added during DOCX generation.
This PR contains both the include function and the ability to scope references in included sections.
It feels that
scopecould be more generic and apply, for say, headers instead of a wrapping div.But the generic version is harder to specify correctly.
LLM authored PR desc, but reads well:
include(path)loads Markdown files or exported notebook notes. During Markdown conversion, each include appends its scope to local IDs and links.The caller places page breaks. Ordinary placeholders are blank by default.
keep=["port"]preserves a field;keep={"port": "camera_port"}also renames it. Code literals stay literal. Notebook loading excludes code and stored outputs.Markdown and MDHTML
The blocks can also be written directly:
::: {.include scope="__camera"} # Camera ## Setup {#sec-setup} See [@sec-setup]. ::: ::: {.include scope="__mic"} # Microphone ## Setup {#sec-setup} See [@sec-setup]. :::md2mdhtml(source)produces:scopeis the complete suffix.scope="__mic"producessec-setup__micby concatenation. The converter inserts no punctuation. The file helper defaults to__followed by the filename stem.The
sec-,fig-andtbl-prefixes remain intact. Reference lookup uses its existing rules without stripping namespaces or adding reference syntax.Inside the include, use
[@sec-setup]. Outside, use[@sec-setup__mic]. An unqualified outside reference reports a missing target. Links to outside targets stay unchanged. Nested scopes append in order:sec-setup__lens__camera.HTML export adds numbers and reference text. Each h1 resets the normal heading counter. Nested divs use the same
:::delimiter.Implementation and checks
Include handling runs with the div renderer and processes include contents without reparsing the whole document. Invalid scope attributes produce parser warnings. Rust
renderandwiki2mdhtmlreturn strings. The helper reuses the notebook conversion functions andMdreturn type.Independent review approved the changes. All 963 Python tests and 42 Rust tests passed; the WASM target compiled. The combined converter suite passed 40 tests and 16 downstream integration tests passed. The default Python suite excludes one slow test.