Convert Font Awesome HTML tags into inline SVG
Project description
fa2svg
A small Python package that converts Font Awesome <i>/<span> tags into embedded SVG images (<img src="data:image/svg+xml;base64,…">) so you can safely use FA icons in emails (or any HTML source that strips out inline <svg>).
Installation
pip install fa2svg
Or for local development:
git clone https://github.com/meena-erian/fa2svg.git
cd fa2svg
pip install -e .
Upload to PyPI
Make sure your .pypirc is set up as described in the project docs, then:
# from project root
twine upload --config-file "./.pypirc" dist/*
Usage
from fa2svg.converter import to_inline_svg_img
html = '''
<p>
Coffee time:
<i class="fas fa-mug-saucer"
style="font-size:64px;color:#c60">
</i>
and stars:
<span class="far fa-star"
style="font-size:48px;color:gold">
</span>
</p>
'''
converted = to_inline_svg_img(html)
print(converted)
# => all <i>/<span> icons replaced with <img src="data:image/svg+xml;base64,…" …
# preserving exact size, color, aspect ratio & baseline alignment
API
to_inline_svg_img(html: str) → strFetches the correct FA SVG, bakes in your inlinefont-sizeandcolor(or defaults to1em& current text color), and outputs a<img>tag with a base64-encoded SVG data URI, plus the properwidth,heightandvertical-alignCSS.
Contributing
- Fork the repo
- Create a topic branch
- Commit your changes & push
- Open a Pull Request
Issues and PRs are very welcome!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fa2svg-0.1.3.tar.gz.
File metadata
- Download URL: fa2svg-0.1.3.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6175d70297451688c12fa1548a9857915938f2436931ec8d74deb10973cb8f50
|
|
| MD5 |
69fd207ba2c4b8437346f635befb33b5
|
|
| BLAKE2b-256 |
853fb973d5a6f90e48d5e3e630d404678e9df7779ca1255ad3991bd9562529ec
|
File details
Details for the file fa2svg-0.1.3-py3-none-any.whl.
File metadata
- Download URL: fa2svg-0.1.3-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f8ffe9341ad8c02fdfa77f30f8238a81b474a877108ab2f3fcb577181a3614b6
|
|
| MD5 |
e93216e5fab5ea17a78bd1ac77b60ad3
|
|
| BLAKE2b-256 |
d3b65ec456136d45965dd9def8da488ae46688430ba39532697d9ec7cb766773
|