Skip to main content

Markdown extension to display icons

Project description

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.

Current Version: 3.0

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...

Usage / Setup:

Default Prefix is "icon-":

md = markdown.Markdown(extensions=["iconfonts"])
converted_text = md.convert(text)

Use a custom Prefix:

md = markdown.Markdown(
    extensions=["iconfonts"],
    extension_configs={"iconfonts": {"prefix": "mypref-"}},
)
converted_text = md.convert(text)

No prefix:

This isn't suggested, as it will take over the already built in HTML Entities

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

The base option allows for use of Bootstrap and FontAwesome icons

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

Input: &icon-html5;

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

Combine options with a comma:

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

Input! &icon-spinner:spin:red,bold;

Output: <i aria-hidden="true" class="icon-spinner icon-spin red bold"></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>

Project details


Release history Release notifications | RSS feed

This version

3.0

Download files

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

Source Distribution

markdown_icons-3.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

markdown_icons-3.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file markdown_icons-3.0.tar.gz.

File metadata

  • Download URL: markdown_icons-3.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.9

File hashes

Hashes for markdown_icons-3.0.tar.gz
Algorithm Hash digest
SHA256 4371ac5d761a0f733094505b59691cb7368365e331d45d3ac886703aa77cfae3
MD5 28a497420841af4bf714a2068bd576bc
BLAKE2b-256 75263cfb9471fe8ae7171a835c2d0a6503ad8a3af7de32008e9393068cddb81f

See more details on using hashes here.

File details

Details for the file markdown_icons-3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for markdown_icons-3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 921f1b90e3ebe046fb2142bc59bf8c3b97e816bd3e04283c3f242948c02007ef
MD5 5b601b644c554d9603ee1a88003a9150
BLAKE2b-256 2e38cf2d06a12132974151e0353eb76ec150938a3dee7383c68f5a8d1fead1eb

See more details on using hashes here.

Supported by

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