Skip to main content

Code style: black

markdown-icons (iconfonts.py)

Easily display icon fonts in python markdown. Just add the CSS necessary for your font and add this extension.

This is a 3rd party extension for Python Markdown. You can see a full list of 3rd party extensions here.

Although this works with any icon font, users can use a mod syntax to add more prefixed classes to support Font Awesome and its special classes such as 2x, 3x, muted, spin, etc

Furthermore, users can add their own user_mod syntax to add additional, non-prefixed, pre-defined classes for greater control over their icons while allowing you to control exactly what styles are allowed.

See the python markdown documentation for more information.

Use it in any personal or commercial project you want.

Syntax:

  • Accepts a-z, A-Z, 0-9, _(underscore), and - (hypen)
  • Uses HTML Entity like syntax: &entity_name;
&icon-html5;
&icon-css3;
&icon-my-icon;

Mod syntax:

&icon-html5:2x;
&icon-quote:3x,muted;
&icon-spinner:large,spin;

User mod syntax:

&icon-html5::red;
&icon-quote:2x:bold;

Example Markdown:

I love &icon-html5; and &icon-css3;
&icon-spinner:large,spin; Sorry we have to load...
Output:
I love <i aria-hidden="true" class="icon-html5"></i> and <i aria-hidden="true" class="icon-css3"></i>
<i aria-hidden="true" class="icon-spinner icon-large icon-spin"></i> Sorry we have to load...

Installation:

pip install markdown-iconfonts

Usage / Setup:

Default Prefix is "icon-":

import markdown

md = markdown.Markdown(extensions=['iconfonts'])

or

import markdown
from iconfonts import IconFontsExtension

md = markdown.Markdown(extensions=[IconFontsExtension()])

The base option allows for use of Bootstrap 3 and FontAwesome 4 icons

md = markdown.Markdown(extensions=['iconfonts'],
                       extension_configs={"base":"icon"})
converted_text = md.convert(text)

Input: &icon-html5;

Output: <i aria-hidden="true" class="icon icon-html5"></i>

prefix_base_pairs option

The prefix_base_pairs option allows for multiple prefix-base pairs to be specified, to allow you to support both Bootstrap 3/Glyphicon and FontAwesome icons

md = markdown.Markdown(extensions=['iconfonts'],
                       extension_configs={
                           'iconfonts': {
                               'prefix_base_pairs': {
                                   'fa-': 'fa',
                                   'glyphicon-': 'glyphicon',
                               }
                           }
                       })
converted_text = md.convert(text)

Input: &glyphicon-remove; &fa-html5;

Output: <i aria-hidden="true" class="glyphicon glyphicon-remove"></i><i aria-hidden="true" class="fa fa-html5"></i>

How to run the unit tests

  • Install Markdown: pip install markdown
  • Install markdown icons. Copy the iconfonts.py file into site-packages/markdown/extensions/
  • Navigate to the test directory in CMD/terminal and run python unit-tests.py -v

Metadata

Release files for markdown-iconfonts 3.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for markdown-iconfonts 3.0.0
File Size Uploaded
markdown-iconfonts-3.0.0.tar.gz 5.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for markdown-iconfonts 3.0.0
File Interpreter ABI Platform
markdown_iconfonts-3.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 10.2 kB

Release files / markdown-iconfonts-3.0.0.tar.gz

Download URL markdown-iconfonts-3.0.0.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
5cdc0d4e80cb4cbc2301e4b3430488bf2e07b95a2664a5ebe1451b6c175a1839
BLAKE2b-256 checksum
How to use checksums
c7907955c77aea8e1b32ca7fff1d3f8393991ee720135d427a42940ed6ec872a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

Release files / markdown_iconfonts-3.0.0-py3-none-any.whl

Download URL markdown_iconfonts-3.0.0-py3-none-any.whl
Size 4.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0c6faa00242893b115e2fbbc9d08949651ae7474d0cf0d3305f26b196ee1fa74
BLAKE2b-256 checksum
How to use checksums
5af85a04c6dc0743769cea3cde4fe4cb62ca320c07524986b254bdc890ce4f80
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

Release history Release notifications | RSS feed

This release

3.0.0 This release

2 release files

2.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page