{"id":129504,"date":"2022-11-05T11:41:55","date_gmt":"2022-11-05T11:41:55","guid":{"rendered":"https:\/\/blog.finxter.com\/?p=860752"},"modified":"2022-11-05T11:41:55","modified_gmt":"2022-11-05T11:41:55","slug":"working-with-markdown-files-in-python","status":"publish","type":"post","link":"https:\/\/sickgaming.net\/blog\/2022\/11\/05\/working-with-markdown-files-in-python\/","title":{"rendered":"Working with Markdown Files in Python"},"content":{"rendered":"\n<div class=\"kk-star-ratings kksr-auto kksr-align-left kksr-valign-top\" data-payload=\"{&quot;align&quot;:&quot;left&quot;,&quot;id&quot;:&quot;860752&quot;,&quot;slug&quot;:&quot;default&quot;,&quot;valign&quot;:&quot;top&quot;,&quot;ignore&quot;:&quot;&quot;,&quot;reference&quot;:&quot;auto&quot;,&quot;class&quot;:&quot;&quot;,&quot;count&quot;:&quot;1&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;5&quot;,&quot;best&quot;:&quot;5&quot;,&quot;gap&quot;:&quot;5&quot;,&quot;greet&quot;:&quot;Rate this post&quot;,&quot;legend&quot;:&quot;5\\\/5 - (1 vote)&quot;,&quot;size&quot;:&quot;24&quot;,&quot;width&quot;:&quot;142.5&quot;,&quot;_legend&quot;:&quot;{score}\\\/{best} - ({count} {votes})&quot;,&quot;font_factor&quot;:&quot;1.25&quot;}\">\n<div class=\"kksr-stars\">\n<div class=\"kksr-stars-inactive\">\n<div class=\"kksr-star\" data-star=\"1\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"2\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"3\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"4\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"5\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div class=\"kksr-stars-active\" style=\"width: 142.5px;\">\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/div>\n<div class=\"kksr-legend\" style=\"font-size: 19.2px;\"> 5\/5 &#8211; (1 vote) <\/div>\n<\/div>\n<p class=\"wp-embed-aspect-16-9 wp-has-aspect-ratio\">This article will show you how to create and work with markdown files using Python.<\/p>\n<p class=\"has-base-background-color has-background\"><img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/14.0.0\/72x72\/1f4a1.png\" alt=\"\ud83d\udca1\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/> Markdown is an excellent tool with many features to spice up a flat-text file, such as changing text colors, adding bullet points, tables, and much more. A terrific way to add pizzazz to an otherwise dull file.<\/p>\n<p>To make it more interesting, we have the following running scenario:<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/as_logo.png\" alt=\"\" class=\"wp-image-862472\" width=\"401\" height=\"114\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/as_logo.png 411w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/as_logo-300x85.png 300w\" sizes=\"auto, (max-width: 401px) 100vw, 401px\" \/><\/figure>\n<\/div>\n<p class=\"wp-embed-aspect-16-9 wp-has-aspect-ratio\"><em>Acme Spinners, manufacturer of the Spinner Widgets, has contacted you to create a README.md file for their software. They would like you to format the flat-text file to make it easier to navigate and more professional. <\/em><\/p>\n<p>Each section of this article builds on the previous one. In the end, an entire <code>README.md<\/code> file will be created.<\/p>\n<hr class=\"wp-block-separator has-alpha-channel-opacity wp-embed-aspect-16-9 wp-has-aspect-ratio\"\/>\n<p class=\"wp-embed-aspect-16-9 wp-has-aspect-ratio has-global-color-8-background-color has-background\"><img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/14.0.0\/72x72\/1f4ac.png\" alt=\"\ud83d\udcac\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/> <strong>Question<\/strong>: How would we write code to create and populate an md file<em>?<\/em><\/p>\n<p class=\"wp-embed-aspect-16-9 wp-has-aspect-ratio\">We can accomplish this task by performing the following steps:<\/p>\n<ol type=\"video\" class=\"wp-embed-aspect-16-9 wp-has-aspect-ratio\">\n<li>Install Required Library<\/li>\n<li>Create a Python File<\/li>\n<li>Create a Markdown File<\/li>\n<li>Preview Markdown File<\/li>\n<li>Add Logo Image<\/li>\n<li>Add a Paragraph<\/li>\n<li>Add Heading<\/li>\n<li>Add Table<\/li>\n<li>Add Bullet Points<\/li>\n<li>Add Table of Contents<\/li>\n<\/ol>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n<h2>Install Required Library<\/h2>\n<p class=\"has-global-color-8-background-color has-background\">Before running the code in this article, the <a rel=\"noreferrer noopener\" href=\"https:\/\/pypi.org\/project\/mdutils\/\" data-type=\"URL\" data-id=\"https:\/\/pypi.org\/project\/mdutils\/\" target=\"_blank\"><code>mdutils<\/code><\/a> library must be installed.<\/p>\n<p>To install this library, navigate to the command prompt and run the following code.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">pip install mdutils<\/pre>\n<p>This library contains tools to assist in the creation of markdown files in Python, transforming a bland flat-text file into a fantastic-looking one!<\/p>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n<h2>Create Python File<\/h2>\n<p class=\"has-global-color-8-background-color has-background\">Let&#8217;s start by creating a Python file called <code>acme.py<\/code> and placing this file into the current working directory. <\/p>\n<p>In the IDE, navigate to and open <code>acme.py<\/code> and add the following lines.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"1-2\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from mdutils.mdutils import MdUtils\nfrom mdutils import Html<\/pre>\n<p>These lines allow access to and manipulation of markdown features.<\/p>\n<p>Save this file.<\/p>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n<h2>Create a Markdown File<\/h2>\n<p class=\"has-global-color-8-background-color has-background\">The next step is to create a markdown file. <\/p>\n<p>Open the <code>acme.py<\/code> file created earlier. At this point, this file should only contain two (2) lines of code.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from mdutils.mdutils import MdUtils\nfrom mdutils import Html<\/pre>\n<p>The following code snippet appends two (2) additional lines to <code>acme.py<\/code>.<\/p>\n<p>The first highlighted line calls the <a rel=\"noreferrer noopener\" href=\"https:\/\/pypi.org\/project\/mdutils\/\" data-type=\"URL\" data-id=\"https:\/\/pypi.org\/project\/mdutils\/\" target=\"_blank\"><code>Mdutils()<\/code><\/a> function and passes one (1) argument: a filename. This creates an object and saves it to <code>mdAcme<\/code>. If output to the terminal, an object similar to the one below would display.<\/p>\n<pre class=\"wp-block-preformatted\"><code>&lt;mdutils.mdutils.MdUtils object at 0x00000257FEB64940><\/code><\/pre>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"4,6\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from mdutils.mdutils import MdUtils\nfrom mdutils import Html mdAcme = MdUtils(file_name='acme') mdAcme.create_md_file()<\/pre>\n<p>The following line appends the <a rel=\"noreferrer noopener\" href=\"https:\/\/pypi.org\/project\/mdutils\/\" data-type=\"URL\" data-id=\"https:\/\/pypi.org\/project\/mdutils\/\" target=\"_blank\"><code>create_md_file()<\/code><\/a> function to the <code>mdAcme<\/code> object. When this code is run, the<code> acmd.md<\/code> file is created and saved to the current working directory.<\/p>\n<p>Typically, the above line is only called once all the file contents have been finalized. From hereon in, all additional code will be placed above this line.<\/p>\n<p>Save the <code>acme.py<\/code> file.<\/p>\n<p class=\"has-global-color-8-background-color has-background\"><img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/14.0.0\/72x72\/1f4a1.png\" alt=\"\ud83d\udca1\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/><strong>Note<\/strong>: A file extension is not required when passing a filename to the <a rel=\"noreferrer noopener\" href=\"https:\/\/pypi.org\/project\/mdutils\/\" data-type=\"URL\" data-id=\"https:\/\/pypi.org\/project\/mdutils\/\" target=\"_blank\"><code>Mdutils()<\/code><\/a> function. By default, <code>md <\/code>is assumed.<\/p>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n<h2>Preview a Markdown File<\/h2>\n<p class=\"has-global-color-8-background-color has-background\">During the progression of our markdown file, we can preview the file in our IDE. These instructions assume you are using the <a rel=\"noreferrer noopener\" href=\"https:\/\/code.visualstudio.com\/\" data-type=\"URL\" data-id=\"https:\/\/code.visualstudio.com\/\" target=\"_blank\">VSC<\/a> IDE.<\/p>\n<p>In the IDE, hover over the <code>acme.md<\/code> file and right-mouse click. This action displays a pop-up. <\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"290\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_11-1024x290.png\" alt=\"\" class=\"wp-image-863729\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_11-1024x290.png 1024w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_11-300x85.png 300w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_11-768x218.png 768w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_11.png 1151w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n<p>From this pop-up, select Open Preview (or <code>CTRL+SHIFT+V<\/code>). This action displays a preview of the <code>acme.md<\/code> file. At this point, there is no data to display.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"290\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_06-1024x290.png\" alt=\"\" class=\"wp-image-863696\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_06-1024x290.png 1024w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_06-300x85.png 300w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_06-768x217.png 768w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_06.png 1152w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n<p>No worries! We&#8217;ll fix this in the next sections!<\/p>\n<p class=\"has-global-color-8-background-color has-background\"><strong><img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/14.0.0\/72x72\/1f4a1.png\" alt=\"\ud83d\udca1\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/>Note<\/strong>: Depending on the IDE, the Preview option may differ.<\/p>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n<h2>Add Logo Image<\/h2>\n<p class=\"has-global-color-8-background-color has-background\">Let&#8217;s add a logo to the top of the Markdown file. Save the logo at the top of this article and place it in the current working directory.<\/p>\n<p>There are two (2) ways to add an image. <\/p>\n<p><strong>Option 1:<\/strong> Use <a rel=\"noreferrer noopener\" href=\"https:\/\/mdutils.readthedocs.io\/en\/latest\/mdutils.tools.html\" data-type=\"URL\" data-id=\"https:\/\/mdutils.readthedocs.io\/en\/latest\/mdutils.tools.html\" target=\"_blank\"><code>new_line()<\/code><\/a><\/p>\n<p>The highlighted line calls the <a rel=\"noreferrer noopener\" href=\"https:\/\/mdutils.readthedocs.io\/en\/latest\/mdutils.tools.html\" data-type=\"URL\" data-id=\"https:\/\/mdutils.readthedocs.io\/en\/latest\/mdutils.tools.html\" target=\"_blank\"><code>new_line()<\/code><\/a> function, which adds a new line to the file. Then, <a rel=\"noreferrer noopener\" href=\"https:\/\/mdutils.readthedocs.io\/en\/latest\/mdutils.tools.html\" data-type=\"URL\" data-id=\"https:\/\/mdutils.readthedocs.io\/en\/latest\/mdutils.tools.html\" target=\"_blank\"><code>new_inline_image()<\/code><\/a> is called and passed one (1) argument: path (the full path to the image). <\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"5\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from mdutils.mdutils import MdUtils\nfrom mdutils import Html mdAcme = MdUtils(file_name='acme')\nmdAcme.new_line(mdAcme.new_inline_image(path='as_logo.png')) mdAcme.create_md_file()<\/pre>\n<p>Update <code>acme.py<\/code>, save and run.<\/p>\n<p>If we preview <code>acme.md<\/code>, the logo displays on a new line (size: 411&#215;117) and is left-aligned.<\/p>\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"290\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_08-1024x290.png\" alt=\"\" class=\"wp-image-863707\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_08-1024x290.png 1024w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_08-300x85.png 300w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_08-768x217.png 768w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_08.png 1152w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<p><strong>Option 2:<\/strong><\/p>\n<p>To change the image size and\/or alignment, use the <a rel=\"noreferrer noopener\" href=\"https:\/\/mdutils.readthedocs.io\/en\/latest\/mdutils.tools.html\" data-type=\"URL\" data-id=\"https:\/\/mdutils.readthedocs.io\/en\/latest\/mdutils.tools.html\" target=\"_blank\"><code>Html. image()<\/code><\/a> function.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"5\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from mdutils.mdutils import MdUtils\nfrom mdutils import Html mdAcme = MdUtils(file_name='acme')\nmdAcme.new_paragraph(Html.image(path='as_logo.png', size='250', align='center')) mdAcme.create_md_file()<\/pre>\n<p>The highlighted line calls the <a rel=\"noreferrer noopener\" href=\"https:\/\/mdutils.readthedocs.io\/en\/latest\/mdutils.tools.html\" data-type=\"URL\" data-id=\"https:\/\/mdutils.readthedocs.io\/en\/latest\/mdutils.tools.html\" target=\"_blank\"><code>new_paragraph()<\/code><\/a> function, which adds a new line to the file. Then, <code><a rel=\"noreferrer noopener\" href=\"https:\/\/mdutils.readthedocs.io\/en\/latest\/mdutils.tools.html\" data-type=\"URL\" data-id=\"https:\/\/mdutils.readthedocs.io\/en\/latest\/mdutils.tools.html\" target=\"_blank\">Html_image()<\/a><\/code> is called and passed three (3) arguments: <code>path<\/code> (image location\/name), <code>size <\/code>(image size) and <code>align<\/code> (image alignment).<\/p>\n<p>Update <code>acme.py<\/code>, save and run.<\/p>\n<p>If we preview <code>acme. md<\/code>, the logo displays in its modified size and is center-aligned.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"290\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_07-1024x290.png\" alt=\"\" class=\"wp-image-863701\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_07-1024x290.png 1024w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_07-300x85.png 300w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_07-768x217.png 768w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_07.png 1152w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n<p>For this article, Option 2 is used.<\/p>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n<h2>Add a Paragraph<\/h2>\n<p class=\"has-global-color-8-background-color has-background\">Earlier, <a rel=\"noreferrer noopener\" href=\"https:\/\/mdutils.readthedocs.io\/en\/latest\/mdutils.tools.html\" data-type=\"URL\" data-id=\"https:\/\/mdutils.readthedocs.io\/en\/latest\/mdutils.tools.html\" target=\"_blank\"><code>new_paragraph()<\/code><\/a> was used to add a logo. However, we can also use this to add plain text. Let&#8217;s add a new paragraph.<\/p>\n<p>The highlighted line creates a new string. This string is formatted to bold, italics and is center-aligned.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"6\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from mdutils.mdutils import MdUtils\nfrom mdutils import Html mdAcme = MdUtils(file_name='acme')\nmdAcme.new_paragraph(Html.image(path='as_logo.png', size='250', align='center'))\nmdAcme.new_paragraph('License and Installation Instructions', bold_italics_code='bi', align='center') mdAcme.create_md_file()<\/pre>\n<p>Update <code>acme.py<\/code>, save and run.<\/p>\n<p>If we preview <code>acme.md<\/code>, the paragraph displays in bold italics and is center-aligned.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"290\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_09-1024x290.png\" alt=\"\" class=\"wp-image-863718\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_09-1024x290.png 1024w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_09-300x85.png 300w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_09-768x217.png 768w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_09.png 1152w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n<h2>Add Heading and Text<\/h2>\n<p class=\"has-global-color-8-background-color has-background\">A Level 1 Heading (<code>level=1<\/code>) called Overview and text is added.<\/p>\n<p>In the highlighted area below, an Overview section is created. <\/p>\n<p>This section shows how to use the <a rel=\"noreferrer noopener\" href=\"https:\/\/mdutils.readthedocs.io\/en\/latest\/mdutils.tools.html\" data-type=\"URL\" data-id=\"https:\/\/mdutils.readthedocs.io\/en\/latest\/mdutils.tools.html\" target=\"_blank\"><code>write()<\/code><\/a> and <a rel=\"noreferrer noopener\" href=\"https:\/\/mdutils.readthedocs.io\/en\/latest\/mdutils.tools.html\" data-type=\"URL\" data-id=\"https:\/\/mdutils.readthedocs.io\/en\/latest\/mdutils.tools.html\" target=\"_blank\"><code>new_paragraph()<\/code><\/a> functions to display text, change text colors and add hyperlinks.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"8-10\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from mdutils.mdutils import MdUtils\nfrom mdutils import Html mdAcme = MdUtils(file_name='acme')\nmdAcme.new_paragraph(Html.image(path='as_logo.png', size='250', align='center'))\nmdAcme.new_paragraph('License and Installation Instructions', bold_italics_code='bi', align='center') mdAcme.new_header(level=1, title='Overview')\nmdAcme.write(\"Welcome to &lt;font color='red'>Acme Spinners&lt;\/font>!\\n\\n\")\nmdAcme.new_paragraph(\"Visit our website at &lt;a href='#'>acmespinners.ca&lt;\/a> to view our videos on the latest spinner techniques.\\n\") mdAcme.create_md_file()<\/pre>\n<p>Update <code>acme.py<\/code>, save and run.<\/p>\n<p>If we preview <code>acme.md<\/code>, the Overview heading and text displays.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"422\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_201-1024x422.png\" alt=\"\" class=\"wp-image-865220\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_201-1024x422.png 1024w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_201-300x124.png 300w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_201-768x317.png 768w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_201.png 1036w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n<p>Let&#8217;s open <code>acme.md<\/code> to review the code when not in Preview Mode. <\/p>\n<p>Notice that the code in the <code>acme.py<\/code> file was converted to HTML.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"439\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_202-1024x439.png\" alt=\"\" class=\"wp-image-865228\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_202-1024x439.png 1024w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_202-300x129.png 300w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_202-768x329.png 768w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_202.png 1277w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n<p class=\"has-global-color-8-background-color has-background\"><img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/14.0.0\/72x72\/1f4a1.png\" alt=\"\ud83d\udca1\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/><strong>Note<\/strong>: If you are unfamiliar with HTML, click <a rel=\"noreferrer noopener\" href=\"https:\/\/www.w3schools.com\/html\/\" data-type=\"URL\" data-id=\"https:\/\/www.w3schools.com\/html\/\" target=\"_blank\">here<\/a> to learn more!<\/p>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n<h2>Add Table<\/h2>\n<p class=\"has-global-color-8-background-color has-background\">A Level 2 Heading (<code>level=2<\/code>) called License, and a table is added.<\/p>\n<p>In the highlighted area below, a License section was created. <\/p>\n<p>This section displays details about the license in a table format. This example adds a line for each entry. However, a loop could also be used to populate the table.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"12-18\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from mdutils.mdutils import MdUtils\nfrom mdutils import Html mdAcme = MdUtils(file_name='acme')\nmdAcme.new_paragraph(Html.image(path='as_logo.png', size='250', align='center'))\nmdAcme.new_paragraph('License and Installation Instructions', bold_italics_code='bi', align='center') mdAcme.new_header(level=1, title='Overview')\nmdAcme.write(\"Welcome to &lt;font color='red'>Acme Spinners&lt;\/font>!\\n\\n\")\nmdAcme.new_paragraph(\"Visit our website at &lt;a href='#'>acmespinners.ca&lt;\/a> to view our videos on the latest spinner techniques.\\n\") mdAcme.new_header(level=2, title='License')\ndata = [\"Item\", \"Description\"]\ndata.extend([\"License #\", \"ACS-3843-34-2217\"])\ndata.extend([\"Purchase Date\", \"Nov. 1, 2022\"])\ndata.extend([\"\", \"\"])\nmdAcme.new_table(columns=2, rows=4, text=data, text_align='left')\nmdAcme.new_line()<\/pre>\n<p>Update, save and run the <code>acme.py<\/code> file.<\/p>\n<p>If we preview <code>acme.md<\/code>, the following displays.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"636\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_203-1024x636.png\" alt=\"\" class=\"wp-image-865275\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_203-1024x636.png 1024w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_203-300x186.png 300w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_203-768x477.png 768w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_203.png 1027w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n<h2>Add Bullet Points<\/h2>\n<p class=\"has-global-color-8-background-color has-background\">A Level 3 Heading (<code>level=3<\/code>) called Instructions, and two (2) sets of bullet points are added.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"19-23\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from mdutils.mdutils import MdUtils\nfrom mdutils import Html mdAcme = MdUtils(file_name='acme')\nmdAcme.new_paragraph(Html.image(path='as_logo.png', size='250', align='center'))\nmdAcme.new_paragraph('License and Installation Instructions', bold_italics_code='bi', align='center') mdAcme.new_header(level=1, title='Overview')\nmdAcme.write(\"Welcome to &lt;font color='red'>Acme Spinners&lt;\/font>!\\n\\n\")\nmdAcme.new_paragraph(\"Visit our website at &lt;a href='#'>acmespinners.ca&lt;\/a> to view our videos on the latest spinner techniques.\\n\") mdAcme.new_header(level=2, title='License')\ndata = [\"Item\", \"Description\"]\ndata.extend([\"License #\", \"ACS-3843-34-2217\"])\ndata.extend([\"Purchase Date\", \"Nov. 1, 2022\"])\ndata.extend([\"\", \"\"])\nmdAcme.new_table(columns=2, rows=4, text=data, text_align='left') mdAcme.new_header(level=3, title='Instructions')\nlist1 = ['Getting Started', 'Remove Battery', ['Add 2 AAA Batteries', 'Close and lock']]\nmdAcme.new_list(list1)\nlist2 = ['1. Set Level', ['1. Scroll to view levels', '2. Press Select'], '2. Press Start', ]\nmdAcme.new_list(list2) mdAcme.create_md_file()<\/pre>\n<p>Update, save and run the <code>acme.py<\/code> file.<\/p>\n<p>If we preview <code>acme.md<\/code>, the following displays.<\/p>\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"932\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_204-1024x932.png\" alt=\"\" class=\"wp-image-865305\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_204-1024x932.png 1024w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_204-300x273.png 300w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_204-768x699.png 768w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_204.png 1042w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<p class=\"has-global-color-8-background-color has-background\"><img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/14.0.0\/72x72\/1f4a1.png\" alt=\"\ud83d\udca1\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/><strong>Note<\/strong>: There are additional ways to configure bullet points. For this article, the most commonly used was selected.<\/p>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n<h2>Add a Table of Contents<\/h2>\n<p class=\"has-global-color-8-background-color has-background\">This sections combines the three (3) headings created earlier (different level for each) and from these lines, creates a Table of Contents.<\/p>\n<p>On the highlighted line, the Table of Contents is created. For this function, a title (&#8216;<code>Table of Contents<\/code>&#8216;), and depth (<code>3<\/code>) was passed. <\/p>\n<p>A depth of 3 was selected as each heading in this article was assigned a different level (example, <code>level=1<\/code>, <code>level=2, level=3<\/code>).<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"25\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from mdutils.mdutils import MdUtils\nfrom mdutils import Html mdAcme = MdUtils(file_name='acme')\nmdAcme.new_paragraph(Html.image(path='as_logo.png', size='250', align='center'))\nmdAcme.new_paragraph('License and Installation Instructions', bold_italics_code='bi', align='center') mdAcme.new_header(level=1, title='Overview')\nmdAcme.write(\"Welcome to &lt;font color='red'>Acme Spinners&lt;\/font>!\\n\\n\")\nmdAcme.new_paragraph(\"Visit our website at &lt;a href='#'>acmespinners.ca&lt;\/a> to view our videos on the latest spinner techniques.\\n\") mdAcme.new_header(level=2, title='License')\ndata = [\"Item\", \"Description\"]\ndata.extend([\"License #\", \"ACS-3843-34-2217\"])\ndata.extend([\"Purchase Date\", \"Nov. 1, 2022\"])\ndata.extend([\"\", \"\"])\nmdAcme.new_table(columns=2, rows=4, text=data, text_align='left') mdAcme.new_header(level=3, title='Instructions')\nlist1 = ['Getting Started', 'Remove Battery', ['Add 2 AAA Batteries', 'Close and lock']]\nmdAcme.new_list(list1)\nlist2 = ['1. Set Level', ['1. Scroll to view levels', '2. Press Select'], '2. Press Start', ]\nmdAcme.new_list(list2) mdAcme.new_table_of_contents(table_title='Table of Contents', depth=3) mdAcme.create_md_file()<\/pre>\n<p>Update, save and run the <code>acme.py<\/code> file.<\/p>\n<p>If we preview <code>acme.md<\/code>, the following displays.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"909\" height=\"1024\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_205-909x1024.png\" alt=\"\" class=\"wp-image-865341\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_205-909x1024.png 909w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_205-266x300.png 266w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_205-768x865.png 768w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/new_acme_205.png 1052w\" sizes=\"auto, (max-width: 909px) 100vw, 909px\" \/><\/figure>\n<\/div>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n<h2>Summary<\/h2>\n<p>This article has shown you how to construct a fantastic-looking flat-text file!<\/p>\n<p>Good Luck &amp; Happy Coding!<\/p>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n<h2>Programmer Humor &#8211; Blockchain<\/h2>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"280\" height=\"394\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/07\/image-31.png\" alt=\"\" class=\"wp-image-457795\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/07\/image-31.png 280w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/07\/image-31-213x300.png 213w\" sizes=\"auto, (max-width: 280px) 100vw, 280px\" \/><figcaption><em>&#8220;Blockchains are like grappling hooks, in that it&#8217;s extremely cool when you encounter a problem for which they&#8217;re the right solution, but it happens way too rarely in real life.&#8221;<\/em> <strong>source <\/strong>&#8211; <a href=\"https:\/\/imgs.xkcd.com\/comics\/blockchain.png\" data-type=\"URL\" data-id=\"https:\/\/imgs.xkcd.com\/comics\/blockchain.png\" target=\"_blank\" rel=\"noreferrer noopener\">xkcd<\/a><\/figcaption><\/figure>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>5\/5 &#8211; (1 vote) This article will show you how to create and work with markdown files using Python. Markdown is an excellent tool with many features to spice up a flat-text file, such as changing text colors, adding bullet points, tables, and much more. A terrific way to add pizzazz to an otherwise dull [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[857],"tags":[73,468,528],"class_list":["post-129504","post","type-post","status-publish","format-standard","hentry","category-python-tut","tag-programming","tag-python","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/129504","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/comments?post=129504"}],"version-history":[{"count":0,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/129504\/revisions"}],"wp:attachment":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/media?parent=129504"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/categories?post=129504"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/tags?post=129504"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}