mdutils.tools package¶
Submodules¶
mdutils.tools.Header module¶
-
class
mdutils.tools.Header.
AtxHeaderLevel
[source]¶ Bases:
enum.Enum
An enumeration.
-
HEADING
= 2¶
-
LEASTHEADING
= 6¶
-
MINORHEADING
= 5¶
-
SUBHEADING
= 3¶
-
SUBSUBHEADING
= 4¶
-
TITLE
= 1¶
-
-
class
mdutils.tools.Header.
Header
(level: int, title: str, style: mdutils.tools.Header.HeaderStyle, header_id: str = None)[source]¶ Bases:
object
Contain the main methods to define Headers on a Markdown file.
Features available: - Create Markdown Titles: atx and setext formats are available. - Create Header Anchors.
Example: >>> str(Header(level=1, title='New Header', style=HeaderStyle.ATX))
-
static
atx
(level: mdutils.tools.Header.AtxHeaderLevel, title: str, header_id: str = None) → str[source]¶ Return an atx-style header.
Parameters: - title – Text title.
- level – HeaderLevel enum member, e.g., TITLE, HEADING, SUBHEADING, etc.
- header_id – ID of the header for extended Markdown syntax (optional)
Returns: an atx-style header string
-
static
choose_header
(level: int, title: str, style: str = 'atx', header_id: str = '') → str[source]¶ This method choose the style and the header level.
Examples: >>> from mdutils.tools.Header import Header >>> Header.choose_header(level=1, title='New Header', style='atx') '\n# New Header\n'
>>> Header.choose_header(level=2, title='Another Header 1', style='setext') '\nAnother Header 1\n----------------\n'
Parameters: - level – Header Level, For Atx-style 1 til 6. For Setext-style 1 and 2 header levels.
- title – Header Title.
- style – Header Style atx or setext.
- header_id – ID of the header for extended Markdown syntax
Returns:
-
static
header_anchor
(text: str, link: str = None) → str[source]¶ Create an internal link to a defined header level in the markdown file.
Parameters: - text – Displayed text for the link.
- link – Internal link (optional). If not provided, it is generated based on the text.
Returns: a header anchor string
Examples:
- Using the default generated link based on the text:
>>> header_link = Header.header_anchor("Section 1") >>> print(header_link) [Section 1](#section-1)
- Providing a custom link:
>>> header_link = Header.header_anchor("Section 1", "custom-link") >>> print(header_link) [Section 1](#custom-link)
- Providing a link with an existing ‘#’ symbol:
>>> header_link = Header.header_anchor("Section 1", "#existing-link") >>> print(header_link) [Section 1](#existing-link)
-
static
mdutils.tools.Html module¶
-
class
mdutils.tools.Html.
Html
[source]¶ Bases:
object
-
classmethod
image
(path: str, size: str = None, align: str = None) → str[source]¶ Parameters: - path (str) –
- size (str) – (In px) for width write
'<int>'
, for height write'x<int>'
or width and height'<int>x<int>
. - align (str) – can be
'left'
,'center'
or'right'
.
Returns: html format
Return type: str
Example: >>> Html.image(path='../image.jpg', size='200', align='center') >>> Html.image(path='../image.jpg', size='x200', align='left') >>> Html.image(path='../image.jpg', size='300x400')
-
classmethod
mdutils.tools.Image module¶
-
class
mdutils.tools.Image.
Image
(reference: mdutils.tools.Link.Reference)[source]¶ Bases:
object
-
static
new_inline_image
(text: str, path: str, tooltip: str = None) → str[source]¶ Parameters: - text (str) – Text that is going to be displayed in the markdown file as a iamge.
- path (str) – Image’s path / link.
- tooltip (str) –
Returns: return the image in markdown format
'![ + text + '](' + path + 'tooltip' + ')'
.Return type: str
-
new_reference_image
(text: str, path: str, reference_tag: str = None, tooltip: str = None) → str[source]¶ Parameters: - text (str) – Text that is going to be displayed in the markdown file as a image.
- path (str) – Image’s path / link.
- reference_tag (str) – Tag that will be placed at the end of the markdown file jointly with the image’s path.
- tooltip (str) –
Returns: return the image in markdown format
'![ + text + '][' + reference_tag + ']'
.Return type: str
-
static
mdutils.tools.Link module¶
-
class
mdutils.tools.Link.
Inline
[source]¶ Bases:
object
-
static
new_link
(link: str, text: str = None, tooltip: str = None)[source]¶ Parameters: - link (str) –
- text (str) – Text that is going to be displayed in the markdown file as a link.
- tooltip (str) – Add a tool tip on the image.
Returns: '[' + text +'](' + link + 'tooltip' + ')'
or if link is only defined:`<` + link '>'
.Return type: str
-
static
-
class
mdutils.tools.Link.
Reference
[source]¶ Bases:
object
-
new_link
(link: str, text: str, reference_tag: str = None, tooltip: str = None) → str[source]¶ Parameters: - link (str) –
- text (str) – Text that is going to be displayed in the markdown file as a link.
- reference_tag (str) – Reference that will be saved on reference dict.
- tooltip (str) – Add a tooltip on the link.
Returns: '[' + text + '][' + reference_tag + ']'
or if reference_Tag is not defined:'[' + text + ']'
.Return type: str
-
mdutils.tools.MDList module¶
-
class
mdutils.tools.MDList.
MDCheckbox
(items, checked: bool = False)[source]¶ Bases:
mdutils.tools.MDList.MDListHelper
This class allows to create checkbox MarkDown list.
-
class
mdutils.tools.MDList.
MDList
(items, marked_with: str = '-')[source]¶ Bases:
mdutils.tools.MDList.MDListHelper
This class allows to create unordered or ordered MarkDown list.
mdutils.tools.Table module¶
-
class
mdutils.tools.Table.
Table
[source]¶ Bases:
object
-
create_table
(columns: int, rows: int, text: List[str], text_align: Union[str, list, None] = None)[source]¶ This method takes a list of strings and creates a table.
Using argumentscolumns
androws
allows to create a table of n columns and m rows. Thecolumns * rows
operations has to correspond to the number of elements oftext
list argument.Parameters: - columns (int) – number of columns of the table.
- rows (int) – number of rows of the table.
- text (list of str) – a list of strings.
- text_align (str_or_list) – text align argument.
Values available are:
'right'
,'center'
,'left'
andNone
(default). If text_align is a list then individual alignment can be set for each column.
Returns: a markdown table.
Return type: str
Example: >>> from mdutils.tools.Table import Table >>> text_list = ['List of Items', 'Description', 'Result', 'Item 1', 'Description of item 1', '10', 'Item 2', 'Description of item 2', '0'] >>> table = Table().create_table(columns=3, rows=3, text=text_list, text_align='center') >>> print(repr(table)) '\n|List of Items|Description|Result|\n| :---: | :---: | :---: |\n|Item 1|Description of item 1|10|\n|Item 2|Description of item 2|0|\n'
¶ List of Items Description Results Item 1 Description of Item 1 10 Item 2 Description of Item 2 0
-
mdutils.tools.TableOfContents module¶
-
class
mdutils.tools.TableOfContents.
TableOfContents
[source]¶ Bases:
object
-
create_table_of_contents
(array_of_title_contents: List[str], depth: int = 1) → str[source]¶ This method can create a table of contents using an array of the different titles. The depth can be changed. :param array_of_title_contents: a string list with the different headers. :type array_of_title_contents: list :param depth: allows to include atx headers 1 through 6. Possible values: 1, 2, 3, 4, 5, or 6. :type depth: int :return: return a string ready to be written to a Markdown file. :rtype: str
-
mdutils.tools.TextUtils module¶
-
class
mdutils.tools.TextUtils.
TextUtils
[source]¶ Bases:
object
This class helps to create bold, italics and change color text.
-
static
add_tooltip
(link: str, tip: str) → str[source]¶ Parameters: - link (str) –
- tip (str) –
return:
link + "'" + format + "'"
-
static
bold
(text: str) → str[source]¶ Bold text converter.
Parameters: text (str) – a text string. Returns: a string like this example: '**text**'
Return type: str
-
static
center_text
(text: str) → str[source]¶ Place a text string to center.
Parameters: text (str) – a text string. Returns: a string like this exampple: '<center>text</center>'
-
static
inline_code
(text: str) → str[source]¶ Inline code text converter.
Parameters: text (str) – a text string. Returns: a string like this example: '``text
’``Return type: str
-
static
insert_code
(code: str, language: str = '') → str[source]¶ This method allows to insert a peace of code.
Parameters: code – code string. :type code:str :param language: code language: python. c++, c#… :type language: str :return: markdown style. :rtype: str
-
static
italics
(text: str) → str[source]¶ Italics text converter.
Parameters: text (str) – a text string. Returns: a string like this example: '_text_'
Return type: str
-
static
text_color
(text: str, color: str = 'black') → str[source]¶ Change text color.
Parameters: - text (str) – it is the text that will be changed its color.
- color (str) – it is the text color:
'orange'
,'blue'
,'red'
… or a RGB color such as'#ffce00'
.
Returns: a string like this one:
'<font color='color'>'text'</font>'
Return type: str
-
static
text_external_link
(text: str, link: str = '') → str[source]¶ Using this method can be created an external link of a file or a web page.
Parameters: - text (str) – Text to be displayed.
- link (str) – External Link.
Returns: return a string like this:
'[Text to be shown](https://write.link.com)'
Return type: str
-
static
text_format
(text: str, bold_italics_code: str = '', color: str = 'black', align: str = '') → str[source]¶ Text format helps to write multiple text format such as bold, italics and color.
Parameters: - text (str) – it is a string in which will be added the mew format
- bold_italics_code (str) – using ‘b’: bold, ‘i’: _italics_ and ‘c’: inline_code.
- color (str) – Can change text color. For example: ‘red’, ‘green, ‘orange’…
- align (str) – Using this parameter you can align text.
Returns: return a string with the new text format.
Return type: str
Example: >>> from mdutils.tools.TextUtils import TextUtils >>> TextUtils.text_format(text='Some Text Here', bold_italics_code='bi', color='red', align='center') '***<center><font color="red">Some Text Here</font></center>***'
-
static