Repository navigation
feat(model): render and build documents outside the crate - #186
Open
Idk121-blip wants to merge 2 commits into
Open
Idk121-blip wants to merge 2 commits into
Idk121-blip wants to merge 2 commits into
Conversation
A caller that changes a document from to_document, or builds one itself, had no way to render it: the Markdown writer was reachable only through to_markdown_bytes, which parses first. document_to_markdown renders a model as to_markdown_bytes does. Tables built outside the crate had no way to hold the grid invariant (every position exactly once, covered slots pointing at their origin) short of rebuilding GridBuilder. It is re-exported from model, and its undocumented methods are documented.
|
+1. We need parse → edit → render: today a
Thanks @Idk121-blip !! |
This branch has not been deployed
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.
What
Two additions to the public API, both Rust only:
anydoc::document_to_markdown(&Document) -> String: the Markdown writerto_markdown_bytesalready uses, callable on a document model directly.anydoc::model::GridBuilder: re-exported frommodel.new,next_rowandfinishget doc comments, which#![warn(missing_docs)]requires now that they are public.The README's Rust section gets one line showing
document_to_markdown.Why
to_document, or builds one itself, cannot render it: the writer is reachable only throughto_markdown_bytes, which parses first.GridBuilder. A parser for a format anydoc does not read is a frontend too, and the builder is how anydoc's own frontends get that guarantee.How it was verified
document_to_markdown_matches_the_direct_conversion:document_to_markdown(to_document(x))equalsto_markdown_bytes(x)for docx, epub, xlsx and csv fixtures.tables_built_outside_the_crate_keep_the_grid_invariant: builds a table with a column span from outside the crate, checks the covered slot points at its origin, and snapshots the rendered Markdown.cargo fmt --all --check,cargo clippy --workspace --all-targets --all-features -- -D warnings(Node, Python and wasm bindings included),cargo test --lockedandcargo docpass with no warnings.Watch
GridBuilderwas crate-private on purpose (pub(crate) use table::GridBuilder;, "frontends build grids; consumers read them offTable::grid"). This PR removes that line and its comment. If you'd rather keep the builder internal,document_to_markdownstands on its own and I can drop theGridBuilderpart.Follow-ups deliberately left out
document_to_markdowncovers every format but PDF. That is the subject of PDF support via to_document / per-page extraction #62.Summary by cubic
Lets callers render and build document models outside the crate. Previously the Markdown writer was reachable only through
to_markdown_bytes, which parses first, so an edited or hand-builtDocumentcouldn't be rendered;document_to_markdownnow renders a model the same way.GridBuilderis re-exported frommodelwith its methods documented — it was crate-private, leaving external frontends no way to keep the grid invariant (every position exactly once, covered slots pointing at their origin) except by copying it. README and tests cover both additions.Written for commit fcd14aa. Summary will update on new commits.