annals.render#
Render markdown (and other page-like files) to html and PDF, with their images inside.
No web framework in here, so the CLI can use it as the server does. The PDF is made by
WeasyPrint from markdown-it’s HTML (raw html in the markdown is shown as text, never
interpreted). Images are embedded; audio, video, other PDFs and files become a visible link
to the resource, so the reader can open or play it. WeasyPrint is imported on first use; a
missing one is a annals.requirements.MissingDependency with the install hint.
Nothing is fetched from the network: an image outside the document is a link, never loaded.
Everything WeasyPrint is allowed to load is a placeholder url (annals-file:N) for bytes
this module already holds (Embedded).
Module Attributes
longest side of an embedded image; a 6000 px render is shrunk, a phone screenshot is not |
|
an image larger than this on disk is linked, not embedded |
|
an image with more pixels than this is not decoded to be shrunk (a small box would run out of memory) |
|
all embedded images of one PDF together |
|
markdown larger than this is not made into a PDF (rendering cost grows faster than size) |
Functions
|
A4 PDF of the html page |
|
|
|
|
|
The html body of the markdown |
|
A titled A4 PDF of the markdown |
|
A standalone html page: the |
|
The document file a relative |
Classes
|
The bytes a page may show, under placeholder urls, within a size budget. |
- class annals.render.Embedder(*, max_total=80000000)[source]#
Bases:
objectThe bytes a page may show, under placeholder urls, within a size budget.
WeasyPrint is only ever allowed to load these (
html_to_pdf()), and an html output gets them asdata:urls (inline_embedded()), so no render reaches the network or the disk on its own.
- annals.render.PDF_IMAGES_TOTAL_BYTES = 80000000#
all embedded images of one PDF together
- annals.render.PDF_IMAGE_MAX_BYTES = 25000000#
an image larger than this on disk is linked, not embedded
- annals.render.PDF_IMAGE_MAX_PIXELS = 40000000#
an image with more pixels than this is not decoded to be shrunk (a small box would run out of memory)
- annals.render.PDF_IMAGE_MAX_PX = 1800#
longest side of an embedded image; a 6000 px render is shrunk, a phone screenshot is not
- annals.render.PDF_MAX_TEXT_BYTES = 400000#
markdown larger than this is not made into a PDF (rendering cost grows faster than size)
- annals.render.html_to_pdf(doc, embedder)[source]#
A4 PDF of the html page
doc; the only things it may load areembedder’s.- Return type:
- annals.render.inline_embedded(body, embedder)[source]#
bodywith each placeholder url replaced by adata:url of its bytes.- Return type:
- annals.render.markdown_to_html(text, *, rel, files, open_file, file_url, embedder=None, read_bytes=None, list_unreferenced=True)[source]#
The html body of the markdown
text(the filerelof a document) and its images.Images the document holds are embedded (placeholder urls in the returned
Embedder); other files become links, shown as media rows; external images are never fetched. Raw html in the markdown is text, not markup.read_bytes(rel)reads an image the way the caller allows (a share filters svg text);list_unreferenced=Falseleaves out the “More in this document” rows (when the document’s other files are sections of a combined output of their own).
- annals.render.markdown_to_pdf(text, *, title, rel, files, open_file, file_url, created='')[source]#
A titled A4 PDF of the markdown
textwith its images inside (see the module doc).- Return type:
- annals.render.page_html(title, body, *, created='', css='', heading=True)[source]#
A standalone html page: the
titleas the document title, thenbody.cssstyles it on screen (a PDF brings its own); with it the page also gets a viewport, so a phone shows it at its own width.heading=Falseleaves the title out of the body (the text starts with its own).- Return type: