Skip to main content

A simple Markdown to HTML preprocessor that doesn't require third-party modules.

Project description

QuickHTML

A simple Markdown to HTML preprocessor that doesn't require any third-party modules.

Quickly generate HTML from Markdown, using python.

Technologies used

  • Python
  • RegEx

Installation

QuickHTML is a Python module, if Python is not already installed in your system, you can get the latest version here or using a package manager. pip should be installed with Python by default, if not, you can get it here.

QuickHTML can then be installed using pip, by running pip install quickhtml on the command line.

Usage

To see how to use QuickHTML directly from the terminal, run python -m quickhtml -h.

To import QuickHTML in Python files, use:

>>> import quickhtml
>>> ...

The convert() function accepts a string, and returns it formatted as HTML:

>>> string = "# This is a level 1 heading."
>>> quickhtml.convert(string)
'<h1>This is a level 1 heading.</h1>'
>>> ...

The convert_file() function accepts a file path, and returns the file content formatted as HTML:

>>> file_path = "./markdown_documents/example_document.md"
>>> quickhtml.convert_file(file_path)
'<p>This is an example document.</p>'
>>> ...

Supported syntax

Headings

To create a heading, add a number of pound (#) signs before a word or phrase. The number of signs corresponds to the heading level, up to six levels. For example, to create a level three heading (<h3>), use three pound signs (### This is a level three heading.).

Markdown HTML Output
# This is a level 1 heading. <h1>This is a level 1 heading.</h1>

This is a level 1 heading.

## This is a level 2 heading. <h2>This is a level 2 heading.</h2>

This is a level 2 heading.

### This is a level 3 heading. <h3>This is a level 3 heading.</h3>

This is a level 3 heading.

#### This is a level 4 heading. <h4>This is a level 4 heading.</h4>

This is a level 4 heading.

##### This is a level 5 heading. <h5>This is a level 5 heading.</h5>
This is a level 5 heading.
###### This is a level 6 heading. <h6>This is a level 6 heading.</h6>
This is a level 6 heading.

The alternate heading syntax, which uses the equals (=) and minus (-) signs is not supported at the moment.

Paragraphs

Use a blank line to separate paragraphs.

Markdown HTML Output
This 
is
a
paragraph.
<p>This is a paragraph.</p>

This is a paragraph.

This is a paragraph.

This is another paragraph.
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>

This is a paragraph.

This is another paragraph.

Line breaks

End a line with two or more spaces to create a line break (<br>).

Markdown HTML Output
This is a paragraph.  
This is still the same paragraph.
<p>This is a paragraph.<br>
This is still the same paragraph.</p>

This is a paragraph.
This is still the same paragraph.

Emphasis

Emphasis can be added by making text bold, italic, or both.

Bold

To make text bold, add two asterisks (**) or underscores (__) before and after a word, phrase, or letter.

Markdown HTML Output
**This is some bold text.** <p><strong>This is some bold text.</strong></p>

This is some bold text.

This is a __bold__ word. <p>This is a <strong>bold</strong> word.</p>

This is a bold word.

These are some **b**__o__**l**__d__ letters. <p>These are some <strong>b</strong><strong>o</strong><strong>l</strong><strong>d</strong> letters.</p>

These are some bold letters.

Italic

To make text italic, add an asterisk (*) or underscore (_) before and after a word, phrase, or letter.

Markdown HTML Output
*This is some italic text.* <p><em>This is some italic text.</em></p>

This is some italic text.

This is an _italic_ word. <p>This is an <em>italic</em> word.</p>

This is an italic word.

These are some *i*_t_*a*_l_*i*_c_ letters. <p>These are some <em>i</em><em>t</em><em>a</em><em>l</em><em>i</em><em>c</em> letters.</p>

These are some italic letters.

Bold and italic

To make text bold and italic, add three asterisks (***) or underscores (___) before and after a word, phrase, or letter.

Markdown HTML Output
***This is some bold and italic text.*** <p><em><strong>This is some bold and italic text.</strong></em></p>

This is some bold and italic text.

These are some ___bold and italic___ words. <p>These are some <em><strong>bold and italic</strong></em> words.</p>

These are some bold and italic words.

These are some ***b***___o___***l***___d___ ***a***___n___***d*** ___i___***t***___a___***l***___i___***c*** letters. <p>These are some <em><strong>b</strong></em><em><strong>o</strong></em><em><strong>l</strong></em><em><strong>d</strong></em> <em><strong>a</strong></em><em><strong>n</strong></em><em><strong>d</strong></em> <em><strong>i</strong></em><em><strong>t</strong></em><em><strong>a</strong></em><em><strong>l</strong></em><em><strong>i</strong></em><em><strong>c</strong></em> letters.</p>

These are some bold and italic letters.

Blockquotes

To create a blockquote, add a number of greater than (>) signs before a paragraph. To nest blockquotes, add a number of signs that is greater or lesser than the last one. For example, a level 1 blockquote (>) followed by a level 2 blockquote (>>).

Markdown HTML Output
> This is a level 1 blockquote.
<blockquote>
  <p>This is a level 1 blockquote.</p>
</blockquote>

This is a level 1 blockquote.

> This is a level 1 blockquote.
> This is another level 1 blockquote.
> This is the third level 1 blockquote.
<blockquote>
  <p>This is a level 1 blockquote.</p>
  <p>This is another level 1 blockquote.</p>
  <p>This is the third level 1 blockquote.</p>
</blockquote>

This is a level 1 blockquote.

This is another level 1 blockquote.

This is the third level 1 blockquote.

>> This is a level 1 blockquote.
>> This is a level 2 blockquote.
>>> This is a level 3 blockquote.
<blockquote>
  <p>This is a level 1 blockquote.</p>
  <blockquote>
    <p>This is a level 2 blockquote.</p>
    <blockquote>
      <p>This is a level 3 blockquote.</p>
    </blockquote>
  </blockquote>
</blockquote>

This is a level 1 blockquote.

This is a level 2 blockquote.

This is a level 3 blockquote.

> This is a level 1 blockquote.
>> This is a level 2 blockquote.
>>> This is a level 3 blockquote.
>> This is a level 2 blockquote.
> This is a level 1 blockquote.
<blockquote>
  <p>This is a level 1 blockquote.</p>
  <blockquote>
    <p>This is a level 2 blockquote.</p>
    <blockquote>
      <p>This is a level 3 blockquote.</p>
    </blockquote>
    <p>This is a level 2 blockquote.</p>
  </blockquote>
  <p>This is a level 1 blockquote.</p>
</blockquote>

This is a level 1 blockquote.

This is a level 2 blockquote.

This is a level 3 blockquote.

This is a level 2 blockquote.

This is a level 1 blockquote.

> This is a level 1 blockquote.
>> This is a level 2 blockquote.
>>> This is a level 3 blockquote.
> This is a level 1 blockquote.
<blockquote>
  <p>This is a level 1 blockquote.</p>
  <blockquote>
    <p>This is a level 2 blockquote.</p>
    <blockquote>
      <p>This is a level 3 blockquote.</p>
    </blockquote>
  </blockquote>
  <p>This is a level 1 blockquote.</p>
</blockquote>

This is a level 1 blockquote.

This is a level 2 blockquote.

This is a level 3 blockquote.

This is a level 1 blockquote.

At the moment, multiline items, such as multiline paragraphs, are not supported inside blockquotes. This means each line is a new item.

Lists

Items can be organized into ordered and unordered lists.

Ordered lists

To create an ordered list, add a number, followed by a period (.) or closing parenthesis ()), followed by a space before a paragraph. The numbers do not have to be in numerical order. To nest ordered lists, add a number of spaces before the number that is greater or lesser than the last number of spaces. For example, a level 1 ordered list (1. ) followed by a level 2 ordered list. ( 1. )

