MDDocument
Handsdown API Index / Handsdown / MDDocument
Auto-generated documentation for handsdown.md_document module.
MDDocument
Show source in md_document.py:22
Markdown file builder.
Can be used as a context manager, on exit context is written to path
.
Examples
md_doc = MDDocument(path=Path('output.md'))
md_doc.append('## New section')
md_doc.append('some content')
md_doc.title = 'My doc'
md_doc.write()
# output is indented for readability
Path('output.md').read_text()
'''# My doc
- [My doc](#my-doc)
- [New section](#new-section)
## New section
some content
'''
with MDDocument(path=Path('output.md')) as md_document:
md_document.title = 'My doc'
md_doc.append_title('New section', level=2)
md_doc.append('New line')
Arguments
path
- Path to store document.
Signature
See also
MDDocument().append
Show source in md_document.py:309
Append content
to the document.
Handle trimming and sectioning the content and update MDDocument().title and MDDocument().toc_section fields.
Arguments
content
- Text to add.
Signature
MDDocument.get_anchor
Show source in md_document.py:127
Convert title to a GitHub-friendly anchor link.
Returns
A test of anchor link.
Signature
MDDocument().get_doc_link
Show source in md_document.py:220
Get Markdown link to a local MD document, use relative path as a link.
Arguments
- MDDocument().path - Path to local MDDocument
anchor
- Unescaped or escaped anchor tag
Returns
A string with Markdown link.
Signature
MDDocument.is_toc
Show source in md_document.py:139
Check if the section is Tree of Contents.
Returns
True the section is ToC.
Signature
MDDocument().path
Show source in md_document.py:302
Output path of the document.
Signature
MDDocument().read
Show source in md_document.py:93
Read and parse content from source_path
.
Arguments
source_path
- Input file path. If not provided - MDDocument().path is used.encoding
- File encoding.
Signature
MDDocument().render_doc_link
Show source in md_document.py:178
Render Markdown link to a local MD document, use relative path as a link.
Examples
md_doc = MDDocument(path='/root/parent/doc.md')
MDDocument.render_doc_link(
'my title',
anchor='my-anchor',
target_path=Path('/root/parent/doc.md'
)
'[my title](#my-anchor)'
MDDocument.render_doc_link('my title', target_path=Path('/root/parent/other.md'))
'[my title](other.md)'
MDDocument.render_doc_link('my title', anchor='my-anchor', target_path=Path('doc.md'))
'[my title](doc.md#my-anchor)'
MDDocument.render_doc_link('my title', anchor='my-anchor')
'[my title](#my-anchor)'
Arguments
- MDDocument().title - Link text.
anchor
- Unescaped or escaped anchor tag.target_path
- Target MDDocument path.
Returns
A string with Markdown link.
Signature
def render_doc_link(
self, title: str, anchor: str = "", target_path: Optional[Path] = None
) -> str:
...
MDDocument.render_link
Show source in md_document.py:156
Render Markdown link wih escaped title.
Examples
MDDocument.render_link('my title', 'doc.md#test')
'[my title](doc.md#test)'
MDDocument.render_link('MyClass.__init__', 'my.md')
'[MyClass.__init__](doc.md#my.md)'
Arguments
- MDDocument().title - Link text.
link
- Link target.
Returns
A string with Markdown link.
Signature
MDDocument().sections
Show source in md_document.py:295
All non-special sections
of the document.
Signature
MDDocument().source_file_name
Show source in md_document.py:86
Source cide file name.
Signature
MDDocument().subtitle
Show source in md_document.py:271
MDDocument subtitle or an empty string.
Signature
MDDocument().subtitle
Show source in md_document.py:278
Signature
MDDocument().title
Show source in md_document.py:259
MDDocument title or an empty string.
Signature
MDDocument().title
Show source in md_document.py:266
Signature
MDDocument().toc_section
Show source in md_document.py:283
Document Tree of Contents section or an empty line.
Signature
MDDocument().toc_section
Show source in md_document.py:290
Signature
MDDocument().write
Show source in md_document.py:251
Write MD content to MDDocument().path.