### Create Markdown File with mdutils Source: https://github.com/didix21/mdutils/blob/master/doc/source/examples/Example_Markdown.md Initializes the Mdutils library and creates a new Markdown file with a specified name and title. The `create_md_file()` method must be called last to finalize the file generation. ```python import Mdutils mdFile = Mdutils(file_name='Example_Markdown',title='Markdown File Example') mdFile.create_md_file() ``` -------------------------------- ### Create Markdown Table using new_table Method Source: https://github.com/didix21/mdutils/blob/master/doc/source/examples/Example_Markdown.md The `new_table` method generates markdown tables. It requires the number of columns and rows, and optionally accepts a list of strings for table content and a `text_align` parameter to align the content within the cells. An example demonstrates creating a table with 3 columns and 6 rows, populated with sample data. ```python list_of_strings = ["Items", "Descriptions", "Data"] for x in range(5): list_of_strings.extend(["Item " + str(x), "Description Item " + str(x), str(x)]) mdFile.new_line() mdFile.new_table(columns=3, rows=6, text=list_of_strings, text_align='center') ``` -------------------------------- ### Create Reference Link - Python Source: https://github.com/didix21/mdutils/blob/master/doc/source/examples/Example_Python.md Generates a markdown reference link. It takes a URL, display text, and a reference tag. Optional arguments allow for styling the link text as bold, italics, or code. ```python mdFile.insert_code("[1]: https://github.com/didix21/mdutils", language="python") mdFile.write('\n - Reference link: ' + mdFile.new_reference_link(link='https://github.com/didix21/mdutils', text='mdutils', reference_tag='1') + '\n - Reference link: ' + mdFile.new_reference_link(link='https://github.com/didix21/mdutils', text='another reference', reference_tag='md') + '\n - Bold link: ' + mdFile.new_reference_link(link='https://github.com/didix21/mdutils', text='Bold reference', reference_tag='bold', bold_italics_code='b') + '\n - Italics link: ' + mdFile.new_reference_link(link='https://github.com/didix21/mdutils', text='Italics reference', reference_tag='italics', bold_italics_code='i')) ``` -------------------------------- ### Create Headers using mdutils (Atx and Setext) Source: https://github.com/didix21/mdutils/blob/master/doc/source/examples/Example_Markdown.md Demonstrates the creation of Markdown headers using the `new_header` method. It supports 'atx' style with levels 1-6 and 'setext' style with levels 1-2. Atx levels 1 and 2 are automatically added to the table of contents by default. ```python mdFile.new_header(level=1, title='Atx Header 1') mdFile.new_header(level=2, title='Atx Header 2') mdFile.new_header(level=3, title='Atx Header 3') mdFile.new_header(level=4, title='Atx Header 4') mdFile.new_header(level=5, title='Atx Header 5') mdFile.new_header(level=6, title='Atx Header 6') ``` ```python mdFile.new_header(level=1, title='Setext Header 1', style='setext') mdFile.new_header(level=2, title='Setext Header 2', style='setext') ``` -------------------------------- ### Resize HTML Images using mdutils Source: https://github.com/didix21/mdutils/blob/master/doc/source/examples/Example_Python.md Explains how to resize images in markdown files using the `Html.image` method. This method allows specifying image dimensions for width, height, or both. The output is an HTML image tag. ```python path = "./doc/source/images/sunset.jpg" mdFile.new_paragraph("With ``Html.image`` you can change size of images in a markdown file. For example you can do" "the following for changing width: ``mdFile.new_paragraph(Html.image(path=path, size='200'))``") mdFile.new_paragraph(Html.image(path=path, size='200')) mdFile.new_paragraph( "Or maybe only want to change height: ``mdFile.new_paragraph(Html.image(path=path, size='x300'))``") mdFile.new_paragraph(Html.image(path=path, size='x300')) mdFile.new_paragraph("Or change width and height: ``mdFile.new_paragraph(Html.image(path=path, size='300x300'))``") mdFile.new_paragraph(Html.image(path=path, size='300x300')) mdFile.write('\n') ``` -------------------------------- ### Create Table of Contents with mdutils Source: https://github.com/didix21/mdutils/blob/master/doc/source/examples/Example_Markdown.md Generates a table of contents for the Markdown file. This method should typically be called before `create_md_file()`. It supports specifying the table title and the depth of headers to include. ```python mdFile.new_table_of_contents(table_title='Contents', depth=2) ``` -------------------------------- ### Insert Reference Image using mdutils Source: https://github.com/didix21/mdutils/blob/master/doc/source/examples/Example_Python.md Demonstrates how to insert inline images using the `new_reference_image` method in mdutils. The method returns a formatted string that can be inserted into a markdown file. It requires text, path, and an optional reference tag. ```python mdFile.new_header(3, "Reference Images") mdFile.new_paragraph("You can add inline images using ``new_reference_image`` method. Method will return: " "``[image][im]``. Check the following example: ") mdFile.insert_code( "mdFile.new_line(mdFile.new_reference_image(text='{}', path='{}', reference_tag='im'))".format(image_text, path)) mdFile.new_line(mdFile.new_reference_image(text=image_text, path=path, reference_tag='im')) ``` -------------------------------- ### Install mdutils using Pip Source: https://github.com/didix21/mdutils/blob/master/doc/source/README.md This snippet shows the command to install the mdutils package using pip, the standard package installer for Python. Ensure you have pip installed and accessible in your environment. ```bash pip install mdutils ``` -------------------------------- ### Create Inline Markdown Links in Python Source: https://github.com/didix21/mdutils/blob/master/doc/source/examples/Example_Python.md Creates markdown inline links with optional text formatting (bold, italics, code). Requires a URL and optionally link text and formatting style. The output is a formatted markdown link string. ```python link = "https://github.com/didix21/mdutils" text = "mdutils" mdFile.new_line(' - Inline link: ' + mdFile.new_inline_link(link=link, text=text)) mdFile.new_line(' - Bold inline link: ' + mdFile.new_inline_link(link=link, text=text, bold_italics_code='b')) mdFile.new_line(' - Italics inline link: ' + mdFile.new_inline_link(link=link, text=text, bold_italics_code='i')) mdFile.new_line(' - Code inline link: ' + mdFile.new_inline_link(link=link, text=text, bold_italics_code='c')) mdFile.new_line( ' - Bold italics code inline link: ' + mdFile.new_inline_link(link=link, text=text, bold_italics_code='cbi')) mdFile.new_line(' - Another inline link: ' + mdFile.new_inline_link(link=link)) ``` -------------------------------- ### Install mdutils with Pip Source: https://github.com/didix21/mdutils/blob/master/README.md Installs the mdutils Python package using pip. This is the standard method for installing Python packages. ```bash $ pip install mdutils ``` -------------------------------- ### Create Inline Image - Python Source: https://github.com/didix21/mdutils/blob/master/doc/source/examples/Example_Python.md Generates an inline markdown image link. It takes alternative text for the image and its path. The output format is `[alt text](../path/to/image.png)`. ```python mdFile.new_line(mdFile.new_inline_image(text='snow trees', path='./doc/source/images/photo-of-snow-covered-trees.jpg')) ``` -------------------------------- ### Create Unordered List - Python Source: https://github.com/didix21/mdutils/blob/master/doc/source/examples/Example_Python.md Creates an unordered markdown list from a list of items. Nested lists are supported. By default, items are marked with a hyphen. ```python items = ["Item 1", "Item 2", "Item 3", "Item 4", ["Item 4.1", "Item 4.2", ["Item 4.2.1", "Item 4.2.2"], "Item 4.3", ["Item 4.3.1"]], "Item 5"] mdFile.new_list(items) ``` -------------------------------- ### Align HTML Images using mdutils Source: https://github.com/didix21/mdutils/blob/master/doc/source/examples/Example_Python.md Details how to align images within markdown using the `Html.image` method. This capability is demonstrated by providing an 'align' parameter along with size and path to the `Html.image` function. ```python mdFile.new_header(3, "Align images") mdFile.new_paragraph("Html.image allow to align images, too. For example you can run: " "``mdFile.new_paragraph(Html.image(path=path, size='300x200', align='center'))``") mdFile.new_paragraph(Html.image(path=path, size='300x200', align='center')) ``` -------------------------------- ### Insert Code Snippets into Markdown with Python Source: https://github.com/didix21/mdutils/blob/master/doc/source/examples/Example_Python.md Shows how to insert code blocks into a Markdown file using the insert_code method from mdutils. This method takes the code string and its language as arguments. It's useful for documenting code examples within the generated Markdown. ```python mdFile.insert_code("import Mdutils\n\n\nmdFile = Mdutils(file_name='Example_Markdown',title='Markdown File Example')\nmdFile.create_md_file()", language='python') ``` -------------------------------- ### Create Paragraphs and Format Text with mdutils Source: https://github.com/didix21/mdutils/blob/master/doc/source/examples/Example_Markdown.md Adds new paragraphs to the Markdown file using the `new_paragraph` method. This method also allows for text formatting, including bold, italics, code styling, and color. ```python mdFile.new_paragraph("Using ``new_paragraph`` method you can very easily add a new paragraph" " This example of paragraph has been added using this method. Moreover," "``new_paragraph`` method make your live easy because it can give format" " to the text. Lets see an example:") ``` ```python mdFile.new_paragraph("This is an example of text in which has been added color, bold and italics text.", bold_italics_code='bi', color='purple') ``` -------------------------------- ### Install mdutils using Poetry Source: https://github.com/didix21/mdutils/blob/master/doc/source/README.md This snippet demonstrates how to add the mdutils package as a dependency to your project using Poetry, a dependency management tool for Python. This command integrates mdutils into your project's dependency graph managed by Poetry. ```bash poetry add mdutils ``` -------------------------------- ### Create Ordered List - Python Source: https://github.com/didix21/mdutils/blob/master/doc/source/examples/Example_Python.md Creates an ordered markdown list from a list of items. Nested lists are supported. The `marked_with` parameter can be set to '1' for numbered lists or other characters like '+' or '*' for custom bullet points. ```python items = ["Item 1", "Item 2", ["1. Item 2.1", "2. Item 2.2"], "Item 3"] mdFile.new_list(items) mdFile.new_list(items, marked_with='*') ``` -------------------------------- ### Python: Create New Line with mdutils Source: https://github.com/didix21/mdutils/blob/master/doc/source/examples/Example_Python.md Shows how to insert line breaks in a markdown file using the `new_line` method. This method also allows for text formatting including bold, italics, and alignment. ```python mdFile.new_line("This is an example of line break which has been created with ``new_line`` method.") ``` ```python mdFile.new_line("This is an inline code which contains bold and italics text and it is centered", bold_italics_code='cib', align='center') ``` -------------------------------- ### Python: Create New Paragraph with mdutils Source: https://github.com/didix21/mdutils/blob/master/doc/source/examples/Example_Python.md Demonstrates creating new paragraphs in a markdown file using the `new_paragraph` method. It supports adding plain text or text with specified formatting (bold, italics, color). ```python mdFile.new_paragraph("Using ``new_paragraph`` method you can very easily add a new paragraph" " This example of paragraph has been added using this method. Moreover," "``new_paragraph`` method make your live easy because it can give format" " to the text. Lets see an example:") ``` ```python mdFile.new_paragraph("This is an example of text in which has been added color, bold and italics text.", bold_italics_code='bi', color='purple') ``` -------------------------------- ### Write Text with Formatting using write Method Source: https://github.com/didix21/mdutils/blob/master/doc/source/examples/Example_Markdown.md The `write` method allows writing text to markdown files with various formatting options. It supports markdown directives like bold, italics, and inline code, as well as parameters for bold-italics-code formatting, text color, and text alignment. This method does not automatically add newlines. ```python mdFile.write("The following text has been written with ``write`` method. You can use markdown directives to write:" ``` ```python "**bold**, _italics_, ``inline_code``... or ") mdFile.write("use the following available parameters: \n") ``` ```python mdFile.write(' \n') mdFile.write('bold_italics_code', bold_italics_code='bic') mdFile.write(' \n') mdFile.write('Text color', color='green') mdFile.write(' \n') mdFile.write('Align Text to center', align='center') ``` -------------------------------- ### Tools - Header Module Source: https://github.com/didix21/mdutils/blob/master/doc/source/mdutils.md Functions and classes for creating markdown headers using ATX and Setext styles. ```APIDOC ## Header Module ### Description This module provides tools for generating markdown headers in both ATX and Setext styles, including options for different heading levels and anchor generation. ### Classes #### `Header` ##### Methods * **`atx(level, text)`**: Creates an ATX-style markdown header. * `level` (int): The header level (e.g., 1 for #, 2 for ##). * `text` (str): The header text. * Returns: str - The markdown formatted header. * **`choose_header(style, level, text)`**: Creates a markdown header based on the specified style and level. * `style` (HeaderStyle): The style of the header (ATX or SETEXT). * `level` (int): The header level. * `text` (str): The header text. * Returns: str - The markdown formatted header. * **`header_anchor(text)`**: Generates a markdown-compatible anchor link for a given header text. * `text` (str): The header text. * Returns: str - The anchor link. * **`setext(level, text)`**: Creates a Setext-style markdown header. * `level` (int): The header level (e.g., 1 for TITLE, 2 for HEADING). * `text` (str): The header text. * Returns: str - The markdown formatted header. #### `AtxHeaderLevel` Enum for ATX header levels. * `TITLE` * `HEADING` * `SUBHEADING` * `MINORHEADING` * `SUBSUBHEADING` * `LEASTHEADING` #### `SetextHeaderLevel` Enum for Setext header levels. * `TITLE` * `HEADING` #### `HeaderStyle` Enum for header styles. * `ATX` * `SETEXT` ``` -------------------------------- ### Create External Link Source: https://github.com/didix21/mdutils/blob/master/doc/source/mdutils.tools.md Creates a Markdown-formatted external link, combining display text with a URL. ```python from mdutils.tools.TextUtils import TextUtils text_to_display = 'Visit Example' link_url = 'https://example.com' external_link = TextUtils.text_external_link(text=text_to_display, link=link_url) print(external_link) ``` -------------------------------- ### Link Creation Source: https://github.com/didix21/mdutils/blob/master/doc/source/mdutils.tools.md Functions for creating inline and reference-style markdown links. ```APIDOC ## POST /didix21/mdutils/tools/Link/Inline/new_link ### Description Creates an inline markdown link with optional text and tooltip. ### Method POST ### Endpoint /didix21/mdutils/tools/Link/Inline/new_link ### Parameters #### Query Parameters - **link** (str) - Required - The URL for the link. - **text** (str) - Optional - The text to display for the link. If not provided, the link itself might be used or an empty string. - **tooltip** (str) - Optional - Tooltip text for the link. ### Request Body ```json { "link": "https://example.com", "text": "Example Link", "tooltip": "Visit Example.com" } ``` ### Response #### Success Response (200) - **markdown_link** (str) - The markdown string representing the inline link. #### Response Example ```json { "markdown_link": "[Example Link](https://example.com "Visit Example.com")" } ``` ``` ```APIDOC ## POST /didix21/mdutils/tools/Link/Reference/new_link ### Description Creates a reference-style markdown link, storing the reference for later use. ### Method POST ### Endpoint /didix21/mdutils/tools/Link/Reference/new_link ### Parameters #### Query Parameters - **link** (str) - Required - The URL for the link. - **text** (str) - Required - The text to display for the link. - **reference_tag** (str) - Optional - A unique tag to identify this reference. If not provided, one may be generated. - **tooltip** (str) - Optional - Tooltip text for the link. ### Request Body ```json { "link": "https://example.com", "text": "Example Reference Link", "reference_tag": "ref-example", "tooltip": "A reference link" } ``` ### Response #### Success Response (200) - **markdown_link** (str) - The markdown string representing the reference-style link. #### Response Example ```json { "markdown_link": "[Example Reference Link][ref-example]" } ``` ``` ```APIDOC ## GET /didix21/mdutils/tools/Link/Reference/get_references ### Description Retrieves all stored link references as a dictionary. ### Method GET ### Endpoint /didix21/mdutils/tools/Link/Reference/get_references ### Response #### Success Response (200) - **references** (dict) - A dictionary where keys are reference tags and values are the corresponding URLs. #### Response Example ```json { "references": { "ref-example": "https://example.com" } } ``` ``` ```APIDOC ## GET /didix21/mdutils/tools/Link/Reference/get_references_as_markdown ### Description Retrieves all stored link references formatted as markdown. ### Method GET ### Endpoint /didix21/mdutils/tools/Link/Reference/get_references_as_markdown ### Response #### Success Response (200) - **markdown_references** (str) - A string containing all references in markdown format. #### Response Example ```json { "markdown_references": "[ref-example]: https://example.com" } ``` ``` -------------------------------- ### Create Inline Markdown Link Source: https://github.com/didix21/mdutils/blob/master/doc/source/mdutils.tools.md Creates an inline Markdown link. It accepts the URL, optional display text, and an optional tooltip. If only the link is provided, it returns the link enclosed in angle brackets. Otherwise, it returns a formatted Markdown link. ```python from mdutils.tools.Link import Inline inline_link = Inline.new_link(link='https://www.example.com', text='Example Website', tooltip='Visit Example') print(inline_link) # Link only link_only = Inline.new_link(link='https://www.example.com') print(link_only) ``` -------------------------------- ### Tools - Link Module Source: https://github.com/didix21/mdutils/blob/master/doc/source/mdutils.md Utilities for creating markdown links, both inline and reference styles. ```APIDOC ## Link Module ### Description This module provides functionalities for creating markdown links, supporting both inline and reference link formats. ### Classes #### `Inline` ##### Methods * **`new_link(text, url)`**: Creates a markdown link with inline syntax. * `text` (str): The link text. * `url` (str): The URL the link points to. * Returns: str - The markdown formatted inline link. #### `Reference` ##### Methods * **`get_references(links)`**: Extracts reference definitions from a list of links. * `links` (list): A list of tuples, where each tuple is (text, url). * Returns: dict - A dictionary of reference definitions. * **`get_references_as_markdown(links)`**: Generates markdown formatted reference link definitions. * `links` (list): A list of tuples, where each tuple is (text, url). * Returns: str - The markdown formatted reference link definitions. * **`new_link(text, url, label)`**: Creates a markdown link with reference syntax. * `text` (str): The link text. * `url` (str): The URL the link points to. * `label` (str, optional): The label for the reference. If not provided, it's generated from the text. * Returns: str - The markdown formatted reference link. ``` -------------------------------- ### Create Inline Links with Formatting in Python Source: https://github.com/didix21/mdutils/blob/master/README.md Demonstrates how to create inline Markdown links using the new_inline_link method. Supports adding text formatting such as bold, italics, and code to the link text. The method takes a link URL, optional display text, and a flag for formatting. ```python mdFile.new_line(' - Inline link: ' + mdFile.new_inline_link(link='https://github.com/didix21/mdutils', text='mdutils')) mdFile.new_line(' - Bold inline link: ' + mdFile.new_inline_link(link='https://github.com/didix21/mdutils', text='mdutils', bold_italics_code='b')) mdFile.new_line(' - Italics inline link: ' + mdFile.new_inline_link(link='https://github.com/didix21/mdutils', text='mdutils', bold_italics_code='i')) mdFile.new_line(' - Code inline link: ' + mdFile.new_inline_link(link='https://github.com/didix21/mdutils', text='mdutils', bold_italics_code='c')) mdFile.new_line(' - Bold italics code inline link: ' + mdFile.new_inline_link(link='https://github.com/didix21/mdutils', text='mdutils', bold_italics_code='cbi')) mdFile.new_line(' - Another inline link: ' + mdFile.new_inline_link(link='https://github.com/didix21/mdutils')) ``` -------------------------------- ### Create Markdown Table with Columns and Rows Source: https://github.com/didix21/mdutils/blob/master/doc/source/mdutils.md Constructs a Markdown table using specified dimensions (columns and rows) and a list of text content for cells. It supports text alignment within cells and can place the table at a specific location using a marker. The total number of text elements must equal columns * rows. ```python def new_table(columns: int, rows: int, text: list[str], text_align: str | list | None = 'center', marker: str = '') -> str: """This method takes a list of strings and creates a table. > Using arguments `columns` and `rows` allows to create a table of *n* columns and *m* rows. The > `columns * rows` operations has to correspond to the number of elements of `text` list argument. > Moreover, `argument` allows to place the table wherever you want from the file. * **Parameters:** * **columns** (*int*) – this variable defines how many columns will have the table. * **rows** (*int*) – this variable defines how many rows will have the table. * **text** (*list*) – it is a list containing all the strings which will be placed in the table. * **text_align** (*str*) – allows to align all the cells to the `'right'`, `'left'` or `'center'`. By default: `'center'`. * **marker** (*str*) – using `create_marker` method can place the table anywhere of the markdown file. * **Returns:** can return the table created as a string. * **Return type:** str * **Example:** ```pycon >>> from mdutils import MdUtils >>> md = MdUtils(file_name='Example') >>> text_list = ['List of Items', 'Description', 'Result', 'Item 1', 'Description of item 1', '10', 'Item 2', 'Description of item 2', '0'] >>> table = md.new_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' ``` > #### **Table result on Markdown** > | List of Items | Description | Results | > |-----------------|-----------------------|-----------| > | Item 1 | Description of Item 1 | 10 | > | Item 2 | Description of Item 2 | 0 | """ pass ``` -------------------------------- ### Python: Write Text with mdutils Source: https://github.com/didix21/mdutils/blob/master/doc/source/examples/Example_Python.md Illustrates writing text to a markdown file without adding newlines using the `write` method. This method supports markdown directives and formatting arguments like color and alignment. ```python mdFile.write("The following text has been written with ``write`` method. You can use markdown directives to write:" "**bold**, _italics_, ``inline_code``... or ") mdFile.write("use the following available parameters: \n") ``` ```python mdFile.write(' \n') mdFile.write('bold_italics_code', bold_italics_code='bic') mdFile.write(' \n') mdFile.write('Text color', color='green') mdFile.write(' \n') mdFile.write('Align Text to center', align='center') ``` -------------------------------- ### Create Ordered Lists in Python Source: https://github.com/didix21/mdutils/blob/master/README.md Demonstrates how to create Markdown ordered lists using the new_list method with the '1' marked_with parameter. Supports nested ordered lists and mixed list types. The numbering restarts for each nesting level unless explicitly defined. ```python items = ['Item 1', 'Item 2', ['1. Item 2.1', '2. Item 2.2'], 'Item 3'] mdFile.new_list(items, marked_with='1') ``` -------------------------------- ### Table Creation Source: https://github.com/didix21/mdutils/blob/master/doc/source/mdutils.tools.md Function for generating markdown-formatted tables. ```APIDOC ## POST /didix21/mdutils/tools/Table/Table/create_table ### Description Creates a markdown-formatted table from a list of strings. ### Method POST ### Endpoint /didix21/mdutils/tools/Table/Table/create_table ### Parameters #### Request Body - **columns** (int) - Required - The number of columns in the table. - **rows** (int) - Required - The number of rows in the table. - **text** (List[str]) - Required - A flat list of strings containing the table cell content. The total number of elements must equal `columns * rows`. - **text_align** (str | list | None) - Optional - Default `None`. Specifies text alignment. Can be a single string ('left', 'center', 'right') or a list of strings for per-column alignment. ### Request Example ```json { "columns": 3, "rows": 3, "text": ["Header 1", "Header 2", "Header 3", "Row 1 Col 1", "Row 1 Col 2", "Row 1 Col 3", "Row 2 Col 1", "Row 2 Col 2", "Row 2 Col 3"], "text_align": "center" } ``` ### Response #### Success Response (200) - **markdown_table** (str) - The markdown string representing the generated table. #### Response Example ```json { "markdown_table": "\n|Header 1|Header 2|Header 3|\n| :---: | :---: | :---: |\n|Row 1 Col 1|Row 1 Col 2|Row 1 Col 3|\n|Row 2 Col 1|Row 2 Col 2|Row 2 Col 3|\n" } ``` ``` -------------------------------- ### Create Reference Links in Python Source: https://github.com/didix21/mdutils/blob/master/README.md Shows how to create Markdown reference links using the new_reference_link method. This method generates a link with a tag (e.g., [mdutils][1]) and automatically appends the corresponding reference definition at the end of the file. It also supports applying bold or italics to the link text. ```python mdFile.write('\n - Reference link: ' + mdFile.new_reference_link(link='https://github.com/didix21/mdutils', text='mdutils', reference_tag='1')) mdFile.write('\n - Reference link: ' + mdFile.new_reference_link(link='https://github.com/didix21/mdutils', text='another reference', reference_tag='md')) mdFile.write('\n - Bold link: ' + mdFile.new_reference_link(link='https://github.com/didix21/mdutils', text='Bold reference', reference_tag='bold', bold_italics_code='b')) mdFile.write('\n - Italics link: ' + mdFile.new_reference_link(link='https://github.com/didix21/mdutils', text='Italics reference', reference_tag='italics', bold_italics_code='i')) ``` -------------------------------- ### Create Inline Link Source: https://github.com/didix21/mdutils/blob/master/doc/source/mdutils.md Constructs an inline link in Markdown format. Accepts a URL and optional display text. Supports basic text formatting (bold, italics, code) and text alignment. If text is omitted, the URL itself is used. ```python from mdutils import MdUtils mdfile = MdUtils("Link_Example") print(mdfile.new_inline_link(link='https://example.com', text='Example Link', bold_italics_code='b')) print(mdfile.new_inline_link(link='https://example.com')) ``` -------------------------------- ### Create Headers in Markdown Source: https://github.com/didix21/mdutils/blob/master/README.md Shows how to create headers of different levels and styles using the new_header method in mdutils. It supports 'atx' style (levels 1-6) and 'setext' style (levels 1-2). Headers can optionally include an ID for extended Markdown syntax. ```python mdFile.new_header(level=1, title='Atx Header 1') mdFile.new_header(level=2, title='Atx Header 2') mdFile.new_header(level=3, title='Atx Header 3') mdFile.new_header(level=4, title='Atx Header 4') mdFile.new_header(level=5, title='Atx Header 5') mdFile.new_header(level=6, title='Atx Header 6') mdFile.new_header(level=1, title='Header', header_id='firstheader') mdFile.new_header(level=1, title='Setext Header 1', style='setext') mdFile.new_header(level=2, title='Setext Header 2', style='setext') ``` -------------------------------- ### Generate ATX Markdown Headers Source: https://github.com/didix21/mdutils/blob/master/doc/source/mdutils.tools.md Creates ATX-style Markdown headers. Supports different levels of headings (TITLE, HEADING, SUBHEADING, etc.) and optionally includes a header ID for extended Markdown syntax. Requires the Header and AtxHeaderLevel enums from mdutils.tools.Header. ```python from mdutils.tools.Header import Header, AtxHeaderLevel header_string = Header.atx(level=AtxHeaderLevel.HEADING, title='My Section', header_id='section-1') print(header_string) ``` -------------------------------- ### Create Line Breaks and Format Text with mdutils Source: https://github.com/didix21/mdutils/blob/master/doc/source/examples/Example_Markdown.md Inserts new line breaks into the Markdown file using the `new_line` method. Similar to `new_paragraph`, this method supports text formatting options such as bold, italics, code styling, and text alignment. ```python mdFile.new_line("This is an example of line break which has been created with ``new_line`` method.") ``` ```python mdFile.new_line("This is an inline code which contains bold and italics text and it is centered", bold_italics_code='cib', align='center') ``` -------------------------------- ### Create Markdown Table Source: https://github.com/didix21/mdutils/blob/master/doc/source/mdutils.tools.md Creates a Markdown table from a list of strings. Requires the number of columns, rows, and the list of text elements. An optional text alignment can be specified for columns. The method returns the formatted Markdown table string. ```python from mdutils.tools.Table import Table text_list = ['Header 1', 'Header 2', 'Data 1', 'Data 2', 'More Data 1', 'More Data 2'] table = Table().create_table(columns=2, rows=3, text=text_list, text_align='left') print(table) ``` -------------------------------- ### Insert Formatted Code Blocks in Markdown with mdutils Source: https://context7.com/didix21/mdutils/llms.txt Demonstrates how to insert code blocks with syntax highlighting into markdown using mdutils' TextUtils.insert_code. This function takes the code string and the programming language as input and returns a markdown-formatted code block. This is essential for presenting code examples clearly in documentation. ```python from mdutils import TextUtils code = """def hello(): print("Hello, World!")""" formatted_code = TextUtils.insert_code(code, language='python') print(formatted_code) ``` -------------------------------- ### Place Text Using Marker Source: https://github.com/didix21/mdutils/blob/master/doc/source/mdutils.md Replaces a previously created marker within the Markdown file content with a specified text string. ```APIDOC ## place_text_using_marker ### Description Replaces a given marker string in the file data with a new text string. This function is useful for inserting content at specific locations previously marked. ### Method N/A (This is a function within a library, not a direct API endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters * **text** (str) - Required - The new string that will replace the marker. * **marker** (str) - Required - The marker string that needs to be replaced. ### Returns * **str**: A new string representing the file data with the marker replaced. ### Request Example ```python from mdutils.mdutils import MdUtils mdFile = MdUtils(file_name='my_markdown', title='My Document') # Assume 'MY_MARKER' was previously placed in the file data mdFile.place_text_using_marker(text='This is the inserted content.', marker='MY_MARKER') ``` ### Response #### Success Response (N/A) N/A #### Response Example ```markdown # My Document This is the inserted content. ``` ``` -------------------------------- ### Image Handling Source: https://github.com/didix21/mdutils/blob/master/doc/source/mdutils.tools.md Functions for creating markdown-formatted image references. ```APIDOC ## POST /didix21/mdutils/new_reference_image ### Description Creates a markdown-formatted image reference with optional tooltip. ### Method POST ### Endpoint /didix21/mdutils/new_reference_image ### Parameters #### Query Parameters - **text** (str) - Required - Text to be displayed for the image. - **path** (str) - Required - The path or URL of the image. - **reference_tag** (str) - Optional - A tag to associate with the image reference. - **tooltip** (str) - Optional - Tooltip text for the image. ### Request Body ```json { "text": "Example Image Text", "path": "/path/to/image.png", "reference_tag": "img-ref-1", "tooltip": "This is a sample tooltip" } ``` ### Response #### Success Response (200) - **markdown_image** (str) - The markdown string representing the image reference. #### Response Example ```json { "markdown_image": "![Example Image Text][img-ref-1]" } ``` ``` -------------------------------- ### Tools - Image Module Source: https://github.com/didix21/mdutils/blob/master/doc/source/mdutils.md Functions for creating markdown image syntax. ```APIDOC ## Image Module ### Description This module provides methods for creating different types of markdown image syntax. ### Classes #### `Image` ##### Methods * **`new_inline_image(text, path)`**: Creates a markdown image with inline syntax. * `text` (str): The alt text for the image. * `path` (str): The URL or path to the image. * Returns: str - The markdown formatted inline image. * **`new_reference_image(text, path)`**: Creates a markdown image with reference syntax. * `text` (str): The alt text for the image. * `path` (str): The URL or path to the image. * Returns: str - The markdown formatted reference image. ``` -------------------------------- ### Create Reference Markdown Link Source: https://github.com/didix21/mdutils/blob/master/doc/source/mdutils.tools.md Generates a Markdown link using a reference style. It requires the link URL, display text, and a reference tag. An optional tooltip can also be provided. The function returns a Markdown link formatted using the reference tag. ```python from mdutils.tools.Link import Reference ref_link = Reference.new_link(link='https://www.example.com', text='Example Reference', reference_tag='ref1', tooltip='A reference link') print(ref_link) # Without reference tag ref_link_no_tag = Reference.new_link(link='https://www.example.com', text='Another Reference') print(ref_link_no_tag) ``` -------------------------------- ### Tools - Table Module Source: https://github.com/didix21/mdutils/blob/master/doc/source/mdutils.md Utilities for creating markdown tables. ```APIDOC ## Table Module ### Description This module provides functionalities for creating markdown tables. ### Classes #### `Table` ##### Methods * **`create_table(content, alignments)`**: Creates a markdown table from a list of lists. * `content` (list): A list of lists, where each inner list represents a row. * `alignments` (list): A list of strings specifying the alignment for each column ('left', 'right', 'center'). * Returns: str - The markdown formatted table. * **`create_table_array(content, alignments)`**: Similar to `create_table`, likely handles table creation from array-like structures. ``` -------------------------------- ### Generate Setext Markdown Headers Source: https://github.com/didix21/mdutils/blob/master/doc/source/mdutils.tools.md Creates Setext-style Markdown headers. Supports TITLE and HEADING levels. Requires the Header and SetextHeaderLevel enums from mdutils.tools.Header. ```python from mdutils.tools.Header import Header, SetextHeaderLevel header_string = Header.setext(level=SetextHeaderLevel.TITLE, title='My Document Title') print(header_string) ``` -------------------------------- ### Create Inline Images in Python Source: https://github.com/didix21/mdutils/blob/master/README.md Shows how to insert inline images into Markdown using the new_inline_image method. The method requires an image path and optional alt text, returning the Markdown string representation of an inline image. ```python mdFile.new_line(mdFile.new_inline_image(text='snow trees', path='./doc/source/images/photo-of-snow-covered-trees.jpg')) ``` -------------------------------- ### File Utilities - MarkDownFile Class Source: https://github.com/didix21/mdutils/blob/master/doc/source/mdutils.md Provides methods for reading, writing, and appending content to markdown files. ```APIDOC ## MarkDownFile Class ### Description This class handles operations on markdown files, including reading, rewriting, and appending content. ### Methods #### `append_after_second_line(self, filename, text)` Appends the given text after the second line of the specified markdown file. #### `append_end(self, filename, text)` Appends the given text to the end of the specified markdown file. #### `read_file(self, filename)` Reads the entire content of the specified markdown file. #### `rewrite_all_file(self, filename, content)` Rewrites the entire content of the specified markdown file with the provided content. ``` -------------------------------- ### Create Inline and Reference Links Source: https://context7.com/didix21/mdutils/llms.txt Illustrates the creation of both inline and reference-style Markdown links. Inline links are embedded directly within the text, while reference links are defined separately and referenced within the text, allowing for cleaner Markdown structure. Formatting like bold and italics can be applied to link text. ```python from mdutils.mdutils import MdUtils mdFile = MdUtils(file_name='LinksExample') # Create inline links mdFile.new_paragraph("Visit " + mdFile.new_inline_link(link='https://github.com', text='GitHub')) mdFile.new_paragraph("Check " + mdFile.new_inline_link(link='https://python.org', text='Python')) # Create inline link with bold text bold_link = mdFile.new_inline_link(link='https://example.com', text='Example', bold_italics_code='b') mdFile.new_line("See " + bold_link + " for details.") # Create inline link with italics italic_link = mdFile.new_inline_link(link='https://docs.python.org', text='documentation', bold_italics_code='i') mdFile.new_line("Read the " + italic_link + " carefully.") # Create reference links (automatically added to end of file) ref1 = mdFile.new_reference_link(link='https://github.com/didix21/mdutils', text='mdutils', reference_tag='md1') ref2 = mdFile.new_reference_link(link='https://daringfireball.net/projects/markdown/', text='Markdown Guide', reference_tag='mdguide') mdFile.new_paragraph("The " + ref1 + " package is great for Markdown generation.") mdFile.new_paragraph("Learn more from the " + ref2 + ".") # Reference link with formatting ref3 = mdFile.new_reference_link(link='https://example.com', text='Important Link', reference_tag='imp', bold_italics_code='b') mdFile.new_line(ref3) mdFile.create_md_file() ``` -------------------------------- ### Create Markdown Image Reference Source: https://github.com/didix21/mdutils/blob/master/doc/source/mdutils.tools.md Generates a Markdown image reference string. It takes the text to display, the image path, an optional reference tag, and an optional tooltip. The function returns the formatted Markdown string for an image. ```python from mdutils.tools.Image import Image image_markdown = Image.new_reference_image(text='Example Image', path='images/example.png', reference_tag='img1', tooltip='An example image') print(image_markdown) ``` -------------------------------- ### Table Creation API Source: https://github.com/didix21/mdutils/blob/master/doc/source/mdutils.md API for creating markdown tables from a list of strings or a list of lists. ```APIDOC ## POST /didix21/mdutils/new_table ### Description Creates a table in markdown format using a list of strings. ### Method POST ### Endpoint /didix21/mdutils/new_table ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **columns** (int) - Required - Defines the number of columns the table will have. - **rows** (int) - Required - Defines the number of rows the table will have. - **text** (List[str]) - Required - A list containing all the strings to be placed in the table. The length must be `columns * rows`. - **text_align** (str | List[str] | None) - Optional - Allows alignment of all cells to 'right', 'left', or 'center'. Can be a single string for all cells or a list of strings for each column. Defaults to 'center'. - **marker** (str) - Optional - A marker string to place the table at a specific location in the markdown file (requires `create_marker` method usage). ### Request Example ```json { "columns": 3, "rows": 3, "text": ["List of Items", "Description", "Result", "Item 1", "Description of item 1", "10", "Item 2", "Description of item 2", "0"], "text_align": "center" } ``` ### Response #### Success Response (200) - **table_markdown** (str) - The created table in markdown format. #### Response Example ```json { "table_markdown": "\n|List of Items|Description|Result|\n| :---: | :---: | :---: |\n|Item 1|Description of item 1|10|\n|Item 2|Description of item 2|0|\n" } ``` ## POST /didix21/mdutils/new_table_array ### Description Creates a table in markdown format from a list of lists. ### Method POST ### Endpoint /didix21/mdutils/new_table_array ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **data** (List[List[str]]) - Required - A list of lists, where each inner list represents a row in the table. - **text_align** (str | List[str] | None) - Optional - Allows alignment of all cells to 'right', 'left', or 'center'. Can be a single string for all cells or a list of strings for each column. - **marker** (str) - Optional - A marker string to place the table at a specific location in the markdown file (requires `create_marker` method usage). ### Request Example ```json { "data": [ ["Header 1", "Header 2"], ["Row 1 Col 1", "Row 1 Col 2"], ["Row 2 Col 1", "Row 2 Col 2"] ], "text_align": "left" } ``` ### Response #### Success Response (200) - **table_markdown** (str) - The created table in markdown format. #### Response Example ```json { "table_markdown": "\n|Header 1|Header 2|\n| :--- | :--- |\n|Row 1 Col 1|Row 1 Col 2|\n|Row 2 Col 1|Row 2 Col 2|\n" } ``` ``` -------------------------------- ### Tools - MDList Module Source: https://github.com/didix21/mdutils/blob/master/doc/source/mdutils.md Classes for generating markdown lists, including ordered, unordered, and task lists. ```APIDOC ## MDList Module ### Description This module provides classes for creating markdown lists, including support for checkboxes in task lists. ### Classes #### `MDCheckbox` ##### Methods * **`get_md(checked)`**: Generates the markdown string for a checkbox. * `checked` (bool): True if the checkbox should be checked, False otherwise. * Returns: str - The markdown string for the checkbox (e.g., '- [x]' or '- [ ]'). #### `MDList` ##### Methods * **`get_md(items, list_type='unordered')`**: Generates the markdown string for a list. * `items` (list): A list of list items. Each item can be a string or a nested list. * `list_type` (str, optional): The type of list ('unordered' or 'ordered'). Defaults to 'unordered'. * Returns: str - The markdown formatted list. #### `MDListHelper` Helper class for markdown list operations (specific methods not detailed here). ``` -------------------------------- ### Create Markdown Inline Image Source: https://github.com/didix21/mdutils/blob/master/doc/source/mdutils.tools.md Generates a Markdown formatted inline image. Requires the image text (alt text), path or URL, and an optional tooltip. Uses the Image class from mdutils.tools.Image. ```python from mdutils.tools.Image import Image inline_image = Image.new_inline_image(text='My Image', path='path/to/image.png', tooltip='This is a tooltip') print(inline_image) ```