Markdown HTML Output
1. This is a level 1 ordered list item.
2. This is another level 1 ordered list item.
3. This is the third level 1 ordered list item.
<ol>
  <li>This is a level 1 ordered list item.</li>
  <li>This is another level 1 ordered list item.</li>
  <li>This is the third level 1 ordered list item.</li>
</ol>
  1. This is a level 1 ordered list item.
  2. This is another level 1 ordered list item.
  3. This is the third level 1 ordered list item.
1) This is a level 1 ordered list item.
2) This is another level 1 ordered list item.
3) This is the third level 1 ordered list item.
<ol>
  <li>This is a level 1 ordered list item.</li>
  <li>This is another level 1 ordered list item.</li>
  <li>This is the third level 1 ordered list item.</li>
</ol>
  1. This is a level 1 ordered list item.
  2. This is another level 1 ordered list item.
  3. This is the third level 1 ordered list item.
1. This is a level 1 ordered list item.
1. This is another level 1 ordered list item.
1. This is the third level 1 ordered list item.
<ol>
  <li>This is a level 1 ordered list item.</li>
  <li>This is another level 1 ordered list item.</li>
  <li>This is the third level 1 ordered list item.</li>
</ol>
  1. This is a level 1 ordered list item.
  2. This is another level 1 ordered list item.
  3. This is the third level 1 ordered list item.
82. This is a level 1 ordered list item.
6. This is another level 1 ordered list item.
14. This is the third level 1 ordered list item.
<ol>
  <li>This is a level 1 ordered list item.</li>
  <li>This is another level 1 ordered list item.</li>
  <li>This is the third level 1 ordered list item.</li>
