mdutils.tools package¶
Submodules¶
mdutils.tools.tools module¶
-
class
mdutils.tools.tools.
Header
[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 Hanchors.
- Auto generate a table of contents.
- Create Tables.
- Bold, italics,
inline_code
text converters. - Align text to center.
- Add color to text.
-
choose_header
(level, title, style='atx')[source]¶ This method choose the style and the header level.
Examples: >>> from mdutils.tools.tools import Header >>> createHeaders = Header() >>> createHeaders.choose_header(level=1, title='New Header', style='atx') '\n# New Header\n'
>>> createHeaders.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.
Returns:
-
static
header_anchor
(text, link='')[source]¶ Creates an internal link of a defined Header level 1 or level 2 in the markdown file.
Giving a text string an text link you can create an internal link of already existing header. If the
link
string does not contain ‘#’, it will creates an automatic link of the type#title-1
.Parameters: - text (str) – it is the text that will be displayed.
- link (str) – it is the internal link.
Returns: '[text](#link)'
Return type: string
Example: [Title 1](#title-1)
-
class
mdutils.tools.tools.
TableOfContents
[source]¶ Bases:
object
-
create_table_of_contents
(array_of_title_contents, depth=1)[source]¶ This method can create a table of contents using an array of the different titles. The deep can be changed. Only accepts 1 or 2.
Parameters: - array_of_title_contents (list) – a string list with the different headers.
- depth (int) – allows to include Headers 1 and 2 or only Headers of level 1. Possibly values 1 or 2.
Returns: return a string ready to be written to a Markdown file.
Return type: str
-
-
class
mdutils.tools.tools.
TextUtils
[source]¶ Bases:
object
This class helps to create bold, italics and change color text.
-
static
bold
(text)[source]¶ Bold text converter.
Parameters: text (str) – a text string. Returns: a string like this example: '**text**'
Return type: str
-
static
center_text
(text)[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)[source]¶ Inline code text converter.
Parameters: text (str) – a text string. Returns: a string like this example: '`text`'
Return type: str
-
static
italics
(text)[source]¶ Italics text converter.
Parameters: text (str) – a text string. Returns: a string like this example: '_text_'
Return type: str
-
static
text_color
(text, color='black')[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, link='')[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
-
text_format
(text, bold_italics_code='', color='black', align='')[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.tools import TextUtils >>> textUtils = 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