Skip to content

Feature: add @comark/pdf renderer powered by jasy for PDF print and layout #421

Description

@miguelrk

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

  1. 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 }}"
    ---
  2. Built-in Print Syntax/Components: Support print-specific helper directives such as ::page-break (mapped to jasy PageBreak).
  3. Dual Execution Support:
    • Browser: Render PDF bytes and mount them in an <iframe> via a Blob URL (@comark/pdf/previewmount()).
    • Node.js: Helper utilities to export raw PDF bytes or write a file (@comark/pdf/noderenderPdfToBuffer / renderPdfToFile) with no Playwright/Chromium dependency.
  4. 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions