annals.notebook#
A share’s documents as separate notebook sources: one plain web page per text file.
A notebook product (NotebookLM, and Gemini’s notebooks, which share its sources) takes a
web page by its link, one source per link, and several links pasted at once; it reads
the page’s text and keeps its own copy. It does not unpack a zip, and its upload picker
needs the files on the device first. So the fewest taps from an iPad is: tick the
documents, copy one list of links, paste it into the notebook (see
misc/docs/notebook-sources.md for the research behind this).
The links are a share’s (annals.share): unguessable, scoped to the documents
ticked, expiring, revocable, and filtered like every shared text. This module only
decides what becomes a source and how one looks:
GET <share link>/source/<doc id>/<file> a script-free html page: <title>, the text
source_files(): which files of a document are sources (markdown and html pages, numbered files first, asannals.aggregate.numbered_first()orders them).notebook_sources(): the{doc, file, title, url}rows of a share, in its order.source_scope(): what a notebook share includes of a document: its source pages and the files they show, never the rest of a folder.render_source(): one markdown file as its source page (render_source_body()is the page’s body alone, which the share page embeds), shared-text rules applied twice: to the text (annals.share.filter_refs()), then to every link and image of the rendered page (annals.share.ref_decider()over markdown-it’s tokens), and any annals id left in it removed. Cached, and rendered only up toRENDER_MAX_BYTES(a larger file is sent as escaped text): it is a public route.source_page(): the page a notebook reads. Its<title>is the document’s title, which the notebook shows as the source’s name, so the sources can be told apart.markdown_html(): markdown to html;markdown-it-pywhen installed (thepdfextra), else the text escaped in a<pre>, which a notebook reads as well.
Module Attributes
the kinds of file a notebook can take from a link (images, audio, video and pdf it takes only as uploads) |
|
the path segment of a source page under a share link |
|
plain, readable, light or dark, no script and nothing loaded from elsewhere |
|
ones), nothing else; a sandbox (no origin, no script, no form) even so, since it is served beside the owner's app |
|
its own styles and images, no script, no request elsewhere |
|
rendering is superlinear on hostile input, and the route is public |
|
rendered source pages kept in memory (each at most a few times RENDER_MAX_BYTES) |
Functions
|
|
|
One row per source file of |
|
One markdown file of a share as its source page (see the module docstring). |
|
One markdown file of a share as safe html, links and images made absolute. |
|
The files of a document ( |
|
|
|
The page a notebook reads: a |
|
|
|
The source's name in the notebook: the document's title, plus the file if it has several. |
|
|
- annals.notebook.HTML_SOURCE_CSP = "sandbox; default-src 'none'; img-src 'self' data:; style-src 'self' 'unsafe-inline'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'"#
its own styles and images, no script, no request elsewhere
- Type:
an html source
- annals.notebook.RENDER_MAX_BYTES = 300000#
rendering is superlinear on hostile input, and the route is public
- Type:
markdown past this size is sent as escaped text, not rendered
- annals.notebook.SOURCE_CACHE_SIZE = 32#
rendered source pages kept in memory (each at most a few times RENDER_MAX_BYTES)
- annals.notebook.SOURCE_CSP = "sandbox; default-src 'none'; img-src 'self' data:; style-src 'unsafe-inline'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'"#
ones), nothing else; a sandbox (no origin, no script, no form) even so, since it is served beside the owner’s app
- Type:
what a source page may do
- Type:
show its own images (and data
- annals.notebook.SOURCE_CSS = ":root{color-scheme:light dark}body{font:17px/1.6 system-ui,-apple-system,'Segoe UI',sans-serif;max-width:46rem;margin:0 auto;padding:1.5rem 1rem 4rem}pre,code{font-family:ui-monospace,Menlo,monospace;font-size:.9em}pre{white-space:pre-wrap;overflow-wrap:anywhere}table{border-collapse:collapse}th,td{border:1px solid #8884;padding:.3em .6em}img{max-width:100%;height:auto}"#
plain, readable, light or dark, no script and nothing loaded from elsewhere
- Type:
a source page is read by a fetcher and, now and then, by a person
- annals.notebook.SOURCE_KINDS = ('md', 'html')#
the kinds of file a notebook can take from a link (images, audio, video and pdf it takes only as uploads)
- annals.notebook.SOURCE_SEGMENT = 'source'#
the path segment of a source page under a share link
- annals.notebook.markdown_html(text, *, rewrite_url=None, render=None)[source]#
text(markdown) as html; every link and image throughrewrite_url.render(text, rewrite_url)overrides the default renderer. Without one (nomarkdown-it-py) the text is escaped in a<pre>: no markup, so no link.- Return type:
- annals.notebook.notebook_sources(scope, *, link)[source]#
One row per source file of
scope((meta, files)pairs, in the share’s order).{"sources": [{"doc", "file", "title", "url"}], "skipped": [{"doc", "title", "kinds"}]};skippednames the documents with nothing a notebook can take from a link (only images, audio, pdf…), so the page can say why they are missing.- Return type:
- annals.notebook.render_source(text, *, title, **scope)[source]#
One markdown file of a share as its source page (see the module docstring).
scopeisrender_source_body()’s; the page adds the<title>.- Return type:
- annals.notebook.render_source_body(text, *, link, doc_id, rel, files, sources, shared_ids, root_id='', private_hosts=())[source]#
One markdown file of a share as safe html, links and images made absolute.
Every argument is hashable, so a body is rendered once per text and scope.
shared_idsare the annals ids the share includes (opened at<link>/d/<id>),root_idthe shared group’s (opened at<link>/).- Return type:
- annals.notebook.source_files(meta, files)[source]#
The files of a document (
files: those a caller may serve) that are sources.
- annals.notebook.source_link_rewriter(decide, *, link, doc_id, from_dir, sources)[source]#
url -> url | Nonefor a source page, which has no<base>.decide(annals.share.ref_decider()) says what may stay; a relative file it keeps becomes absolute here: another source page of the document links to that page, any other file to the share’s raw file. Anchors and web links stay as they are.
- annals.notebook.source_page(title, body_html)[source]#
The page a notebook reads: a
<title>, the body, plain style, no script.- Return type:
- annals.notebook.source_scope(read_text)[source]#
meta -> files: a document’s source pages and the files they show, for a share.read_text(doc_id, rel)reads one file. A notebook share made with this (thefiles_ofofannals.share.Shares.create()) reaches nothing else of a folder.