</ol>
  1. This is a level 1 ordered list item.
  2. This is another level 1 ordered list item.
  3. This is the third level 1 ordered list item.
1. This is a level 1 ordered list item.
2. This is another level 1 ordered list item.
  1. This is a level 2 ordered list item.
  2. This is another level 2 ordered list item.
3. This is the third level 1 ordered list item.
<ol>
  <li>This is a level 1 ordered list item.</li>
  <li>This is another level 1 ordered list item.</li>
  <ol>
    <li>This is a level 2 ordered list item.</li>
    <li>This is another level 2 ordered list item.</li>
  </ol>
  <li>This is the third level 1 ordered list item.</li>
</ol>
  1. This is a level 1 ordered list item.
  2. This is another level 1 ordered list item.
    1. This is a level 2 ordered list item.
    2. This is another level 2 ordered list item.
  3. This is the third level 1 ordered list item.
1. This is a level 1 ordered list item.
2. This is another level 1 ordered list item.
  1. This is a level 2 ordered list item.
    1. This is a level 3 ordered list item.
3. This is the third level 1 ordered list item.
<ol>
  <li>This is a level 1 ordered list item.</li>
  <li>This is another level 1 ordered list item.</li>
  <ol>
    <li>This is a level 2 ordered list item.</li>
    <ol>
      <li>This is a level 3 ordered list item.</li>
    </ol>
  </ol>
  <li>This is the third level 1 ordered list item.</li>
</ol>
  1. This is a level 1 ordered list item.
  2. This is another level 1 ordered list item.
    1. This is a level 2 ordered list item.
      1. This is a level 3 ordered list item.
  3. This is the third level 1 ordered list item.

Unordered lists

To create an unordered list, add a dash (-), asterisk (*), or plus (+) sign, followed by a space before a paragraph. To nest unordered lists, add a number of spaces before the dash (-), asterisk (*), or plus (+) sign that is greater or lesser than the last number of spaces. For example, a level 1 unordered list (- ) followed by a level 2 unordered list. ( - )

Markdown HTML Output
- This is a level 1 unordered list item.
- This is another level 1 unordered list item.
- This is the third level 1 unordered list item.
<ul>
  <li>This is a level 1 unordered list item.</li>
  <li>This is another level 1 unordered list item.</li>
  <li>This is the third level 1 unordered list item.</li>
</ul>
  • This is a level 1 unordered list item.
  • This is another level 1 unordered list item.
  • This is the third level 1 unordered list item.
- This is a level 1 unordered list item.
* This is another level 1 unordered list item.
+ This is the third level 1 unordered list item.
<ul>
  <li>This is a level 1 unordered list item.</li>
  <li>This is another level 1 unordered list item.</li>
  <li>This is the third level 1 unordered list item.</li>
</ul>
  • This is a level 1 unordered list item.
  • This is another level 1 unordered list item.
  • This is the third level 1 unordered list item.
- This is a level 1 unordered list item.
- This is another level 1 unordered list item.
  - This is a level 2 unordered list item.
  - This is another level 2 unordered list item.
- This is the third level 1 unordered list item.
<ul>
  <li>This is a level 1 unordered list item.</li>
  <li>This is another level 1 unordered list item.</li>
  <ul>
    <li>This is a level 2 unordered list item.</li>
    <li>This is another level 2 unordered list item.</li>
  </ul>
  <li>This is the third level 1 unordered list item.</li>
</ul>
  • This is a level 1 unordered list item.
  • This is another level 1 unordered list item.
    • This is a level 2 unordered list item.
    • This is another level 2 unordered list item.
  • This is the third level 1 unordered list item.
- This is a level 1 unordered list item.
- This is another level 1 unordered list item.
  - This is a level 2 unordered list item.
    - This is a level 3 unordered list item.
- This is the third level 1 unordered list item.
<ul>
  <li>This is a level 1 unordered list item.</li>
  <li>This is another level 1 unordered list item.</li>
  <ul>
    <li>This is a level 2 unordered list item.</li>
    <ul>
      <li>This is a level 3 unordered list item.</li>
    </ul>
  </ul>
  <li>This is the third level 1 unordered list item.</li>
</ul>
  • This is a level 1 unordered list item.
  • This is another level 1 unordered list item.
    • This is a level 2 unordered list item.
      • This is a level 3 unordered list item.
  • This is the third level 1 unordered list item.

At the moment, multiline items, such as multiline paragraphs, are not supported inside lists. This means each line is a new item.

Code

