-
-
Notifications
You must be signed in to change notification settings - Fork 764
feat: Typst-powered accessible PDF export (PDF/UA-1) #2992
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
7937669
56a7916
776075d
f6dc68a
cfb9b6b
12b63f4
87e9e74
2299aba
90e1426
6262696
7cb50ae
d23319f
4d69138
6b2cd52
a0c356b
4697df2
21db062
b3dcb74
f27153c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| # Regenerates the Linux screenshot baselines for the browser (e2e) suite in | ||
| # the same Playwright container the e2e jobs use, and uploads them as an | ||
| # artifact to download and commit. Linux baselines can otherwise only be | ||
| # produced locally through docker; this is the push-button alternative. | ||
| name: Update e2e screenshots | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| filter: | ||
| description: "Test file filter (empty = all browser tests)" | ||
| required: false | ||
| default: "exporterImages" | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| update-screenshots: | ||
| name: "Update screenshots" | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 30 | ||
| container: | ||
| image: mcr.microsoft.com/playwright:v1.60.0-noble | ||
| env: | ||
| # Routed through env so the input never expands into the shell script | ||
| # itself (template-level expansion is a code-injection vector - zizmor | ||
| # template-injection). Deliberately unquoted at use sites: an empty | ||
| # filter must expand to no argument at all. | ||
| FILTER: ${{ inputs.filter }} | ||
| steps: | ||
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| with: | ||
| fetch-depth: 100 | ||
| persist-credentials: false | ||
|
|
||
| - uses: voidzero-dev/setup-vp@313600b80b104eadebb9111787d37a2e83e014ca # v1.17.0 | ||
| with: | ||
| node-version-file: ".node-version" | ||
| cache: true | ||
|
|
||
| - name: Install dependencies | ||
| run: vp install | ||
|
|
||
| # `-u` must come after the filter, and each browser runs separately so a | ||
| # failure in one doesn't stop the others' baselines from updating. | ||
| - name: Update screenshots (chromium) | ||
| run: HOME=/root vp test -c vite.config.browser.ts --run --browser chromium $FILTER -u | ||
| working-directory: tests | ||
| continue-on-error: true | ||
| - name: Update screenshots (firefox) | ||
| run: HOME=/root vp test -c vite.config.browser.ts --run --browser firefox $FILTER -u | ||
| working-directory: tests | ||
| continue-on-error: true | ||
| - name: Update screenshots (webkit) | ||
| run: HOME=/root vp test -c vite.config.browser.ts --run --browser webkit $FILTER -u | ||
| working-directory: tests | ||
| continue-on-error: true | ||
|
|
||
| - name: Show changed baselines | ||
| run: git config --global --add safe.directory "$GITHUB_WORKSPACE" && git status --porcelain tests/src | ||
|
|
||
| - name: Upload updated screenshots | ||
| uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 | ||
| with: | ||
| name: updated-screenshots | ||
| path: tests/src/**/__screenshots__/ | ||
| retention-days: 7 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not useful |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <!-- BEGIN:nextjs-agent-rules --> | ||
|
|
||
| # This is NOT the Next.js you know | ||
|
|
||
| This version has breaking changes — APIs, conventions, and file structure may all differ from your training data. Read the relevant guide in `node_modules/next/dist/docs/` (resolved from this file's directory; in monorepos the `next` package may not be visible from the repo root) before writing any code. Heed deprecation notices. | ||
|
|
||
| This block is written and re-added by `next dev` — verify at `node_modules/next/dist/server/lib/generate-agent-files.js`. Removing it from a diff only re-creates the uncommitted change; committing it with your work keeps the tree clean. | ||
|
|
||
| <!-- END:nextjs-agent-rules --> |
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not useful |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| @AGENTS.md |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // The Typst compiler wasm for the docs build (see next.config.ts): the | ||
| // pdf-ua example bundles it via Vite's `?url`; under the docs site the | ||
| // import is aliased here. `new URL(..., import.meta.url)` is Turbopack's | ||
| // static-asset reference: the ~29MB wasm is emitted as a hashed static | ||
| // file and served by the site itself - no CDN involved, and the version | ||
| // can't skew from the installed package because it IS the installed file. | ||
| const url = new URL( | ||
| "../node_modules/@myriaddreamin/typst-ts-web-compiler/pkg/typst_ts_web_compiler_bg.wasm", | ||
| import.meta.url, | ||
| ).href; | ||
| export default url; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| // Stub for @myriaddreamin/typst-ts-renderer (see next.config.ts): the | ||
| // pdf-ua demo only compiles Typst, never canvas-renders, so the optional | ||
| // renderer peer is not installed. | ||
| export {}; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -121,34 +121,29 @@ import { | |
|
|
||
|
|
||
| With the [PDF exporter](/docs/features/export/pdf), math blocks export as vector formulas — no rasterization, so they also work server-side out of the box. Inline math is rasterized to images that flow with the text: | ||
| With the [PDF exporter](/docs/features/export/pdf) (or the standalone | ||
| [Typst exporter](/docs/features/export/typst) — they share mappings), math | ||
| blocks and inline math export as **native Typst equations**: real, selectable | ||
| text, no rasterization, so they also work server-side out of the box: | ||
|
|
||
| ```typescript | ||
| import { | ||
| createInlineMathMapping, | ||
| inlineMathMapping, | ||
| mathBlockMapping, | ||
| } from "@blocknote/math-block/pdf-exporter"; | ||
| } from "@blocknote/math-block/typst-exporter"; | ||
|
|
||
| // Spread into the PDFExporter's mappings as for DOCX above - note that | ||
| // inline math is a factory here: `math: createInlineMathMapping()`. | ||
| // Spread into the PDFExporter's mappings as for DOCX above: | ||
| // `mathBlock: mathBlockMapping` and `math: inlineMathMapping`. | ||
| ``` | ||
|
|
||
| The inline math factory takes one option: | ||
|
|
||
| ```typescript | ||
| createInlineMathMapping(options?: { | ||
| /** | ||
| * Rasterizes the formula SVG to an image. Defaults to the built-in | ||
| * canvas rasterizer, which only works in the browser - when exporting | ||
| * server-side, pass one backed by e.g. `@resvg/resvg-js` or `sharp`; | ||
| * without it, a server-side export throws. The `RasterizeSVG` type is | ||
| * exported from the same subpath. | ||
| */ | ||
| rasterize?: RasterizeSVG; | ||
| }); | ||
| ``` | ||
| The LaTeX is converted to Typst's math notation. Most KaTeX commands are | ||
| covered; a valid formula using an uncovered command fails the export loudly | ||
| (rather than silently exporting something else), while invalid LaTeX renders | ||
| the error placeholder as in other formats. | ||
|
|
||
| Math blocks require the `@react-pdf/math` package (a peer dependency of the PDF mapping). | ||
| The deprecated [react-pdf exporter](/docs/features/export/pdf#deprecated-the-react-pdf-exporter)'s | ||
| mappings remain available from `@blocknote/math-block/pdf-exporter` during its | ||
| deprecation window. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see reason in preserving this for math which is new |
||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| { | ||
| "title": "Export", | ||
| "pages": ["markdown", "html", "pdf", "docx", "email", "odt", "..."] | ||
| "pages": ["markdown", "html", "pdf", "docx", "email", "odt", "typst", "..."] | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get why we'd need this, you can re-gen with docker, why is that different?