annals.aggregate#
Many markdown files as ONE markdown document: a title, a table of contents, a section per file.
The mechanism is text in, text out. aggregate_markdown() takes (path, text) pairs
and knows nothing of documents, groups or shares; its choices are keyword arguments with
working defaults:
>>> print(aggregate_markdown(
... {"notes.md": "# Notes\nOne line\nwrapped.", "01-intro.md": "Hello."},
... title="Bundle"), end="")
# Bundle
**Contents**
- [01-intro.md](#01-intromd)
- [notes.md](#notesmd)
## 01-intro.md
Hello.
## notes.md
## Notes
One line wrapped.
order: how the files are arranged;numbered_first()by default (paths whose parts start with a number first, numerically, the rest in the order given),Nonekeeps the order given, or anypaths -> pathscallable.demote: how many levels each file’s own headings go down (1: a file’s#becomes##);0leaves them.unwrap: join hard-wrapped lines of a paragraph or list item into one line (unwrap_lines()); code, tables, quotes and html are left as they are.toc: the table of contents, as links to the sections’ GitHub-style anchors.
doc_markdown_files() is the bridge from annals documents: it yields the pairs for a
set of documents and the files of each a caller may read, through a read callable, so
the owner’s API, the share server (which reads filtered text) and the CLI share it.
Nothing is stored: the document is made per request.
Functions
|
One markdown document of |
|
|
|
|
|
The id GitHub (and most renderers) give a heading; |
|
|
|
|
|
The pairs with repeated paths told apart: |
|
|
Exceptions
The markdown to aggregate is over the size a caller allows. |
- exception annals.aggregate.TooLarge[source]#
Bases:
ValueErrorThe markdown to aggregate is over the size a caller allows.
- annals.aggregate.aggregate_markdown(files, *, title='', order=<function numbered_first>, demote=1, unwrap=True, toc=True, section_level=2)[source]#
One markdown document of
files({path: text}or(path, text)pairs).A
# title, a table of contents, then one section per file, headed by its path, with the file’s text below (front matter dropped, headingsdemote-d, lines unwrapped); see the module docstring for each choice.- Return type:
- annals.aggregate.demote_headings(text, levels=1, *, max_level=6)[source]#
textwith every headinglevelsdeeper (at mostmax_level); code untouched.Setext headings (a line underlined with
===or---) become#headings.>>> print(demote_headings("# A\nB\n---\n```\n# code\n```")) ## A ### B
# code- Return type:
- annals.aggregate.doc_markdown_files(docs, *, read, max_bytes=None, skip=(<class 'KeyError'>, <class 'OSError'>, <class 'ValueError'>))[source]#
(path, text)for every markdown file ofdocs((meta, files)pairs).filesare the files of that document the caller may read, andread(doc_id, rel)reads one (the share server passes its filtered reader). A document whose one markdown file is its page is named by that file; a folder, or a document with several markdown files, by its title then the file (Report/01-intro.md). A filereadcannot read (one ofskip) is left out; pastmax_bytesin all,TooLarge.
- annals.aggregate.heading_anchor(text, seen=None)[source]#
The id GitHub (and most renderers) give a heading;
seennumbers repeats.>>> seen = {} >>> heading_anchor("01-intro.md", seen), heading_anchor("01-intro.md", seen) ('01-intromd', '01-intromd-1')
- Return type:
- annals.aggregate.numbered_first(paths)[source]#
pathswith numbered ones first, compared part by part, the rest in their given order.A part (a folder or file name) that starts with digits sorts by that number, before any part that does not; parts without a number keep the order they first appeared in, so a folder’s files stay together.
>>> numbered_first(["b.md", "10-z.md", "a.md", "2-y.md", "r/02.md", "r/01.md"]) ['2-y.md', '10-z.md', 'b.md', 'a.md', 'r/01.md', 'r/02.md']
- annals.aggregate.strip_front_matter(text)[source]#
textwithout a leading YAML front-matter block (---…---).It must start with a
key:line, so a page that opens with a horizontal rule keeps it.>>> strip_front_matter("---\ntitle: x\n---\n# Body") '# Body' >>> strip_front_matter("---\nIntro\n---\nbody") '---\nIntro\n---\nbody'
- Return type:
- annals.aggregate.unique_paths(pairs)[source]#
The pairs with repeated paths told apart:
a.md,a.md (2).
- annals.aggregate.unwrap_lines(text)[source]#
textwith hard-wrapped paragraphs and list items joined into one line each.Only ordinary text lines are joined: headings, list markers, quotes, tables, html, fenced or indented code, and a line ending in a hard break (two spaces or
\) keep their line breaks.>>> print(unwrap_lines("A long\nsentence.\n\n- item\n goes on\n- next\n\n code\n more")) A long sentence. - item goes on - next code more
- Return type: