annals.references#

The references of documents, extracted and combined, in three forms.

A document’s references are the body of its references section: a markdown heading named “References”, “Sources”, “Bibliography”, “Works cited” or “Citations” (any level, any case), down to the next heading of the same or a higher level. Three forms, each text in, text out:

  • grouped (the default): one ### section per document holding its references as they are, under ## References for <title>;

  • deduped: every entry once, its citation number removed, as one bulleted list;

  • urls: every web address once, one per line and nothing else, the form a notebook (Gemini Notebook, formerly NotebookLM) accepts as pasted website sources.

>>> doc = '''# Bees
... Text [1].
... ## REFERENCES
... 1. [Hive life](https://bees.org/hive). 2024.
... [2] Smith J. Pollen, <https://pollen.net/a>
... ## Appendix
... not a reference https://no.org
... '''
>>> reference_sections(doc)
['1. [Hive life](https://bees.org/hive). 2024.\n[2] Smith J. Pollen, <https://pollen.net/a>']
>>> [strip_citation_number(e) for e in reference_entries(reference_sections(doc)[0])]
['[Hive life](https://bees.org/hive). 2024.', 'Smith J. Pollen, <https://pollen.net/a>']
>>> print(combine_references([("Bees", [doc]), ("Wasps", ["no references here"])],
...                          title="Insects", form="urls"), end="")
https://bees.org/hive
https://pollen.net/a

The mechanism knows nothing of the store: doc_reference_texts() is the bridge that reads a set of documents through a read(doc_id, rel) callable, so the owner’s API and, later, a share can use it alike.

Module Attributes

REFERENCE_HEADINGS

section names that hold references (a heading's text starts with one of them)

Functions

collect(docs, *, read, title[, form])

The references of docs (their meta) in form, with the counts the page shows.

combine_references(items, *, title[, form])

items (a title and the texts of its pages) as their references in form.

doc_reference_texts(docs, *, read[, skip])

(title, texts) for each of docs ((meta, files) pairs): its markdown pages' text.

reference_entries(section)

The entries of a references section: each numbered or bulleted item, with its wrapped lines.

reference_sections(text)

The body of each references section of a markdown text, as written (blank edges trimmed).

strip_citation_number(entry)

entry without its leading number or bullet (1., [1], -).

url_key(url)

What makes two addresses the same page: no fragment, no trailing slash, host in lowercase.

urls_of(text)

The web addresses in text, in order of appearance, each once as written.

annals.references.REFERENCE_HEADINGS = ('references', 'sources', 'bibliography', 'works cited', 'citations')#

section names that hold references (a heading’s text starts with one of them)

annals.references.collect(docs, *, read, title, form='grouped')[source]#

The references of docs (their meta) in form, with the counts the page shows.

{text, items, without, count}: items documents had references, without had none, count lines of references (grouped: entries; the others: output lines or addresses). text is empty when none had any. Every surface (the HTTP route, annals references, MCP) reads references through here.

Return type:

dict

annals.references.combine_references(items, *, title, form='grouped')[source]#

items (a title and the texts of its pages) as their references in form.

Items with no references section are left out. An empty string means none had any.

Return type:

str

annals.references.doc_reference_texts(docs, *, read, skip=(<class 'KeyError'>, <class 'OSError'>, <class 'ValueError'>))[source]#

(title, texts) for each of docs ((meta, files) pairs): its markdown pages’ text.

Pages come in numbered_first() order; a page read cannot read (one of skip) is left out.

Return type:

Iterator[tuple[str, list[str]]]

annals.references.reference_entries(section)[source]#

The entries of a references section: each numbered or bulleted item, with its wrapped lines.

Prose that is not an item (an “Accessed on …” note) is not an entry. A section with no list markers at all is one entry per non-blank line.

Return type:

list[str]

annals.references.reference_sections(text)[source]#

The body of each references section of a markdown text, as written (blank edges trimmed).

Return type:

list[str]

annals.references.strip_citation_number(entry)[source]#

entry without its leading number or bullet (1., [1], -).

Return type:

str

annals.references.url_key(url)[source]#

What makes two addresses the same page: no fragment, no trailing slash, host in lowercase.

Return type:

str

annals.references.urls_of(text)[source]#

The web addresses in text, in order of appearance, each once as written.

Return type:

list[str]