Sick Gaming
[Tut] Working with Markdown Files in Python - Printable Version

+- Sick Gaming (https://www.sickgaming.net)
+-- Forum: Programming (https://www.sickgaming.net/forum-76.html)
+--- Forum: Python (https://www.sickgaming.net/forum-83.html)
+--- Thread: [Tut] Working with Markdown Files in Python (/thread-100195.html)



[Tut] Working with Markdown Files in Python - xSicKxBot - 11-07-2022

Working with Markdown Files in Python

<div>
<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;}">
<div class="kksr-stars">
<div class="kksr-stars-inactive">
<div class="kksr-star" data-star="1" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" data-star="2" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" data-star="3" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" data-star="4" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" data-star="5" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
</p></div>
<div class="kksr-stars-active" style="width: 142.5px;">
<div class="kksr-star" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
</p></div>
</div>
<div class="kksr-legend" style="font-size: 19.2px;"> 5/5 – (1 vote) </div>
</div>
<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>
<p class="has-base-background-color has-background"><img src="https://s.w.org/images/core/emoji/14.0.0/72x72/1f4a1.png" alt="?" 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>
<p>To make it more interesting, we have the following running scenario:</p>
<div class="wp-block-image">
<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="(max-width: 401px) 100vw, 401px" /></figure>
</div>
<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>
<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>
<hr class="wp-block-separator has-alpha-channel-opacity wp-embed-aspect-16-9 wp-has-aspect-ratio"/>
<p class="wp-embed-aspect-16-9 wp-has-aspect-ratio has-global-color-8-background-color has-background"><img src="https://s.w.org/images/core/emoji/14.0.0/72x72/1f4ac.png" alt="?" 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>
<p class="wp-embed-aspect-16-9 wp-has-aspect-ratio">We can accomplish this task by performing the following steps:</p>
<ol type="video" class="wp-embed-aspect-16-9 wp-has-aspect-ratio">
<li>Install Required Library</li>
<li>Create a Python File</li>
<li>Create a Markdown File</li>
<li>Preview Markdown File</li>
<li>Add Logo Image</li>
<li>Add a Paragraph</li>
<li>Add Heading</li>
<li>Add Table</li>
<li>Add Bullet Points</li>
<li>Add Table of Contents</li>
</ol>
<hr class="wp-block-separator has-alpha-channel-opacity"/>
<h2>Install Required Library</h2>
<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>
<p>To install this library, navigate to the command prompt and run the following code.</p>
<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>
<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>
<hr class="wp-block-separator has-alpha-channel-opacity"/>
<h2>Create Python File</h2>
<p class="has-global-color-8-background-color has-background">Let’s start by creating a Python file called <code>acme.py</code> and placing this file into the current working directory. </p>
<p>In the IDE, navigate to and open <code>acme.py</code> and add the following lines.</p>
<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
from mdutils import Html</pre>
<p>These lines allow access to and manipulation of markdown features.</p>
<p>Save this file.</p>
<hr class="wp-block-separator has-alpha-channel-opacity"/>
<h2>Create a Markdown File</h2>
<p class="has-global-color-8-background-color has-background">The next step is to create a markdown file. </p>
<p>Open the <code>acme.py</code> file created earlier. At this point, this file should only contain two (2) lines of code.</p>
<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
from mdutils import Html</pre>
<p>The following code snippet appends two (2) additional lines to <code>acme.py</code>.</p>
<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>
<pre class="wp-block-preformatted"><code>&lt;mdutils.mdutils.MdUtils object at 0x00000257FEB64940></code></pre>
<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
from mdutils import Html mdAcme = MdUtils(file_name='acme') mdAcme.create_md_file()</pre>
<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>
<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>
<p>Save the <code>acme.py</code> file.</p>
<p class="has-global-color-8-background-color has-background"><img src="https://s.w.org/images/core/emoji/14.0.0/72x72/1f4a1.png" alt="?" 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>
<hr class="wp-block-separator has-alpha-channel-opacity"/>
<h2>Preview a Markdown File</h2>
<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>
<p>In the IDE, hover over the <code>acme.md</code> file and right-mouse click. This action displays a pop-up. </p>
<div class="wp-block-image">
<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="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>
<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>
<div class="wp-block-image">
<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="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>
<p>No worries! We’ll fix this in the next sections!</p>
<p class="has-global-color-8-background-color has-background"><strong><img src="https://s.w.org/images/core/emoji/14.0.0/72x72/1f4a1.png" alt="?" class="wp-smiley" style="height: 1em; max-height: 1em;" />Note</strong>: Depending on the IDE, the Preview option may differ.</p>
<hr class="wp-block-separator has-alpha-channel-opacity"/>
<h2>Add Logo Image</h2>
<p class="has-global-color-8-background-color has-background">Let’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>
<p>There are two (2) ways to add an image. </p>
<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>
<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>
<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
from mdutils import Html mdAcme = MdUtils(file_name='acme')
mdAcme.new_line(mdAcme.new_inline_image(path='as_logo.png')) mdAcme.create_md_file()</pre>
<p>Update <code>acme.py</code>, save and run.</p>
<p>If we preview <code>acme.md</code>, the logo displays on a new line (size: 411×117) and is left-aligned.</p>
<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="(max-width: 1024px) 100vw, 1024px" /></figure>
<p><strong>Option 2:</strong></p>
<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>
<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
from mdutils import Html mdAcme = MdUtils(file_name='acme')
mdAcme.new_paragraph(Html.image(path='as_logo.png', size='250', align='center')) mdAcme.create_md_file()</pre>
<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>
<p>Update <code>acme.py</code>, save and run.</p>
<p>If we preview <code>acme. md</code>, the logo displays in its modified size and is center-aligned.</p>
<div class="wp-block-image">
<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="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>
<p>For this article, Option 2 is used.</p>
<hr class="wp-block-separator has-alpha-channel-opacity"/>
<h2>Add a Paragraph</h2>
<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’s add a new paragraph.</p>
<p>The highlighted line creates a new string. This string is formatted to bold, italics and is center-aligned.</p>
<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
from mdutils import Html mdAcme = MdUtils(file_name='acme')
mdAcme.new_paragraph(Html.image(path='as_logo.png', size='250', align='center'))
mdAcme.new_paragraph('License and Installation Instructions', bold_italics_code='bi', align='center') mdAcme.create_md_file()</pre>
<p>Update <code>acme.py</code>, save and run.</p>
<p>If we preview <code>acme.md</code>, the paragraph displays in bold italics and is center-aligned.</p>
<div class="wp-block-image">
<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="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>
<hr class="wp-block-separator has-alpha-channel-opacity"/>
<h2>Add Heading and Text</h2>
<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>
<p>In the highlighted area below, an Overview section is created. </p>
<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>
<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
from mdutils import Html mdAcme = MdUtils(file_name='acme')
mdAcme.new_paragraph(Html.image(path='as_logo.png', size='250', align='center'))
mdAcme.new_paragraph('License and Installation Instructions', bold_italics_code='bi', align='center') mdAcme.new_header(level=1, title='Overview')
mdAcme.write("Welcome to &lt;font color='red'>Acme Spinners&lt;/font>!\n\n")
mdAcme.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>
<p>Update <code>acme.py</code>, save and run.</p>
<p>If we preview <code>acme.md</code>, the Overview heading and text displays.</p>
<div class="wp-block-image">
<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="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>
<p>Let’s open <code>acme.md</code> to review the code when not in Preview Mode. </p>
<p>Notice that the code in the <code>acme.py</code> file was converted to HTML.</p>
<div class="wp-block-image">
<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="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>
<p class="has-global-color-8-background-color has-background"><img src="https://s.w.org/images/core/emoji/14.0.0/72x72/1f4a1.png" alt="?" 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>
<hr class="wp-block-separator has-alpha-channel-opacity"/>
<h2>Add Table</h2>
<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>
<p>In the highlighted area below, a License section was created. </p>
<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>
<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
from mdutils import Html mdAcme = MdUtils(file_name='acme')
mdAcme.new_paragraph(Html.image(path='as_logo.png', size='250', align='center'))
mdAcme.new_paragraph('License and Installation Instructions', bold_italics_code='bi', align='center') mdAcme.new_header(level=1, title='Overview')
mdAcme.write("Welcome to &lt;font color='red'>Acme Spinners&lt;/font>!\n\n")
mdAcme.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')
data = ["Item", "Description"]
data.extend(["License #", "ACS-3843-34-2217"])
data.extend(["Purchase Date", "Nov. 1, 2022"])
data.extend(["", ""])
mdAcme.new_table(columns=2, rows=4, text=data, text_align='left')
mdAcme.new_line()</pre>
<p>Update, save and run the <code>acme.py</code> file.</p>
<p>If we preview <code>acme.md</code>, the following displays.</p>
<div class="wp-block-image">
<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="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>
<hr class="wp-block-separator has-alpha-channel-opacity"/>
<h2>Add Bullet Points</h2>
<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>
<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
from mdutils import Html mdAcme = MdUtils(file_name='acme')
mdAcme.new_paragraph(Html.image(path='as_logo.png', size='250', align='center'))
mdAcme.new_paragraph('License and Installation Instructions', bold_italics_code='bi', align='center') mdAcme.new_header(level=1, title='Overview')
mdAcme.write("Welcome to &lt;font color='red'>Acme Spinners&lt;/font>!\n\n")
mdAcme.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')
data = ["Item", "Description"]
data.extend(["License #", "ACS-3843-34-2217"])
data.extend(["Purchase Date", "Nov. 1, 2022"])
data.extend(["", ""])
mdAcme.new_table(columns=2, rows=4, text=data, text_align='left') mdAcme.new_header(level=3, title='Instructions')
list1 = ['Getting Started', 'Remove Battery', ['Add 2 AAA Batteries', 'Close and lock']]
mdAcme.new_list(list1)
list2 = ['1. Set Level', ['1. Scroll to view levels', '2. Press Select'], '2. Press Start', ]
mdAcme.new_list(list2) mdAcme.create_md_file()</pre>
<p>Update, save and run the <code>acme.py</code> file.</p>
<p>If we preview <code>acme.md</code>, the following displays.</p>
<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="(max-width: 1024px) 100vw, 1024px" /></figure>
<p class="has-global-color-8-background-color has-background"><img src="https://s.w.org/images/core/emoji/14.0.0/72x72/1f4a1.png" alt="?" 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>
<hr class="wp-block-separator has-alpha-channel-opacity"/>
<h2>Add a Table of Contents</h2>
<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>
<p>On the highlighted line, the Table of Contents is created. For this function, a title (‘<code>Table of Contents</code>‘Wink, and depth (<code>3</code>) was passed. </p>
<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>
<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
from mdutils import Html mdAcme = MdUtils(file_name='acme')
mdAcme.new_paragraph(Html.image(path='as_logo.png', size='250', align='center'))
mdAcme.new_paragraph('License and Installation Instructions', bold_italics_code='bi', align='center') mdAcme.new_header(level=1, title='Overview')
mdAcme.write("Welcome to &lt;font color='red'>Acme Spinners&lt;/font>!\n\n")
mdAcme.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')
data = ["Item", "Description"]
data.extend(["License #", "ACS-3843-34-2217"])
data.extend(["Purchase Date", "Nov. 1, 2022"])
data.extend(["", ""])
mdAcme.new_table(columns=2, rows=4, text=data, text_align='left') mdAcme.new_header(level=3, title='Instructions')
list1 = ['Getting Started', 'Remove Battery', ['Add 2 AAA Batteries', 'Close and lock']]
mdAcme.new_list(list1)
list2 = ['1. Set Level', ['1. Scroll to view levels', '2. Press Select'], '2. Press Start', ]
mdAcme.new_list(list2) mdAcme.new_table_of_contents(table_title='Table of Contents', depth=3) mdAcme.create_md_file()</pre>
<p>Update, save and run the <code>acme.py</code> file.</p>
<p>If we preview <code>acme.md</code>, the following displays.</p>
<div class="wp-block-image">
<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="(max-width: 909px) 100vw, 909px" /></figure>
</div>
<hr class="wp-block-separator has-alpha-channel-opacity"/>
<h2>Summary</h2>
<p>This article has shown you how to construct a fantastic-looking flat-text file!</p>
<p>Good Luck &amp; Happy Coding!</p>
<hr class="wp-block-separator has-alpha-channel-opacity"/>
<h2>Programmer Humor – Blockchain</h2>
<div class="wp-block-image">
<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="(max-width: 280px) 100vw, 280px" /><figcaption><em>“Blockchains are like grappling hooks, in that it’s extremely cool when you encounter a problem for which they’re the right solution, but it happens way too rarely in real life.”</em> <strong>source </strong>– <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>
</div>
</div>


https://www.sickgaming.net/blog/2022/11/05/working-with-markdown-files-in-python/