pulpweaver4 0.0.91 → 0.0.186
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ast/djot.js +23 -0
- package/dist/ast/djot.js.map +1 -1
- package/dist/ast/index.d.ts +1 -0
- package/dist/ast/index.js +1 -0
- package/dist/ast/index.js.map +1 -1
- package/dist/ast/nodes.d.ts +59 -5
- package/dist/ast/nodes.js.map +1 -1
- package/dist/ast/table.d.ts +27 -0
- package/dist/ast/table.js +32 -0
- package/dist/ast/table.js.map +1 -0
- package/dist/browser.js +2420 -0
- package/dist/citations/index.d.ts +1 -1
- package/dist/citations/index.js +1 -1
- package/dist/citations/index.js.map +1 -1
- package/dist/citations/project.d.ts +12 -2
- package/dist/citations/project.js +21 -7
- package/dist/citations/project.js.map +1 -1
- package/dist/colour/images.d.ts +11 -2
- package/dist/colour/images.js +53 -3
- package/dist/colour/images.js.map +1 -1
- package/dist/colour/ink-limit.d.ts +2 -2
- package/dist/colour/ink-limit.js +6 -0
- package/dist/colour/ink-limit.js.map +1 -1
- package/dist/colour/previews.d.ts +8 -4
- package/dist/colour/previews.js +11 -8
- package/dist/colour/previews.js.map +1 -1
- package/dist/config/config.d.ts +91 -3
- package/dist/config/config.js +200 -3
- package/dist/config/config.js.map +1 -1
- package/dist/config/project-schema.d.ts +0 -8
- package/dist/config/project-schema.js +207 -12
- package/dist/config/project-schema.js.map +1 -1
- package/dist/config/schema.js +10 -0
- package/dist/config/schema.js.map +1 -1
- package/dist/config/secrets.d.ts +11 -0
- package/dist/config/secrets.js +19 -0
- package/dist/config/secrets.js.map +1 -0
- package/dist/csl/project.d.ts +19 -4
- package/dist/csl/project.js +23 -10
- package/dist/csl/project.js.map +1 -1
- package/dist/fonts/index.d.ts +1 -1
- package/dist/fonts/index.js +1 -1
- package/dist/fonts/index.js.map +1 -1
- package/dist/fonts/lint.d.ts +51 -0
- package/dist/fonts/lint.js +101 -16
- package/dist/fonts/lint.js.map +1 -1
- package/dist/fonts/walk.d.ts +13 -0
- package/dist/fonts/walk.js +50 -33
- package/dist/fonts/walk.js.map +1 -1
- package/dist/html/css.d.ts +4 -0
- package/dist/html/css.js +11 -3
- package/dist/html/css.js.map +1 -1
- package/dist/html/dom.d.ts +6 -1
- package/dist/html/dom.js +28 -6
- package/dist/html/dom.js.map +1 -1
- package/dist/html/generated.d.ts +17 -0
- package/dist/html/generated.js +21 -0
- package/dist/html/generated.js.map +1 -0
- package/dist/html/images.d.ts +18 -0
- package/dist/html/images.js +49 -2
- package/dist/html/images.js.map +1 -1
- package/dist/html/index.d.ts +1 -0
- package/dist/html/index.js +1 -0
- package/dist/html/index.js.map +1 -1
- package/dist/html/render.d.ts +5 -4
- package/dist/html/render.js +24 -6
- package/dist/html/render.js.map +1 -1
- package/dist/hyphenation/exceptions.d.ts +5 -0
- package/dist/hyphenation/exceptions.js +11 -0
- package/dist/hyphenation/exceptions.js.map +1 -1
- package/dist/hyphenation/index.d.ts +1 -1
- package/dist/hyphenation/index.js +1 -1
- package/dist/hyphenation/index.js.map +1 -1
- package/dist/import/convert.d.ts +21 -0
- package/dist/import/convert.js +65 -0
- package/dist/import/convert.js.map +1 -0
- package/dist/incremental/cache.d.ts +59 -0
- package/dist/incremental/cache.js +64 -0
- package/dist/incremental/cache.js.map +1 -0
- package/dist/incremental/index.d.ts +3 -0
- package/dist/incremental/index.js +4 -0
- package/dist/incremental/index.js.map +1 -0
- package/dist/incremental/keys.d.ts +27 -0
- package/dist/incremental/keys.js +89 -0
- package/dist/incremental/keys.js.map +1 -0
- package/dist/incremental/session.d.ts +180 -0
- package/dist/incremental/session.js +401 -0
- package/dist/incremental/session.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/indexes/layout.d.ts +8 -2
- package/dist/indexes/layout.js +6 -4
- package/dist/indexes/layout.js.map +1 -1
- package/dist/layout/cache.d.ts +174 -0
- package/dist/layout/cache.js +150 -0
- package/dist/layout/cache.js.map +1 -0
- package/dist/layout/converge.d.ts +28 -0
- package/dist/layout/converge.js +102 -9
- package/dist/layout/converge.js.map +1 -1
- package/dist/layout/counters.d.ts +4 -0
- package/dist/layout/counters.js +15 -0
- package/dist/layout/counters.js.map +1 -1
- package/dist/layout/index.d.ts +5 -2
- package/dist/layout/index.js +3 -0
- package/dist/layout/index.js.map +1 -1
- package/dist/layout/lists.d.ts +52 -3
- package/dist/layout/lists.js +513 -46
- package/dist/layout/lists.js.map +1 -1
- package/dist/layout/lookahead.d.ts +151 -0
- package/dist/layout/lookahead.js +581 -0
- package/dist/layout/lookahead.js.map +1 -0
- package/dist/layout/margin-boxes.d.ts +11 -1
- package/dist/layout/margin-boxes.js +24 -1
- package/dist/layout/margin-boxes.js.map +1 -1
- package/dist/layout/page-rules.d.ts +6 -1
- package/dist/layout/page-rules.js +42 -1
- package/dist/layout/page-rules.js.map +1 -1
- package/dist/layout/page.js +4 -2
- package/dist/layout/page.js.map +1 -1
- package/dist/layout/pagebuilder.d.ts +248 -3
- package/dist/layout/pagebuilder.js +512 -19
- package/dist/layout/pagebuilder.js.map +1 -1
- package/dist/layout/pages.d.ts +108 -1
- package/dist/layout/pages.js +1362 -159
- package/dist/layout/pages.js.map +1 -1
- package/dist/layout/paragraph.d.ts +14 -0
- package/dist/layout/paragraph.js +304 -31
- package/dist/layout/paragraph.js.map +1 -1
- package/dist/layout/pre.js +4 -0
- package/dist/layout/pre.js.map +1 -1
- package/dist/layout/protrusion.d.ts +26 -0
- package/dist/layout/protrusion.js +39 -0
- package/dist/layout/protrusion.js.map +1 -0
- package/dist/layout/ranges.d.ts +2 -0
- package/dist/layout/ranges.js +22 -0
- package/dist/layout/ranges.js.map +1 -0
- package/dist/layout/region.d.ts +2 -1
- package/dist/layout/region.js +9 -5
- package/dist/layout/region.js.map +1 -1
- package/dist/layout/templates.d.ts +71 -0
- package/dist/layout/templates.js +290 -0
- package/dist/layout/templates.js.map +1 -0
- package/dist/layout/vlist.d.ts +3 -3
- package/dist/linebreak/items.d.ts +27 -2
- package/dist/linebreak/items.js +10 -3
- package/dist/linebreak/items.js.map +1 -1
- package/dist/linebreak/knuth-plass.d.ts +20 -0
- package/dist/linebreak/knuth-plass.js +68 -16
- package/dist/linebreak/knuth-plass.js.map +1 -1
- package/dist/lint/book.d.ts +13 -0
- package/dist/lint/book.js +52 -0
- package/dist/lint/book.js.map +1 -0
- package/dist/lint/config.d.ts +9 -0
- package/dist/lint/config.js +40 -6
- package/dist/lint/config.js.map +1 -1
- package/dist/lint/linter.js +1 -0
- package/dist/lint/linter.js.map +1 -1
- package/dist/lint/project.js +1 -1
- package/dist/lint/project.js.map +1 -1
- package/dist/lint/rules/layout.d.ts +3 -1
- package/dist/lint/rules/layout.js +8 -6
- package/dist/lint/rules/layout.js.map +1 -1
- package/dist/lint/rules/source.js +1 -1
- package/dist/lint/rules/source.js.map +1 -1
- package/dist/lint/testing.js +1 -0
- package/dist/lint/testing.js.map +1 -1
- package/dist/measure/bidi-data.d.ts +14 -0
- package/dist/measure/bidi-data.js +69 -0
- package/dist/measure/bidi-data.js.map +1 -0
- package/dist/measure/bidi.d.ts +70 -0
- package/dist/measure/bidi.js +225 -0
- package/dist/measure/bidi.js.map +1 -0
- package/dist/measure/css.d.ts +5 -0
- package/dist/measure/css.js +2 -0
- package/dist/measure/css.js.map +1 -1
- package/dist/measure/measurer.d.ts +36 -2
- package/dist/measure/measurer.js +220 -22
- package/dist/measure/measurer.js.map +1 -1
- package/dist/measure/model.d.ts +20 -2
- package/dist/measure/model.js +13 -6
- package/dist/measure/model.js.map +1 -1
- package/dist/measure/script-data.d.ts +6 -0
- package/dist/measure/script-data.js +34 -0
- package/dist/measure/script-data.js.map +1 -0
- package/dist/measure/scripts.d.ts +36 -0
- package/dist/measure/scripts.js +293 -0
- package/dist/measure/scripts.js.map +1 -0
- package/dist/output/output.d.ts +35 -3
- package/dist/output/output.js +26 -4
- package/dist/output/output.js.map +1 -1
- package/dist/paint/backgrounds.js +7 -20
- package/dist/paint/backgrounds.js.map +1 -1
- package/dist/paint/blend.d.ts +33 -13
- package/dist/paint/blend.js +73 -21
- package/dist/paint/blend.js.map +1 -1
- package/dist/paint/cache.d.ts +80 -0
- package/dist/paint/cache.js +537 -0
- package/dist/paint/cache.js.map +1 -0
- package/dist/paint/canvas.d.ts +4 -13
- package/dist/paint/canvas.js +45 -5
- package/dist/paint/canvas.js.map +1 -1
- package/dist/paint/context.d.ts +2 -0
- package/dist/paint/emphasis.js +1 -1
- package/dist/paint/emphasis.js.map +1 -1
- package/dist/paint/flatten.d.ts +24 -2
- package/dist/paint/flatten.js +55 -12
- package/dist/paint/flatten.js.map +1 -1
- package/dist/paint/forms.d.ts +64 -0
- package/dist/paint/forms.js +319 -0
- package/dist/paint/forms.js.map +1 -0
- package/dist/paint/images.d.ts +4 -1
- package/dist/paint/images.js +13 -2
- package/dist/paint/images.js.map +1 -1
- package/dist/paint/layers.d.ts +64 -0
- package/dist/paint/layers.js +137 -0
- package/dist/paint/layers.js.map +1 -0
- package/dist/paint/painter.d.ts +19 -6
- package/dist/paint/painter.js +15 -135
- package/dist/paint/painter.js.map +1 -1
- package/dist/paint/stacking.d.ts +1 -1
- package/dist/paint/stacking.js +9 -2
- package/dist/paint/stacking.js.map +1 -1
- package/dist/paint/text.d.ts +14 -3
- package/dist/paint/text.js +25 -4
- package/dist/paint/text.js.map +1 -1
- package/dist/paint/vertical.js +2 -2
- package/dist/paint/vertical.js.map +1 -1
- package/dist/pdf/encoded.d.ts +16 -0
- package/dist/pdf/encoded.js +35 -0
- package/dist/pdf/encoded.js.map +1 -0
- package/dist/pdf/include/colour.d.ts +105 -0
- package/dist/pdf/include/colour.js +349 -0
- package/dist/pdf/include/colour.js.map +1 -0
- package/dist/pdf/include/functions.d.ts +17 -0
- package/dist/pdf/include/functions.js +389 -0
- package/dist/pdf/include/functions.js.map +1 -0
- package/dist/pdf/include/pages.d.ts +14 -0
- package/dist/pdf/include/pages.js +27 -0
- package/dist/pdf/include/pages.js.map +1 -0
- package/dist/pdf/include/pdfjs/LICENSE +177 -0
- package/dist/pdf/include/pdfjs/pdf.min.mjs +27 -0
- package/dist/pdf/include/pdfjs/pdf.worker.min.mjs +27 -0
- package/dist/pdf/include/pdfjs/standard_fonts/FoxitDingbats.pfb +0 -0
- package/dist/pdf/include/pdfjs/standard_fonts/FoxitFixed.pfb +0 -0
- package/dist/pdf/include/pdfjs/standard_fonts/FoxitFixedBold.pfb +0 -0
- package/dist/pdf/include/pdfjs/standard_fonts/FoxitFixedBoldItalic.pfb +0 -0
- package/dist/pdf/include/pdfjs/standard_fonts/FoxitFixedItalic.pfb +0 -0
- package/dist/pdf/include/pdfjs/standard_fonts/FoxitSerif.pfb +0 -0
- package/dist/pdf/include/pdfjs/standard_fonts/FoxitSerifBold.pfb +0 -0
- package/dist/pdf/include/pdfjs/standard_fonts/FoxitSerifBoldItalic.pfb +0 -0
- package/dist/pdf/include/pdfjs/standard_fonts/FoxitSerifItalic.pfb +0 -0
- package/dist/pdf/include/pdfjs/standard_fonts/FoxitSymbol.pfb +0 -0
- package/dist/pdf/include/pdfjs/standard_fonts/LICENSE_FOXIT +27 -0
- package/dist/pdf/include/pdfjs/standard_fonts/LICENSE_LIBERATION +363 -0
- package/dist/pdf/include/pdfjs/standard_fonts/LiberationSans-Bold.ttf +0 -0
- package/dist/pdf/include/pdfjs/standard_fonts/LiberationSans-BoldItalic.ttf +0 -0
- package/dist/pdf/include/pdfjs/standard_fonts/LiberationSans-Italic.ttf +0 -0
- package/dist/pdf/include/pdfjs/standard_fonts/LiberationSans-Regular.ttf +0 -0
- package/dist/pdf/include/pdfjs/wasm/LICENSE_JBIG2 +196 -0
- package/dist/pdf/include/pdfjs/wasm/LICENSE_OPENJPEG +39 -0
- package/dist/pdf/include/pdfjs/wasm/LICENSE_PDFJS_JBIG2 +13 -0
- package/dist/pdf/include/pdfjs/wasm/LICENSE_PDFJS_OPENJPEG +22 -0
- package/dist/pdf/include/pdfjs/wasm/LICENSE_PDFJS_QCMS +19 -0
- package/dist/pdf/include/pdfjs/wasm/LICENSE_QCMS +21 -0
- package/dist/pdf/include/pdfjs/wasm/jbig2.wasm +0 -0
- package/dist/pdf/include/pdfjs/wasm/openjpeg.wasm +0 -0
- package/dist/pdf/include/pdfjs/wasm/qcms_bg.wasm +0 -0
- package/dist/pdf/include/pdfjs/wasm/quickjs-eval.wasm +0 -0
- package/dist/pdf/include/prepare.d.ts +58 -0
- package/dist/pdf/include/prepare.js +266 -0
- package/dist/pdf/include/prepare.js.map +1 -0
- package/dist/pdf/include/preview.d.ts +38 -0
- package/dist/pdf/include/preview.js +101 -0
- package/dist/pdf/include/preview.js.map +1 -0
- package/dist/pdf/include/rewrite.d.ts +57 -0
- package/dist/pdf/include/rewrite.js +803 -0
- package/dist/pdf/include/rewrite.js.map +1 -0
- package/dist/pdf/include/serialize.d.ts +32 -0
- package/dist/pdf/include/serialize.js +158 -0
- package/dist/pdf/include/serialize.js.map +1 -0
- package/dist/pdf/include/testing.d.ts +26 -0
- package/dist/pdf/include/testing.js +50 -0
- package/dist/pdf/include/testing.js.map +1 -0
- package/dist/pdf/index.d.ts +1 -0
- package/dist/pdf/index.js +1 -0
- package/dist/pdf/index.js.map +1 -1
- package/dist/pdf/structure/annotations.d.ts +33 -0
- package/dist/pdf/structure/annotations.js +112 -0
- package/dist/pdf/structure/annotations.js.map +1 -0
- package/dist/pdf/structure/forms.d.ts +10 -0
- package/dist/pdf/structure/forms.js +46 -0
- package/dist/pdf/structure/forms.js.map +1 -0
- package/dist/pdf/structure/index.d.ts +41 -5
- package/dist/pdf/structure/index.js +40 -5
- package/dist/pdf/structure/index.js.map +1 -1
- package/dist/pdf/structure/links.d.ts +2 -0
- package/dist/pdf/structure/links.js +1 -1
- package/dist/pdf/structure/links.js.map +1 -1
- package/dist/pdf/structure/presentation.d.ts +28 -0
- package/dist/pdf/structure/presentation.js +79 -0
- package/dist/pdf/structure/presentation.js.map +1 -0
- package/dist/pdf/structure/tags.d.ts +34 -2
- package/dist/pdf/structure/tags.js +117 -14
- package/dist/pdf/structure/tags.js.map +1 -1
- package/dist/pdf/types.d.ts +357 -11
- package/dist/pdf/wasm/pulpweaver4_pdf.d.ts +44 -2
- package/dist/pdf/wasm/pulpweaver4_pdf.js +191 -2
- package/dist/pdf/wasm/pulpweaver4_pdf_bg.wasm +0 -0
- package/dist/pdf/writer.d.ts +13 -1
- package/dist/pdf/writer.js +26 -1
- package/dist/pdf/writer.js.map +1 -1
- package/dist/plugin/define.d.ts +200 -15
- package/dist/plugin/define.js +124 -15
- package/dist/plugin/define.js.map +1 -1
- package/dist/plugin/failure.d.ts +1 -1
- package/dist/plugin/index.d.ts +5 -4
- package/dist/plugin/index.js +5 -4
- package/dist/plugin/index.js.map +1 -1
- package/dist/plugin/reference.d.ts +38 -0
- package/dist/plugin/reference.js +287 -0
- package/dist/plugin/reference.js.map +1 -0
- package/dist/plugin/register.d.ts +39 -7
- package/dist/plugin/register.js +83 -2
- package/dist/plugin/register.js.map +1 -1
- package/dist/preflight/index.d.ts +1 -1
- package/dist/preflight/index.js +1 -1
- package/dist/preflight/index.js.map +1 -1
- package/dist/preflight/pdfx.d.ts +35 -0
- package/dist/preflight/pdfx.js +33 -2
- package/dist/preflight/pdfx.js.map +1 -1
- package/dist/preflight/reader.d.ts +10 -3
- package/dist/preflight/reader.js +86 -5
- package/dist/preflight/reader.js.map +1 -1
- package/dist/print/impose.d.ts +66 -0
- package/dist/print/impose.js +331 -0
- package/dist/print/impose.js.map +1 -0
- package/dist/print/output.js +400 -50
- package/dist/print/output.js.map +1 -1
- package/dist/problem.js +4 -3
- package/dist/problem.js.map +1 -1
- package/dist/profile/index.d.ts +1 -0
- package/dist/profile/index.js +1 -0
- package/dist/profile/index.js.map +1 -1
- package/dist/profile/lint.d.ts +1 -1
- package/dist/profile/lint.js +29 -1
- package/dist/profile/lint.js.map +1 -1
- package/dist/profile/list-table.d.ts +51 -0
- package/dist/profile/list-table.js +137 -0
- package/dist/profile/list-table.js.map +1 -0
- package/dist/profile/metadata.js +3 -0
- package/dist/profile/metadata.js.map +1 -1
- package/dist/profile/profile.d.ts +3 -0
- package/dist/profile/profile.js +9 -1
- package/dist/profile/profile.js.map +1 -1
- package/dist/project.js +3 -0
- package/dist/project.js.map +1 -1
- package/dist/qpdf/index.d.ts +2 -0
- package/dist/qpdf/index.js +3 -0
- package/dist/qpdf/index.js.map +1 -0
- package/dist/qpdf/qpdf.d.ts +125 -0
- package/dist/qpdf/qpdf.js +205 -0
- package/dist/qpdf/qpdf.js.map +1 -0
- package/dist/qpdf/testing.d.ts +12 -0
- package/dist/qpdf/testing.js +9 -0
- package/dist/qpdf/testing.js.map +1 -0
- package/dist/qpdf/wasm/LICENSE-qpdf +202 -0
- package/dist/qpdf/wasm/LICENSE-zlib +22 -0
- package/dist/qpdf/wasm/NOTICE-qpdf.md +42 -0
- package/dist/qpdf/wasm/qpdf.wasm +0 -0
- package/dist/render/index.d.ts +3 -0
- package/dist/render/index.js +2 -0
- package/dist/render/index.js.map +1 -0
- package/dist/render/render.d.ts +98 -0
- package/dist/render/render.js +243 -0
- package/dist/render/render.js.map +1 -0
- package/dist/reproducible/clock.d.ts +4 -5
- package/dist/reproducible/clock.js +4 -5
- package/dist/reproducible/clock.js.map +1 -1
- package/dist/spike/spike-page.chromium.json +4 -4
- package/dist/style/colours.d.ts +7 -2
- package/dist/style/colours.js +24 -2
- package/dist/style/colours.js.map +1 -1
- package/dist/style/compile.js +1 -1
- package/dist/style/compile.js.map +1 -1
- package/dist/style/defaults.d.ts +9 -3
- package/dist/style/defaults.js +14 -2
- package/dist/style/defaults.js.map +1 -1
- package/dist/style/gcpm.d.ts +1 -1
- package/dist/style/gcpm.js +17 -5
- package/dist/style/gcpm.js.map +1 -1
- package/dist/style/properties.js +84 -0
- package/dist/style/properties.js.map +1 -1
- package/dist/test/book.d.ts +22 -2
- package/dist/test/book.js +35 -2
- package/dist/test/book.js.map +1 -1
- package/dist/test/build.d.ts +23 -0
- package/dist/test/build.js +86 -33
- package/dist/test/build.js.map +1 -1
- package/dist/test/layout.js +128 -19
- package/dist/test/layout.js.map +1 -1
- package/dist/test/limits.d.ts +8 -0
- package/dist/test/limits.js +9 -0
- package/dist/test/limits.js.map +1 -0
- package/dist/test/pipeline.d.ts +23 -0
- package/dist/test/pipeline.js.map +1 -1
- package/dist/test/render.d.ts +26 -3
- package/dist/test/render.js +151 -23
- package/dist/test/render.js.map +1 -1
- package/dist/test/runner.d.ts +6 -3
- package/dist/test/runner.js +172 -105
- package/dist/test/runner.js.map +1 -1
- package/dist/test/text.js +2 -2
- package/dist/test/text.js.map +1 -1
- package/dist/text/output.js +2 -2
- package/dist/text/output.js.map +1 -1
- package/dist/text/render.d.ts +4 -3
- package/dist/text/render.js +126 -4
- package/dist/text/render.js.map +1 -1
- package/dist/transform/index.d.ts +1 -1
- package/dist/transform/index.js +1 -1
- package/dist/transform/index.js.map +1 -1
- package/dist/transform/run.d.ts +2 -0
- package/dist/transform/run.js +32 -16
- package/dist/transform/run.js.map +1 -1
- package/dist/web/output.js +116 -10
- package/dist/web/output.js.map +1 -1
- package/dist/web/runtime/justify.js.txt +2 -2
- package/dist/web/site.d.ts +2 -0
- package/dist/web/site.js +8 -1
- package/dist/web/site.js.map +1 -1
- package/docs/README.md +6 -1
- package/docs/manual/chapters/front.dj +34 -0
- package/docs/manual/chapters/guides/citations.dj +426 -0
- package/docs/manual/chapters/guides/colour-and-prepress.dj +261 -0
- package/docs/manual/chapters/guides/editions.dj +329 -0
- package/docs/manual/chapters/guides/in-a-web-page.dj +143 -0
- package/docs/manual/chapters/guides/lines-and-pages.dj +681 -0
- package/docs/manual/chapters/guides/lint-rules.dj +355 -0
- package/docs/manual/chapters/guides/pdfs.dj +501 -0
- package/docs/manual/chapters/guides/plugins.dj +425 -0
- package/docs/manual/chapters/guides/testing.dj +264 -0
- package/docs/manual/chapters/guides/writing-in-djot.dj +537 -0
- package/docs/manual/chapters/start/for-latex-users.dj +256 -0
- package/docs/manual/chapters/start/getting-started.dj +167 -0
- package/docs/manual/chapters/start/your-first-book.dj +426 -0
- package/docs/manual/fonts/CrimsonPro-Italic-VF.ttf +0 -0
- package/docs/manual/fonts/CrimsonPro-VF.ttf +0 -0
- package/docs/manual/fonts/JetBrainsMono-Regular.otf +0 -0
- package/docs/manual/fonts/NotoSansSymbols2-Boxes.ttf +0 -0
- package/docs/manual/fonts/OFL.txt +95 -0
- package/docs/manual/pulpweaver4.toml +39 -0
- package/docs/manual/styles/manual.css +137 -0
- package/docs/reference/css-properties/index.md +9 -0
- package/docs/reference/css-properties/pw-expansion.md +31 -0
- package/docs/reference/css-properties/pw-flow-into.md +31 -0
- package/docs/reference/css-properties/pw-knockout.md +26 -0
- package/docs/reference/css-properties/pw-layer.md +24 -0
- package/docs/reference/css-properties/pw-page-breaking.md +30 -0
- package/docs/reference/css-properties/pw-page-duration.md +28 -0
- package/docs/reference/css-properties/pw-page-rotate.md +29 -0
- package/docs/reference/css-properties/pw-page-transition.md +29 -0
- package/docs/reference/css-properties/pw-protrusion.md +31 -0
- package/docs/reference/lint-rules/ibid-across-page.md +2 -2
- package/docs/reference/plugin-api/capabilities.md +2 -2
- package/docs/reference/plugin-api/claim-kind.md +1 -1
- package/docs/reference/plugin-api/combine-exceptions.md +19 -0
- package/docs/reference/plugin-api/element-break-context.md +34 -0
- package/docs/reference/plugin-api/element-break-item.md +24 -0
- package/docs/reference/plugin-api/element-breaker.md +24 -0
- package/docs/reference/plugin-api/flow-definition.md +30 -0
- package/docs/reference/plugin-api/generated-reference.md +32 -0
- package/docs/reference/plugin-api/index-definition.md +32 -0
- package/docs/reference/plugin-api/index-titles.md +18 -0
- package/docs/reference/plugin-api/index.md +27 -3
- package/docs/reference/plugin-api/insert-class-definition.md +46 -0
- package/docs/reference/plugin-api/insert-placement.md +22 -0
- package/docs/reference/plugin-api/insert-placements.md +18 -0
- package/docs/reference/plugin-api/layout-definition.md +9 -5
- package/docs/reference/plugin-api/layout-slot.md +6 -16
- package/docs/reference/plugin-api/lint-context.md +3 -1
- package/docs/reference/plugin-api/lint-definition.md +1 -1
- package/docs/reference/plugin-api/lint-edition.md +2 -0
- package/docs/reference/plugin-api/page-builder-event.md +22 -0
- package/docs/reference/plugin-api/page-builder-hook.md +7 -3
- package/docs/reference/plugin-api/page-builder-page-event.md +30 -0
- package/docs/reference/plugin-api/page-template-definition.md +34 -0
- package/docs/reference/plugin-api/page-template-region-definition.md +46 -0
- package/docs/reference/plugin-api/plugin-definition.md +5 -1
- package/docs/reference/plugin-api/plugin-reference-options.md +32 -0
- package/docs/reference/plugin-api/plugin-reference.md +22 -0
- package/docs/reference/plugin-api/plugin-registry.md +15 -5
- package/docs/reference/plugin-api/plugin-stage.md +1 -1
- package/docs/reference/plugin-api/plugin.md +9 -2
- package/docs/reference/plugin-api/reference-page.md +34 -0
- package/docs/reference/plugin-api/render-reference-page.md +18 -0
- package/docs/reference/plugin-api/renderers.md +1 -1
- package/docs/reference/pulpweaver4-toml/editions.md +239 -2
- package/docs/reference/pulpweaver4-toml/index.md +44 -1
- package/docs/reference/pulpweaver4-toml/inks.md +15 -4
- package/docs/reference/pulpweaver4-toml/lint.md +1 -1
- package/package.json +5 -1
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
``` =meta
|
|
2
|
+
description = 'Extend pulpweaver4 with a plugin — claim a block, number it, render it to HTML and text, style it, keep it on one page, lint it and test it; break lines, process images and add pw commands — and load it from the project, npm or a URL.'
|
|
3
|
+
```
|
|
4
|
+
|
|
5
|
+
{#plugins}
|
|
6
|
+
# Writing a plugin
|
|
7
|
+
|
|
8
|
+
Everything beyond the core is a plugin: a block of your own, a transform
|
|
9
|
+
that numbers or looks things up, a lint rule, a matcher for tests, an output
|
|
10
|
+
format. Where LaTeX has `\newcommand` and packages, pulpweaver4 has plugins,
|
|
11
|
+
written in JavaScript or TypeScript, with tests, and kept out of the source:
|
|
12
|
+
a chapter stays plain Djot that any tool can read.
|
|
13
|
+
|
|
14
|
+
{#a-plugin-is-a-module}
|
|
15
|
+
## A plugin is a module
|
|
16
|
+
|
|
17
|
+
A plugin is an ES module whose default export says what it adds. This one
|
|
18
|
+
gives a book `::: note` blocks, numbered through the book, set apart in a
|
|
19
|
+
box that never breaks across pages:
|
|
20
|
+
|
|
21
|
+
{project=note file="plugins/note.js"}
|
|
22
|
+
``` js
|
|
23
|
+
// plugins/note.js
|
|
24
|
+
function* walk(node) {
|
|
25
|
+
yield node
|
|
26
|
+
for (const child of node.children ?? []) yield* walk(child)
|
|
27
|
+
}
|
|
28
|
+
const isNote = (node) => node.type === 'pluginBlock' && node.name === 'note'
|
|
29
|
+
|
|
30
|
+
export default {
|
|
31
|
+
name: 'note',
|
|
32
|
+
api: 1,
|
|
33
|
+
description: 'Numbered notes, set apart from the text.',
|
|
34
|
+
url: import.meta.url,
|
|
35
|
+
options: {
|
|
36
|
+
type: 'object',
|
|
37
|
+
additionalProperties: false,
|
|
38
|
+
properties: { label: { type: 'string', description: 'The word before each number.' } },
|
|
39
|
+
},
|
|
40
|
+
blocks: {
|
|
41
|
+
note: { description: 'A note.', attributes: { kind: { type: 'string', enum: ['tip', 'warning'] } } },
|
|
42
|
+
},
|
|
43
|
+
transform: {
|
|
44
|
+
phase: 'number',
|
|
45
|
+
run(ast, ctx) {
|
|
46
|
+
let n = 0
|
|
47
|
+
for (const document of ast.documents) {
|
|
48
|
+
for (const node of walk(document)) {
|
|
49
|
+
if (isNote(node)) node.number = `${ctx.options.label ?? 'Note'} ${++n}`
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
render: {
|
|
55
|
+
note: {
|
|
56
|
+
html: (node, h, ctx) =>
|
|
57
|
+
h('aside.note', { 'data-kind': node.attributes?.kind ?? 'tip' }, [
|
|
58
|
+
h('b.note-label', node.number),
|
|
59
|
+
...ctx.render(node.children),
|
|
60
|
+
]),
|
|
61
|
+
text: (node, render) => `[${node.number}] ${render.children(node)}`,
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
styles: ['./note.css'],
|
|
65
|
+
layout: { boxes: ['aside.note'] },
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Its stylesheet is a file beside it, `./note.css`, read from beside the module
|
|
70
|
+
(`url`, its `import.meta.url`, says where that is when a test imports it):
|
|
71
|
+
|
|
72
|
+
{project=note file="plugins/note.css"}
|
|
73
|
+
``` css
|
|
74
|
+
/* plugins/note.css */
|
|
75
|
+
.note { border: 0.5pt solid; padding: 6pt 9pt; margin: 9pt 0; }
|
|
76
|
+
.note-label { display: block; }
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Name it in `pulpweaver4.toml`, with its options:
|
|
80
|
+
|
|
81
|
+
{project=note}
|
|
82
|
+
``` toml
|
|
83
|
+
[plugins]
|
|
84
|
+
"./plugins/note.js" = { label = "Aside" }
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
and use it in a chapter:
|
|
88
|
+
|
|
89
|
+
{project=note}
|
|
90
|
+
``` djot
|
|
91
|
+
{kind=warning}
|
|
92
|
+
::: note
|
|
93
|
+
Print the letter edition at actual size.
|
|
94
|
+
:::
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
`pw build` puts “Aside 1” over the note, in a box, in every PDF; on the web
|
|
98
|
+
the same `<aside>`; and in the text edition “\[Aside 1\] Print the letter
|
|
99
|
+
edition at actual size.”
|
|
100
|
+
|
|
101
|
+
{#loading-plugins}
|
|
102
|
+
## Loading plugins
|
|
103
|
+
|
|
104
|
+
`[plugins]` names each plugin with a table of its options:
|
|
105
|
+
|
|
106
|
+
- *A file in the project*: the key is its path, quoted, starting `./`:
|
|
107
|
+
`"./plugins/note.js" = {}`. It is a JavaScript module, imported as a
|
|
108
|
+
browser imports one from a server of the project’s folder: it can import
|
|
109
|
+
modules beside it (`import { count } from './count.js'`), and
|
|
110
|
+
`pulpweaver4` (`import { definePlugin } from 'pulpweaver4'`), which is
|
|
111
|
+
the core of the `pw` running it. That holds in every `pw`: `pw build`,
|
|
112
|
+
`pw lint`, `pw test` and the plugin’s own commands. A plugin to share
|
|
113
|
+
between books is better as a package.
|
|
114
|
+
- *An npm package*, installed in the project, by its name:
|
|
115
|
+
`pulpweaver4-questions = {}`. `pw add pulpweaver4-questions` does both,
|
|
116
|
+
`npm install` in the project and the line in `[plugins]`. A
|
|
117
|
+
package can import `pulpweaver4` (as a peer dependency), import its own
|
|
118
|
+
files, fetch the fonts and data it ships by
|
|
119
|
+
`new URL('../fonts/x.otf', import.meta.url)`, as it would unbundled, and
|
|
120
|
+
be written in TypeScript.
|
|
121
|
+
- *A URL*, `"https://…/plugin.js" = {}`, which `pw build` and `pw lint`
|
|
122
|
+
fetch.
|
|
123
|
+
|
|
124
|
+
The browser app has the official plugins built in, `pulpweaver4-epub`,
|
|
125
|
+
`pulpweaver4-rst` and `pulpweaver4-scripture`, and loads a plugin in the
|
|
126
|
+
project or at a URL as `pw build` does; another npm package, which the
|
|
127
|
+
page can’t install, is an error there that says so. `pw dev` loads a
|
|
128
|
+
project’s plugins as `pw build` does, from its `node_modules`.
|
|
129
|
+
|
|
130
|
+
The options are checked against the plugin’s `options` schema, a subset of
|
|
131
|
+
JSON Schema, so a mistake, `label = 3` say, is an error at its place in
|
|
132
|
+
`pulpweaver4.toml`:
|
|
133
|
+
|
|
134
|
+
{.untested}
|
|
135
|
+
``` text
|
|
136
|
+
pulpweaver4.toml:26:33: error: plugins."./plugins/note.js".label must be a string, not 3 [wrong-type]
|
|
137
|
+
|
|
|
138
|
+
24 |
|
|
139
|
+
25 | [plugins]
|
|
140
|
+
26 | "./plugins/note.js" = { label = 3 }
|
|
141
|
+
| ^
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
A plugin without an `options` schema takes no options.
|
|
145
|
+
|
|
146
|
+
{#what-a-plugin-can-add}
|
|
147
|
+
## What a plugin can add
|
|
148
|
+
|
|
149
|
+
| Key | Adds | Works now |
|
|
150
|
+
|----|----|----|
|
|
151
|
+
| `blocks`, `inlines` | `::: name` blocks and `[text]{.name}` spans it owns, with the attributes they take, which the build checks | Yes |
|
|
152
|
+
| `transform` | A function that changes the document in a phase: `resolve`, `number`, `cite`, `index`, `link` or `finalize` | Yes |
|
|
153
|
+
| `render` | HTML for its nodes (`html`, or a function), and their text-edition form (`text`) | Yes |
|
|
154
|
+
| `styles` | CSS, a path beside the module or `{ css: '…' }`, in a cascade layer of its own, `pw.plugins.<name>`, applying only to what it renders | Yes |
|
|
155
|
+
| `layout` | `boxes`: selectors of elements kept whole, never broken across pages; `penalties`: a penalty before or after them | Yes |
|
|
156
|
+
| `lint` | Lint rules and presets, its `recommended` on wherever the core’s is: see [Lint rules for your press](#writing-your-own) | Yes |
|
|
157
|
+
| `matchers` | `expect` matchers for tests | In a test’s own build: [below](#testing-a-plugin) |
|
|
158
|
+
| `read` | A reader for another source format, by file extension | Yes |
|
|
159
|
+
| `output` | An output format, for an edition’s `output` | Yes |
|
|
160
|
+
| `layout`’s `lineBreakers` | Line breakers of your own, by element or language: [below](#line-breakers) | Yes |
|
|
161
|
+
| `layout`’s `resolvers` | What a print edition fills in from its pages, as page references and indexes are: each is given the pages and the book’s HTML, changes the HTML, and returns the elements it changed, the book laid out again until none change. A link it adds is tagged as one in a tagged PDF | Yes |
|
|
162
|
+
| `assets` | Processing the project’s images and fonts, by file type: [below](#processing-images-and-fonts) | Yes |
|
|
163
|
+
| `commands` | `pw <command>`: [below](#commands) | Yes |
|
|
164
|
+
| `layout`’s `inserts`, `pageTemplates`, `flows`, `pageBuilder` | New kinds of inserts, page templates, flows, page-builder hooks | Not yet: accepted, not used ([#138](https://gitlab.com/inkylabs/pulpweaver4/-/issues/138)) |
|
|
165
|
+
|
|
166
|
+
A misspelled key, or a stage written wrong, is an error naming the
|
|
167
|
+
plugin. `api: 1` is the plugin API’s version; a plugin for another version
|
|
168
|
+
is refused.
|
|
169
|
+
|
|
170
|
+
{#plugins-the-document}
|
|
171
|
+
### The document
|
|
172
|
+
|
|
173
|
+
A transform gets the book as its documents, `ast.documents`, each a tree of
|
|
174
|
+
nodes with a `type` (`section`, `heading`, `paragraph`, `text`...), `children`,
|
|
175
|
+
`attributes` and a `position` in the source. A block a plugin claims is a
|
|
176
|
+
`pluginBlock` node whose `name` is the block’s; an inline, a
|
|
177
|
+
`pluginInline`. `ctx.options` holds the plugin’s options, and
|
|
178
|
+
`ctx.error(node, code, message, fix)` and `ctx.warn(…)` report a problem
|
|
179
|
+
at a node, with a code of your own and, if you like, its fix.
|
|
180
|
+
|
|
181
|
+
{#rendering}
|
|
182
|
+
### Rendering
|
|
183
|
+
|
|
184
|
+
An `html` renderer gets the node, `h` (hastscript’s, so
|
|
185
|
+
`h('aside.note', { id: 'x' }, children)`) and `ctx`, whose
|
|
186
|
+
`ctx.render(children)` renders the node’s children and whose `ctx.edition`
|
|
187
|
+
says which edition it is for. A `text` renderer returns a string; its
|
|
188
|
+
second argument’s `children(node)` renders the children as text. A node with
|
|
189
|
+
no text renderer is written as its children.
|
|
190
|
+
|
|
191
|
+
{#line-breakers-assets-and-commands}
|
|
192
|
+
## Line breakers, assets and commands
|
|
193
|
+
|
|
194
|
+
These three work beyond the document: on the engine’s lines, on the
|
|
195
|
+
project’s files, and on the command line. A press’s plugin might have all
|
|
196
|
+
three, as this one does, with a module of its own beside it:
|
|
197
|
+
|
|
198
|
+
{project=press file="plugins/words.js"}
|
|
199
|
+
``` js
|
|
200
|
+
// plugins/words.js
|
|
201
|
+
/** The number of words in a text. */
|
|
202
|
+
export const countWords = (text) => text.split(/\s+/).filter(Boolean).length
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
{#line-breakers}
|
|
206
|
+
### Line breakers
|
|
207
|
+
|
|
208
|
+
A line breaker sets a paragraph’s lines in place of the core’s Knuth--Plass,
|
|
209
|
+
for the paragraphs a selector matches (`elements`) or those in a language
|
|
210
|
+
(`languages`, `ja` for `ja-JP` too), as a press might for a script the core
|
|
211
|
+
doesn’t break well. It is given the paragraph as the engine’s list of
|
|
212
|
+
boxes, glue and penalties and the line breaking options, and returns the
|
|
213
|
+
lines; `setLines`, from `pulpweaver4`, packs the breaks it chooses. This one
|
|
214
|
+
breaks after every word:
|
|
215
|
+
|
|
216
|
+
{project=press file="plugins/press.js"}
|
|
217
|
+
``` js
|
|
218
|
+
// plugins/press.js
|
|
219
|
+
import { setLines } from 'pulpweaver4'
|
|
220
|
+
import { countWords } from './words.js'
|
|
221
|
+
|
|
222
|
+
// Breaks after every word: at each glue that follows a box.
|
|
223
|
+
function wordALine(items, options) {
|
|
224
|
+
const breaks = items.flatMap((item, k) => (item.type === 'glue' && items[k - 1]?.type === 'box' ? [k] : []))
|
|
225
|
+
return setLines(items, breaks, options)
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export default {
|
|
229
|
+
name: 'press',
|
|
230
|
+
api: 1,
|
|
231
|
+
layout: { lineBreakers: { elements: { 'p.word-a-line': wordALine } } },
|
|
232
|
+
assets: {
|
|
233
|
+
svg: {
|
|
234
|
+
description: 'Takes out comments.',
|
|
235
|
+
process: (data) => new TextEncoder().encode(new TextDecoder().decode(data).replace(/<!--[^]*?-->/g, '')),
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
commands: {
|
|
239
|
+
words: {
|
|
240
|
+
description: 'Count the words in files of the project.',
|
|
241
|
+
usage: '<file>…',
|
|
242
|
+
async run(args, { fs, out }) {
|
|
243
|
+
if (!args.length || !fs) {
|
|
244
|
+
out('pw words: name a file of the project')
|
|
245
|
+
return 2
|
|
246
|
+
}
|
|
247
|
+
for (const file of args) out(`${file}: ${countWords(await fs.readText(file))} words`)
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
},
|
|
251
|
+
}
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
{project=press}
|
|
255
|
+
``` djot
|
|
256
|
+
{.word-a-line}
|
|
257
|
+
One word a line.
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
In print, the paragraph is four lines, “One”, “word”, “a”, “line.”. Two
|
|
261
|
+
breakers claiming one paragraph is an error, and so is one that throws: the
|
|
262
|
+
core breaks that paragraph instead. `--pw-line-breaking: browser` still
|
|
263
|
+
gives a paragraph the browser’s lines.
|
|
264
|
+
|
|
265
|
+
{#processing-images-and-fonts}
|
|
266
|
+
### Processing images and fonts
|
|
267
|
+
|
|
268
|
+
`assets` processes the project’s files of a type, by extension, for each
|
|
269
|
+
edition: the images print and the web edition use, and the fonts. The
|
|
270
|
+
plugin above takes the comments out of SVGs. Each file is processed once
|
|
271
|
+
per edition, whatever its name or however often the book uses it, and a
|
|
272
|
+
processor that throws leaves the file as it was, with an error naming the
|
|
273
|
+
plugin.
|
|
274
|
+
|
|
275
|
+
{project=press file="images/box.svg"}
|
|
276
|
+
``` svg
|
|
277
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="120" height="80" viewBox="0 0 120 80">
|
|
278
|
+
<!-- Drawn for the guide. -->
|
|
279
|
+
<rect x="10" y="10" width="100" height="60" fill="#3b5bdb"/>
|
|
280
|
+
</svg>
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
{project=press}
|
|
284
|
+
``` djot
|
|
285
|
+

|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
{project=press}
|
|
289
|
+
``` toml
|
|
290
|
+
[plugins]
|
|
291
|
+
"./plugins/press.js" = {}
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
{#commands}
|
|
295
|
+
### Commands
|
|
296
|
+
|
|
297
|
+
`commands` adds commands to `pw`, run in the project’s folder: `run` gets
|
|
298
|
+
the command’s arguments and a context with the project’s files (`fs`) and
|
|
299
|
+
`out`, to print a line, and returns the exit status. The plugin above adds
|
|
300
|
+
`pw words`:
|
|
301
|
+
|
|
302
|
+
{project=press}
|
|
303
|
+
``` sh
|
|
304
|
+
pw words chapters/01-beginning.dj
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
{project=press .output}
|
|
308
|
+
``` text
|
|
309
|
+
chapters/01-beginning.dj: 100 words
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
`pw --help`, in the project, lists it after pw’s own commands:
|
|
313
|
+
|
|
314
|
+
{project=press output="pw --help"}
|
|
315
|
+
``` text
|
|
316
|
+
...
|
|
317
|
+
The project's plugins' commands:
|
|
318
|
+
pw words <file>…
|
|
319
|
+
Count the words in files of the project. (press)
|
|
320
|
+
...
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
A plugin can’t take a name `pw` has, such as `build`; a command that throws
|
|
324
|
+
is an error naming the plugin, with exit status 1.
|
|
325
|
+
|
|
326
|
+
{#plugins-are-a-set}
|
|
327
|
+
## Plugins are a set
|
|
328
|
+
|
|
329
|
+
In LaTeX, swapping two `\usepackage` lines can change a book. In pulpweaver4,
|
|
330
|
+
a project’s plugins are a set, and their order in `pulpweaver4.toml` changes
|
|
331
|
+
nothing:
|
|
332
|
+
|
|
333
|
+
- *Each name has one owner.* A block, an inline, a renderer, a reader, an
|
|
334
|
+
output or a matcher belongs to one plugin; a second plugin claiming it is
|
|
335
|
+
an error naming both. Lint rules are named `<plugin>/<rule>`, so they
|
|
336
|
+
can’t collide.
|
|
337
|
+
- *Transforms in a phase all see the document as the phase before left
|
|
338
|
+
it*, and each may change only the nodes it owns (and add nodes, and its
|
|
339
|
+
own attributes). A plugin that needs another’s result in the same phase
|
|
340
|
+
says so: `after: ['pulpweaver4-scripture']`.
|
|
341
|
+
- *Each plugin’s CSS has its own layer*, scoped to what it renders.
|
|
342
|
+
|
|
343
|
+
{#builds-you-can-repeat}
|
|
344
|
+
## Builds you can repeat
|
|
345
|
+
|
|
346
|
+
A plugin runs without a clock: `Date` and `performance.now()` give the
|
|
347
|
+
book’s date (`date`, or `SOURCE_DATE_EPOCH`), and `Math.random()` is
|
|
348
|
+
seeded by the plugin and its stage, so the same book always builds the same. A
|
|
349
|
+
plugin that throws is named in the error, with its stage and the node it
|
|
350
|
+
was working on; its output for that node is left out, and the build goes on.
|
|
351
|
+
|
|
352
|
+
{#testing-a-plugin}
|
|
353
|
+
## Testing a plugin
|
|
354
|
+
|
|
355
|
+
`runPlugin(plugin, djot)` builds a little Djot with the plugin and returns
|
|
356
|
+
the [book](#testing), with the plugin’s matchers on `expect`. It
|
|
357
|
+
reads the stylesheets the plugin names by path beside its `url`, which is
|
|
358
|
+
why the note plugin gives `url: import.meta.url`; without it, the build
|
|
359
|
+
says to give it:
|
|
360
|
+
|
|
361
|
+
{project=note file="tests/note.test.ts"}
|
|
362
|
+
``` ts
|
|
363
|
+
// tests/note.test.ts
|
|
364
|
+
import { runPlugin } from 'pulpweaver4/test'
|
|
365
|
+
import note from '../plugins/note.js'
|
|
366
|
+
|
|
367
|
+
test('notes are numbered through the book', async () => {
|
|
368
|
+
const book = await runPlugin(note, '::: note\nOne.\n:::\n\n::: note\nTwo.\n:::\n')
|
|
369
|
+
const labels = [...book.html.querySelectorAll('.note-label')].map((b) => b.textContent)
|
|
370
|
+
expect(labels).toEqual(['Note 1', 'Note 2'])
|
|
371
|
+
})
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
`build()` builds the whole project as `pulpweaver4.toml` sets it out, with
|
|
375
|
+
its plugins, their options and their matchers:
|
|
376
|
+
|
|
377
|
+
{project=note file="tests/notes.test.ts"}
|
|
378
|
+
``` ts
|
|
379
|
+
import { build } from 'pulpweaver4/test'
|
|
380
|
+
|
|
381
|
+
const book = await build({ edition: 'paperback' })
|
|
382
|
+
|
|
383
|
+
test('the notes keep to one page', () => {
|
|
384
|
+
for (const note of book.ast.select('pluginBlock.note')) {
|
|
385
|
+
expect(book.pages.of(note)).toFitOnOnePage()
|
|
386
|
+
}
|
|
387
|
+
})
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
`pw test` runs both files, with the starter’s:
|
|
391
|
+
|
|
392
|
+
{project=note}
|
|
393
|
+
``` sh
|
|
394
|
+
pw test
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
{project=note .output}
|
|
398
|
+
``` text
|
|
399
|
+
...
|
|
400
|
+
Test Files 3 passed (3)
|
|
401
|
+
Tests 5 passed (5)
|
|
402
|
+
...
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
{#publishing-a-plugin}
|
|
406
|
+
## Publishing a plugin
|
|
407
|
+
|
|
408
|
+
A plugin for others is an npm package whose main module is the plugin, with
|
|
409
|
+
`pulpweaver4` as a peer dependency (`npm install --save-peer pulpweaver4`). Name it `pulpweaver4-<name>` so it is
|
|
410
|
+
easy to find. The core’s repository has a whole one, written as a press
|
|
411
|
+
would write it, with a block, an inline, a transform, renderers, styles,
|
|
412
|
+
layout, a lint rule and a matcher:
|
|
413
|
+
[`pulpweaver4-questions`](https://gitlab.com/inkylabs/pulpweaver4/-/tree/master/tests/plugins/pulpweaver4-questions).
|
|
414
|
+
|
|
415
|
+
{#plugins-not-yet}
|
|
416
|
+
## Not yet
|
|
417
|
+
|
|
418
|
+
- *Page-builder hooks, page templates, flows, insert classes* of a
|
|
419
|
+
plugin’s own
|
|
420
|
+
([#138](https://gitlab.com/inkylabs/pulpweaver4/-/issues/138)): plugins
|
|
421
|
+
can declare them, but the core doesn’t use them yet. A stylesheet’s
|
|
422
|
+
flows and page templates work ([Flows and page templates](#flows)).
|
|
423
|
+
- *A plugin declaring the capabilities it needs* (`needs: ['fs']`), so the
|
|
424
|
+
browser app can run it in a sandbox
|
|
425
|
+
([#71](https://gitlab.com/inkylabs/pulpweaver4/-/issues/71)).
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
``` =meta
|
|
2
|
+
description = 'Tests for a book with pw test — facts about its pages, lines, structure and citations, in TypeScript with describe, test and expect, and snapshots of pages, HTML and text.'
|
|
3
|
+
```
|
|
4
|
+
|
|
5
|
+
{#testing}
|
|
6
|
+
# Testing your book
|
|
7
|
+
|
|
8
|
+
A book has facts worth checking every time it is built: each chapter opens
|
|
9
|
+
on a right-hand page, no line runs into the margin, the title page looks as
|
|
10
|
+
it was approved, the introduction cites the source it should. pulpweaver4’s
|
|
11
|
+
tests check them, as a programmer’s tests check code. They are TypeScript
|
|
12
|
+
files with the `describe`, `test` and `expect` you may know from
|
|
13
|
+
[Vitest](https://vitest.dev) or Jest, and they can see everything the build
|
|
14
|
+
makes: the document’s structure, its HTML and its laid-out pages.
|
|
15
|
+
|
|
16
|
+
Tests check particular facts about this book. To hold every book to a
|
|
17
|
+
policy (no widows, no straight quotes), use [lint
|
|
18
|
+
rules](#lint-rules) instead.
|
|
19
|
+
|
|
20
|
+
{#running-the-tests}
|
|
21
|
+
## Running the tests
|
|
22
|
+
|
|
23
|
+
`pw new` makes `tests/book.test.ts`. `pw test` runs every
|
|
24
|
+
`tests/**/*.test.ts` in headless Chromium, the same browser `pw build` lays
|
|
25
|
+
pages out in:
|
|
26
|
+
|
|
27
|
+
{project=tests}
|
|
28
|
+
``` sh
|
|
29
|
+
pw test
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
{project=tests .output}
|
|
33
|
+
``` text
|
|
34
|
+
...
|
|
35
|
+
Test Files 1 passed (1)
|
|
36
|
+
Tests 3 passed (3)
|
|
37
|
+
...
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The tests need nothing installed in the project: `pulpweaver4` and
|
|
41
|
+
`pulpweaver4/test` are pw’s own, and `describe`, `test` and `expect` are
|
|
42
|
+
there without importing them. Starting the browser and building the book
|
|
43
|
+
take some seconds; the tests themselves are quick. The browser app and
|
|
44
|
+
`pw dev` run the same files in the page, with their *Run tests* button
|
|
45
|
+
([Watching as you write](#watching-as-you-write)).
|
|
46
|
+
|
|
47
|
+
To run some of the tests, give words from their files’ paths, as Vitest’s
|
|
48
|
+
filters are: `pw test chapters` runs `tests/chapters.test.ts`. A first
|
|
49
|
+
argument that is a project’s folder, one with `pulpweaver4.toml`, is the
|
|
50
|
+
project to test: `pw test my-book chapters`.
|
|
51
|
+
|
|
52
|
+
{project=tests}
|
|
53
|
+
``` sh
|
|
54
|
+
pw test book
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
{project=tests .output}
|
|
58
|
+
``` text
|
|
59
|
+
...
|
|
60
|
+
Test Files 1 passed (1)
|
|
61
|
+
Tests 3 passed (3)
|
|
62
|
+
...
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
{#building-the-book-in-a-test}
|
|
66
|
+
## Building the book in a test
|
|
67
|
+
|
|
68
|
+
`build()` builds the project as `pw build` does, without writing files,
|
|
69
|
+
and returns the `Book`:
|
|
70
|
+
|
|
71
|
+
{project=tests file="tests/chapters.test.ts"}
|
|
72
|
+
``` ts
|
|
73
|
+
import { build } from 'pulpweaver4/test'
|
|
74
|
+
|
|
75
|
+
const book = await build({ edition: 'paperback' })
|
|
76
|
+
|
|
77
|
+
test('each chapter opens on a right-hand page', () => {
|
|
78
|
+
for (const chapter of book.ast.select('document > section')) {
|
|
79
|
+
expect(book.pages.of(chapter).first).toBeRecto()
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
- *`edition`* is an edition’s name from `pulpweaver4.toml`. Without it,
|
|
85
|
+
`build()` builds the first PDF edition. A web edition has no pages, so
|
|
86
|
+
tests of pages need a print edition.
|
|
87
|
+
- *The project’s plugins* are loaded as `pw build` loads them, with their
|
|
88
|
+
options, so their blocks render and their matchers are on `expect`.
|
|
89
|
+
- *A problem in the book*, an unknown label say, makes `build()` throw,
|
|
90
|
+
with every problem listed as `pw build` lists them. `build({ edition: 'paperback', errors: 'keep' })` returns the book anyway, with its problems
|
|
91
|
+
in `book.problems`.
|
|
92
|
+
- *Lint rules:* `build()` runs the edition’s [lint rules](#lint-rules), as
|
|
93
|
+
`pw build` does. Their problems are in `book.problems`, with the rule’s
|
|
94
|
+
name as `rule`, and an error among them makes `build()` throw too ([Lint
|
|
95
|
+
in a test](#lint-in-a-test)). `build({ lint: false })` leaves them out.
|
|
96
|
+
- *Build once, at the top of the file*, and share the book between the
|
|
97
|
+
file’s tests: a build takes a moment.
|
|
98
|
+
|
|
99
|
+
{#what-a-test-can-see}
|
|
100
|
+
## What a test can see
|
|
101
|
+
|
|
102
|
+
{#testing-the-document}
|
|
103
|
+
### The document
|
|
104
|
+
|
|
105
|
+
`book.ast.select(selector)` finds nodes of the document, in order, with a
|
|
106
|
+
CSS-like selector over node types, classes and labels:
|
|
107
|
+
|
|
108
|
+
| Selector | Finds |
|
|
109
|
+
|----|----|
|
|
110
|
+
| `document > section` | Each chapter: a file’s top-level sections |
|
|
111
|
+
| `section#writing` | The section labelled `writing` |
|
|
112
|
+
| `section#writing > heading` | Its heading |
|
|
113
|
+
| `paragraph`, `blockQuote`, `table`, `footnote`, `citation` | Nodes of a type |
|
|
114
|
+
| `div.note` | `::: note` divs |
|
|
115
|
+
| `section paragraph` | Paragraphs anywhere in a section |
|
|
116
|
+
| `[lang]`, `[lang=de]` | Nodes with an attribute, or with that value |
|
|
117
|
+
|
|
118
|
+
The selectors are a part of CSS’s: types, classes (`.note`), labels
|
|
119
|
+
(`#intro`), attributes, the descendant and child (`>`) combinators, and
|
|
120
|
+
lists (`a, b`), but no pseudo-classes, and neither `+` nor `~`. A second
|
|
121
|
+
argument searches within a node: `book.ast.select('.note', chapter)`.
|
|
122
|
+
|
|
123
|
+
{#the-pages}
|
|
124
|
+
### The pages
|
|
125
|
+
|
|
126
|
+
`book.pages` are the laid-out pages:
|
|
127
|
+
|
|
128
|
+
- *`book.pages.at(3)`* is page 3, counting from 1; `at(-1)` is the last.
|
|
129
|
+
- *`book.pages.of(x)`* is the pages something is on: a node from
|
|
130
|
+
`ast.select`, a CSS selector over the HTML (`'blockquote'`), or an
|
|
131
|
+
element. Its `first` and `last` are pages, and `length` how many.
|
|
132
|
+
- *`book.pages.length`*, and `for (const page of book.pages)`.
|
|
133
|
+
|
|
134
|
+
Each page has its `number`, its `side` (`'recto'` or `'verso'`), its
|
|
135
|
+
`spread` (the pages that face each other), whether it is `blank`, and its
|
|
136
|
+
`lines`. Each line has its `text`, its `width` and `measure`, its adjustment
|
|
137
|
+
`ratio` and `badness` as TeX computes them, whether it is `overfull`, and
|
|
138
|
+
whether it ends `hyphenated`:
|
|
139
|
+
|
|
140
|
+
{project=tests file="tests/chapters.test.ts"}
|
|
141
|
+
``` ts
|
|
142
|
+
test('the paperback fits in 64 pages', () => {
|
|
143
|
+
expect(book.pages.length).toBeLessThanOrEqual(64)
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
test('no page ends with a hyphen', () => {
|
|
147
|
+
for (const page of book.pages) {
|
|
148
|
+
expect(page.lines.at(-1)?.hyphenated ?? false).toBe(false)
|
|
149
|
+
}
|
|
150
|
+
})
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
{#the-index}
|
|
154
|
+
### The index
|
|
155
|
+
|
|
156
|
+
`book.index('subject')` is the subject index, from the book’s [index
|
|
157
|
+
terms](#index-terms). Its `entry(term)`, a term
|
|
158
|
+
written as in the Djot, with `!` between levels, has the `pages` it is on
|
|
159
|
+
(none, if the book has no such term), its page `ranges`, and its `see` and
|
|
160
|
+
`seeAlso` references. With a term in the second chapter:
|
|
161
|
+
|
|
162
|
+
{project=tests}
|
|
163
|
+
``` djot
|
|
164
|
+
[Parachurch ministries amass sizable revenues]{index="Cru; parachurch!revenues"},
|
|
165
|
+
and [tithing]{.xi} is older still.
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
{project=tests file="tests/chapters.test.ts"}
|
|
169
|
+
``` ts
|
|
170
|
+
test('the index sends tithing to the second chapter', () => {
|
|
171
|
+
const tithing = book.index('subject').entry('tithing')
|
|
172
|
+
expect(tithing.pages).toEqual([book.pages.of('#writing').first])
|
|
173
|
+
})
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
{#the-rest}
|
|
177
|
+
### The rest
|
|
178
|
+
|
|
179
|
+
`book.html` is the book’s HTML before layout; `await book.text()` is the
|
|
180
|
+
book as the text edition writes it; `book.problems` is what the build
|
|
181
|
+
warned of.
|
|
182
|
+
|
|
183
|
+
{#matchers-for-books}
|
|
184
|
+
## Matchers for books
|
|
185
|
+
|
|
186
|
+
Besides Vitest’s own matchers, `expect` has these:
|
|
187
|
+
|
|
188
|
+
| Matcher | Checks |
|
|
189
|
+
|----|----|
|
|
190
|
+
| `expect(page).toBeRecto()` | A page is a right-hand page |
|
|
191
|
+
| `expect(book.pages.of(x)).toFitOnOnePage()` | Something isn’t broken across pages |
|
|
192
|
+
| `expect(book.pages.of(x)).toStartPage()` | Something begins at the top of a page |
|
|
193
|
+
| `expect(book).toHaveNoOverfullLines()` | No line is wider than its measure, in the book, a page or `pages.of(x)` |
|
|
194
|
+
| `expect(book).toCite('bauckham')` | The book, or its pages from `pages.of(x)`, cites a source |
|
|
195
|
+
| `await expect(page).toMatchPageSnapshot()` | A page looks as it did, pixel for pixel |
|
|
196
|
+
| `await expect(book).toMatchHtmlSnapshot()` | The HTML is as it was |
|
|
197
|
+
| `await expect(book).toMatchTextSnapshot()` | The text edition is as it was |
|
|
198
|
+
|
|
199
|
+
A failure says what it found:
|
|
200
|
+
|
|
201
|
+
{project=failing file="tests/book.test.ts" .replace}
|
|
202
|
+
``` ts
|
|
203
|
+
import { build } from 'pulpweaver4/test'
|
|
204
|
+
|
|
205
|
+
const book = await build({ edition: 'paperback' })
|
|
206
|
+
|
|
207
|
+
test('page 2 is a recto', () => {
|
|
208
|
+
expect(book.pages.at(2)).toBeRecto()
|
|
209
|
+
})
|
|
210
|
+
|
|
211
|
+
test('the quotation starts a page', () => {
|
|
212
|
+
expect(book.pages.of('blockquote')).toStartPage()
|
|
213
|
+
})
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
{project=failing}
|
|
217
|
+
``` sh
|
|
218
|
+
pw test
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
{project=failing .output}
|
|
222
|
+
``` text
|
|
223
|
+
...
|
|
224
|
+
Error: expected page 2 to be a recto, but it is a verso
|
|
225
|
+
...
|
|
226
|
+
Error: expected "blockquote" to start a page, but it begins partway down page 3
|
|
227
|
+
...
|
|
228
|
+
Test Files 1 failed (1)
|
|
229
|
+
Tests 2 failed (2)
|
|
230
|
+
...
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
{#snapshots}
|
|
234
|
+
## Snapshots
|
|
235
|
+
|
|
236
|
+
A snapshot matcher compares what the book makes with what it made before,
|
|
237
|
+
kept in `tests/__snapshots__/`, beside the test, one file per snapshot: a
|
|
238
|
+
PNG of a page, HTML or text. The first run writes them; look at them, and
|
|
239
|
+
commit them. After that, a page that changes fails its test, and a page
|
|
240
|
+
whose snapshot doesn’t match gets an `.actual.png` beside it to compare.
|
|
241
|
+
|
|
242
|
+
{project=tests file="tests/chapters.test.ts"}
|
|
243
|
+
``` ts
|
|
244
|
+
test('the title page is as approved', async () => {
|
|
245
|
+
await expect(book.pages.at(1)).toMatchPageSnapshot()
|
|
246
|
+
})
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
When a change is meant, `pw test --update` writes the snapshots anew. In CI
|
|
250
|
+
(with `CI` set), a missing snapshot fails instead of being written, so
|
|
251
|
+
write them before you commit:
|
|
252
|
+
|
|
253
|
+
{project=tests}
|
|
254
|
+
``` sh
|
|
255
|
+
pw test --update
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
{project=tests .output}
|
|
259
|
+
``` text
|
|
260
|
+
...
|
|
261
|
+
Test Files 2 passed (2)
|
|
262
|
+
Tests 8 passed (8)
|
|
263
|
+
...
|
|
264
|
+
```
|