To denote text as code, add backticks (`) before and after a word or phrase.

Markdown HTML Output
`This is some text denoted as code.` <code>This is some text denoted as code.</code> This is some text denoted as code.
This is a `word` denoted as code. <p>This is a <code>word</code> denoted as code.</p>

This is a word denoted as code.

Escaping backticks

If the word or phrase you want to denote as code includes one or more backticks, you can escape it by using double backticks (``) instead.

Markdown HTML Output
``This is some text denoted as code.`` <code>This is some text denoted as code.</code> This is some text denoted as code.
This is a ``word`` denoted as code. <p>This is a <code>word</code> denoted as code.</p>

This is a word denoted as code.

``This code contains `backticks`.`` <code>This code contains `backticks`.</code> This code contains `backticks`.

Backticks can also be escaped using a backslash (see escaping characters).

Horizontal Rules

To create a horizontal rule, add three or more asterisks (***), minus (---) signs, or underscores (___) by themselves on a line.

Markdown HTML Output
*** <hr>
--- <hr>
___ <hr>
**** <hr>
----- <hr>
______ <hr>

Links

To create a link, enclose the link name in square brackets ([]), followed by the URL enclosed in parentheses (()).

Markdown HTML Output
[Click me!](https://github.com/ckc-dev/QuickHTML) <a href="https://github.com/ckc-dev/QuickHTML">Click me!</a> Click me!
Go to [GitHub](https://github.com/)'s main page. <p>Go to <a href="https://github.com/">GitHub</a>'s main page.</p>

Go to GitHub's main page.

Adding titles to links

A title can optionally be added to a link, it will appear as a tooltip when the link is hovered. To add a title, enclose it in either single (') or double (") quotes after the URL.

Markdown HTML Output
[Click me!](https://github.com/ckc-dev/QuickHTML "Go to the main page of this repository.") <a href="https://github.com/ckc-dev/QuickHTML" title="Go to the main page of this repository.">Click me!</a> Click me!
Go to [GitHub](https://github.com/ 'Click here to go to the main page of GitHub. <p>Go to <a href="https://github.com/" title="Click here to go to the main page of GitHub.">GitHub</a>'s main page.</p>

Go to GitHub's main page.

Images

To add an image, use an exclamation mark (!), followed by the image alt text enclosed in square brackets ([]), followed by the image's path or URL enclosed in parentheses (()). Titles can be optionally added to images, to add a title, enclose it in either single (') or double (") quotes after the URL.

Markdown HTML Output
![Tux](https://upload.wikimedia.org/wikipedia/commons/thumb/3/35/Tux.svg/256px-Tux.svg.png) <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/3/35/Tux.svg/256px-Tux.svg.png" alt="Tux"> Tux
![Tux](https://upload.wikimedia.org/wikipedia/commons/thumb/3/35/Tux.svg/256px-Tux.svg.png "lewing@isc.tamu.edu Larry Ewing and The GIMP, CC0, via Wikimedia Commons") <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/3/35/Tux.svg/256px-Tux.svg.png" alt="Tux" title="lewing@isc.tamu.edu Larry Ewing and The GIMP, CC0, via Wikimedia Commons"> Tux

Adding links to images

To add a link to an image, enclose the Markdown for the image in square brackets ([]), then follow with the link enclosed in parentheses (()).

Markdown HTML Output
[![Tux](https://upload.wikimedia.org/wikipedia/commons/thumb/3/35/Tux.svg/256px-Tux.svg.png)](https://commons.wikimedia.org/wiki/File:Tux.svg) <a href="https://commons.wikimedia.org/wiki/File:Tux.svg"><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/3/35/Tux.svg/256px-Tux.svg.png" alt="Tux"></a> Tux
[![Tux](https://upload.wikimedia.org/wikipedia/commons/thumb/3/35/Tux.svg/256px-Tux.svg.png)](https://commons.wikimedia.org/wiki/File:Tux.svg "lewing@isc.tamu.edu Larry Ewing and The GIMP, CC0, via Wikimedia Commons") <a href="https://commons.wikimedia.org/wiki/File:Tux.svg" title="lewing@isc.tamu.edu Larry Ewing and The GIMP, CC0, via Wikimedia Commons"><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/3/35/Tux.svg/256px-Tux.svg.png" alt="Tux"></a> Tux

Escaping characters

Add a backslash (\) before a character to escape it, this is often used to display literal characters that would otherwise be used in Markdown syntax.

Markdown HTML Output
\# Without the backslash, this would be a heading. <p># Without the backslash, this would be a heading</p>

# Without the backslash, this would be a heading

\- Without the backslash, this would be an unordered list item. <p>- Without the backslash, this would be an unordered list item.</p>

- Without the backslash, this would be an unordered list item.

Escape sequences

You can use escape sequences when passing strings directly to the convert() function.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

quickhtml-2.0.7.tar.gz (31.2 kB view hashes)

Uploaded Source

Built Distribution

quickhtml-2.0.7-py3-none-any.whl (23.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page