converters
Class info¶
Classes¶
| Name | Children | Inherits |
|---|---|---|
| Registry mkconvert._core Name -> backend class mapping, in order of preference. |
Re-exported classes¶
| Class | Module | Description |
|---|---|---|
| HtmdConverter | mkconvert.converters.htmd | htmd: fast Rust converter. |
| HtmlToMarkdownConverter | mkconvert.converters.base | Base class for HTML -> Markdown converters. |
| HtmlToMarkdownOptions | mkconvert.converters.base | Common HTML -> Markdown options, mapped onto every converter. |
| MarkdownifyConverter | mkconvert.converters.markdownify | markdownify: pure-Python converter on top of BeautifulSoup, highly configurable. |
🛈 DocStrings¶
HTML -> Markdown converters.
Importing this package does not import any converter library: each converter imports its library when instantiated.
registry
module-attribute
¶
registry: Registry[HtmlToMarkdownConverter] = Registry('HTML to Markdown converter')
Converters by name. Order is the preference when no converter is named.
HtmdConverter
¶
Bases: HtmlToMarkdownConverter
htmd: fast Rust converter.
Not supported: emphasis_marker="_".
Source code in src/mkconvert/converters/htmd.py
__init__
¶
__init__(
options: HtmlToMarkdownOptions | None = None,
*,
on_unsupported: OnUnsupported = "warn",
hr_style: Literal["dashes", "asterisks", "underscores"] = "dashes",
link_reference_style: Literal["full", "collapsed", "shortcut"] = "full",
preformatted_code: bool = False,
ul_bullet_spacing: int = 1,
ol_number_spacing: int = 1,
translation_mode: Literal["pure", "faithful"] = "pure",
) -> None
Create an htmd converter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
HtmlToMarkdownOptions | None
|
Common options. |
None
|
on_unsupported
|
OnUnsupported
|
See |
'warn'
|
hr_style
|
Literal['dashes', 'asterisks', 'underscores']
|
|
'dashes'
|
link_reference_style
|
Literal['full', 'collapsed', 'shortcut']
|
Reference link form (with |
'full'
|
preformatted_code
|
bool
|
Keep whitespace of inline |
False
|
ul_bullet_spacing
|
int
|
Spaces after a bullet list marker. |
1
|
ol_number_spacing
|
int
|
Spaces after an ordered list number. |
1
|
translation_mode
|
Literal['pure', 'faithful']
|
|
'pure'
|
Source code in src/mkconvert/converters/htmd.py
HtmlToMarkdownConverter
¶
Bases: Backend[HtmlToMarkdownOptions]
Base class for HTML -> Markdown converters.
Source code in src/mkconvert/converters/base.py
HtmlToMarkdownOptions
¶
Bases: Options
Common HTML -> Markdown options, mapped onto every converter.
Check HtmlToMarkdownConverter.supported_options for what a converter can change.
Source code in src/mkconvert/converters/base.py
bullet_marker
class-attribute
instance-attribute
¶
Marker for unordered list items.
code_block_style
class-attribute
instance-attribute
¶
Fenced or indented code blocks.
code_fence
class-attribute
instance-attribute
¶
Fence for fenced code blocks.
emphasis_marker
class-attribute
instance-attribute
¶
Marker for *emphasis* and **strong**.
heading_style
class-attribute
instance-attribute
¶
# Heading (atx) or underlined headings (setext, h1 / h2 only).
line_break
class-attribute
instance-attribute
¶
<br> as two trailing spaces or a trailing backslash.
link_style
class-attribute
instance-attribute
¶
[text](url) or [text][1] with the URLs collected at the end.
skip_tags
class-attribute
instance-attribute
¶
Tags to drop together with their content, e.g. ("script", "style").
MarkdownifyConverter
¶
Bases: HtmlToMarkdownConverter
markdownify: pure-Python converter on top of BeautifulSoup, highly configurable.
Not supported: code_block_style="indented", code_fence="~~~",
link_style="reference".
Source code in src/mkconvert/converters/markdownify.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
__init__
¶
__init__(
options: HtmlToMarkdownOptions | None = None,
*,
on_unsupported: OnUnsupported = "warn",
bullets: str | None = None,
strip: Sequence[str] | None = None,
convert: Sequence[str] | None = None,
autolinks: bool = True,
default_title: bool = False,
code_language: str = "",
code_language_callback: Callable[[Any], str | None] | None = None,
escape_asterisks: bool = True,
escape_underscores: bool = True,
escape_misc: bool = False,
sub_symbol: str = "",
sup_symbol: str = "",
table_infer_header: bool = False,
wrap: bool = False,
wrap_width: int = 80,
strip_document: Literal["strip", "lstrip", "rstrip"] | None = "strip",
) -> None
Create a markdownify converter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
HtmlToMarkdownOptions | None
|
Common options. |
None
|
on_unsupported
|
OnUnsupported
|
See |
'warn'
|
bullets
|
str | None
|
Bullet markers per nesting level, e.g. |
None
|
strip
|
Sequence[str] | None
|
Tags to drop while keeping their content. |
None
|
convert
|
Sequence[str] | None
|
Only convert these tags (keeping the text of all others). |
None
|
autolinks
|
bool
|
|
True
|
default_title
|
bool
|
Use the URL as title of links without one. |
False
|
code_language
|
str
|
Language for fenced code blocks. |
''
|
code_language_callback
|
Callable[[Any], str | None] | None
|
Derive the language from the |
None
|
escape_asterisks
|
bool
|
Escape |
True
|
escape_underscores
|
bool
|
Escape |
True
|
escape_misc
|
bool
|
Escape other Markdown characters in text. |
False
|
sub_symbol
|
str
|
Wrap |
''
|
sup_symbol
|
str
|
Wrap |
''
|
table_infer_header
|
bool
|
Use the first row as table header if there is no |
False
|
wrap
|
bool
|
Wrap paragraphs at |
False
|
wrap_width
|
int
|
Line width for |
80
|
strip_document
|
Literal['strip', 'lstrip', 'rstrip'] | None
|
Strip whitespace around the result. |
'strip'
|