Skip to main content

Markdown extension to include FontAwesome icons with ease.

Project description

Easily place FontAwesome icons in your MarkDown files

This is a Markdown extension to include FontAwesome icons in your Markdown text, without pasting bulky HTML. Use emoticon-like strings like :fa-mug-hot: to place the corresponding FontAwesome markup in your text flow.

Installation

pip install fontawesome-in-markdown

How to use

Include your favorite version of FontAwesome CSS/assets in your HTML, then add fontawesome_in_markdown to your Markdown:

from markdown import Markdown

markdown = Markdown(extensions=['fontawesome_in_markdown'])

Basic Usage

markdown.convert('I ♥ :fa-mug-hot:')

will output:

<p>I ♥ <i class="fa-solid fa-mug-hot"></i></p>

Icon Styles

You can specify different styles using prefixes:

Legacy Format (Backward Compatible)

:fa fa-star:    → <i class="fa-solid fa-star"></i>
:fas fa-star:   → <i class="fa-solid fa-star"></i>
:far fa-star:   → <i class="fa-regular fa-star"></i>
:fal fa-star:   → <i class="fa-light fa-star"></i>
:fab fa-github: → <i class="fa-brands fa-github"></i>

New Format with Font Family and Style

The new format allows you to specify both family and style with more flexibility:

:fa-cl-s fa-star:   → <i class="fa-solid fa-star"></i>          (Classic Solid)
:fa-cl-r fa-star:   → <i class="fa-regular fa-star"></i>        (Classic Regular)
:fa-cl-l fa-star:   → <i class="fa-light fa-star"></i>          (Classic Light)
:fa-cl-t fa-star:   → <i class="fa-thin fa-star"></i>           (Classic Thin)
:fa-sh-s fa-star:   → <i class="fa-sharp fa-solid fa-star"></i> (Sharp Solid)

Family codes:

  • cl = Classic
  • sh = Sharp
  • dt = Duotone
  • sd = Sharp-Duotone
  • br = Brands

Style codes:

  • s = Solid
  • r = Regular
  • l = Light
  • t = Thin

You can also reverse the order (style-family):

:fa-r-dt fa-star:   → <i class="fa-duotone fa-regular fa-star"></i>
:fa-l-sh fa-star:   → <i class="fa-sharp fa-light fa-star"></i>

Simplified Format

You can omit parts, and they'll default to sensible values:

:fa-star:         → <i class="fa-solid fa-star"></i>             (Default: Classic Solid)
:fa-s fa-star:    → <i class="fa-solid fa-star"></i>             (Only style specified)
:fa-r fa-star:    → <i class="fa-regular fa-star"></i>           (Only style specified)
:fa-dt fa-star:   → <i class="fa-duotone fa-solid fa-star"></i>  (Only family specified)
:fa-br fa-github: → <i class="fa-brands fa-github"></i>          (Brands ignore style)

Size Modifiers

You can add size modifiers:

:fa-star fa-xs:  → <i class="fa-solid fa-star fa-xs"></i>
:fa-star fa-sm:  → <i class="fa-solid fa-star fa-sm"></i>
:fa-star fa-lg:  → <i class="fa-solid fa-star fa-lg"></i>
:fa-star fa-2x:  → <i class="fa-solid fa-star fa-2x"></i>
:fa-star fa-10x: → <i class="fa-solid fa-star fa-10x"></i>

Known Issues

Not a real issue, but worth mentioning: with this version, icon validation has been removed. Invalid icons are handed to FontAwesome and the behavior is handled by the library's CSS. This means that the library no longer warns you about possible typos or errors in the icon and style naming.

Credits

This extension is a fork of fontawesome-markdown by bmcorser.
For some reasons, the original repository is abandoned, so I decided to publish this updated version, after waiting for a PR to be accepted.

Should the original author come back in the future, to maintain the original package, I will probably merge it back. In the meantime this should be a valid dropdown replacement.

Contributions

I'll try my best to keep this repo up to date, reviewing and accepting contributions, but I'm not an expert Pythonista myself. Feel free to send in PRs as long as they describe the scope clearly, to ease the review process.

For those who, like me, don't work with Python on a daily basis, you can run tests in a docker container with:

docker run --rm -v "$(pwd):/app" -w /app python:bookworm bash -c "pip install -e .[test] pytest markdown && pytest -v"

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

fontawesome_in_markdown-0.2.1.tar.gz (17.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fontawesome_in_markdown-0.2.1-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

Details for the file fontawesome_in_markdown-0.2.1.tar.gz.

File metadata

  • Download URL: fontawesome_in_markdown-0.2.1.tar.gz
  • Upload date:
  • Size: 17.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.22

File hashes

Hashes for fontawesome_in_markdown-0.2.1.tar.gz
Algorithm Hash digest
SHA256 e1fb66f2b8bca1219d7f4911bc18e3452d9ac834c1de850a5a4d4eae8e0e2a27
MD5 ca6181f60b8d4b71438308e42b248b6b
BLAKE2b-256 2e7aaeb59e9dd10dc136a33ebffe45b89b581cb787df0bfbf2689a89d8e458d3

See more details on using hashes here.

File details

Details for the file fontawesome_in_markdown-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for fontawesome_in_markdown-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7bd9745a6b6c9f59e96f8eb48f0c786d34f1fece5af4f56ade046c1352df8ccc
MD5 2e1c4b4d1f40a6ed07593f9b30ad1cb0
BLAKE2b-256 034a4ec0e9f1f17a93a7256aa1da5c309d256526dd04f0b1bbb2af15a28f33ba

See more details on using hashes here.

Supported by

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