Description
Add a first-party @comark/pdf renderer to the Comark ecosystem that uses jasy to convert Markdown documents (including frontmatter, components, and data bindings) into print-ready PDF bytes. The Comark AST maps directly to a jasy component tree — no HTML/CSS pipeline and no headless browser.
Motivation
Currently, Comark supports multiple rendering targets (@comark/html, @comark/react, @comark/vue, @comark/svelte, @comark/angular, and @comark/ansi). However, generating print-ready paged documents (PDFs, invoices, reports, books) requires users to manually assemble custom pipelines using external CSS-paged engines, headless browsers, or JSON-based tools like pdfmake.
With Comark's support for components, frontmatter, and data-binding features (::if conditionals and ::for loops), Markdown documents are increasingly used as template generators. We lack a first-party rendering package tailored for paginated media layout that fits the same AST → target pattern as the other renderers.
Proposed solution
Introduce @comark/pdf as an official workspace package. @comark/pdf will leverage jasy (@jasy/pdf) to map a Comark document AST to a declarative PDF component tree (Document / Page / Column / Text / …) and produce PDF bytes via renderToBytes.
Key Features & Requirements
- Frontmatter Configuration: Parse document metadata into jasy
Page props (size, orientation, margins, header/footer):
---
pdf:
format: A4
orientation: portrait
margin: 20mm
header: "Quarterly Report"
footer: "Page {{ page }} of {{ totalPages }}"
---
- Built-in Print Syntax/Components: Support print-specific helper directives such as
::page-break (mapped to jasy PageBreak).
- Dual Execution Support:
- Browser: Render PDF bytes and mount them in an
<iframe> via a Blob URL (@comark/pdf/preview → mount()).
- Node.js: Helper utilities to export raw PDF bytes or write a file (
@comark/pdf/node → renderPdfToBuffer / renderPdfToFile) with no Playwright/Chromium dependency.
- Integration with AST & Data Binding: Seamless processing of AST output from
comark parse + optional plugins. HTML/SVG-emitting plugins (Shiki, KaTeX, Mermaid) degrade for now to monospace source text so content is kept without an HTML intake path.
Alternatives considered
paged.js + Playwright — HTML/CSS Paged Media with a headless browser. Discarded for the shipped pipeline: heavy peers, HTML-centric, does not match the AST → target model.
weasyprint — discarded because it is Python-based.
pdfmake — JSON document model; less natural fit for Comark’s component AST.
Additional context
Description
Add a first-party
@comark/pdfrenderer to the Comark ecosystem that uses jasy to convert Markdown documents (including frontmatter, components, and data bindings) into print-ready PDF bytes. The Comark AST maps directly to a jasy component tree — no HTML/CSS pipeline and no headless browser.Motivation
Currently, Comark supports multiple rendering targets (
@comark/html,@comark/react,@comark/vue,@comark/svelte,@comark/angular, and@comark/ansi). However, generating print-ready paged documents (PDFs, invoices, reports, books) requires users to manually assemble custom pipelines using external CSS-paged engines, headless browsers, or JSON-based tools likepdfmake.With Comark's support for components, frontmatter, and data-binding features (
::ifconditionals and::forloops), Markdown documents are increasingly used as template generators. We lack a first-party rendering package tailored for paginated media layout that fits the same AST → target pattern as the other renderers.Proposed solution
Introduce
@comark/pdfas an official workspace package.@comark/pdfwill leverage jasy (@jasy/pdf) to map a Comark document AST to a declarative PDF component tree (Document/Page/Column/Text/ …) and produce PDF bytes viarenderToBytes.Key Features & Requirements
Pageprops (size, orientation, margins, header/footer):::page-break(mapped to jasyPageBreak).<iframe>via a Blob URL (@comark/pdf/preview→mount()).@comark/pdf/node→renderPdfToBuffer/renderPdfToFile) with no Playwright/Chromium dependency.comarkparse + optional plugins. HTML/SVG-emitting plugins (Shiki, KaTeX, Mermaid) degrade for now to monospace source text so content is kept without an HTML intake path.Alternatives considered
paged.js+ Playwright — HTML/CSS Paged Media with a headless browser. Discarded for the shipped pipeline: heavy peers, HTML-centric, does not match the AST → target model.weasyprint— discarded because it is Python-based.pdfmake— JSON document model; less natural fit for Comark’s component AST.Additional context