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
section names that hold references (a heading's text starts with one of them) |
Functions
|
The references of |
|
|
|
|
|
The entries of a references section: each numbered or bulleted item, with its wrapped lines. |
|
The body of each references section of a markdown text, as written (blank edges trimmed). |
|
|
|
What makes two addresses the same page: no fragment, no trailing slash, host in lowercase. |
|
The web addresses in |
- 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) inform, with the counts the page shows.{text, items, without, count}:itemsdocuments had references,withouthad none,countlines of references (grouped: entries; the others: output lines or addresses).textis empty when none had any. Every surface (the HTTP route,annals references, MCP) reads references through here.- Return type:
- annals.references.combine_references(items, *, title, form='grouped')[source]#
items(a title and the texts of its pages) as their references inform.Items with no references section are left out. An empty string means none had any.
- Return type:
- annals.references.doc_reference_texts(docs, *, read, skip=(<class 'KeyError'>, <class 'OSError'>, <class 'ValueError'>))[source]#
(title, texts)for each ofdocs((meta, files)pairs): its markdown pages’ text.Pages come in
numbered_first()order; a pagereadcannot read (one ofskip) is left out.
- 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.
- annals.references.reference_sections(text)[source]#
The body of each references section of a markdown text, as written (blank edges trimmed).
- annals.references.strip_citation_number(entry)[source]#
entrywithout its leading number or bullet (1.,[1],-).- Return type: