Skip to main content

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) → str Fetches the correct FA SVG, bakes in your inline font-size and color (or defaults to 1em & current text color), and outputs a <img> tag with a base64-encoded SVG data URI, plus the proper width, height and vertical-align CSS.

Contributing

  1. Fork the repo
  2. Create a topic branch
  3. Commit your changes & push
  4. Open a Pull Request

Issues and PRs are very welcome!

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

fa2svg-0.1.3.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

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

fa2svg-0.1.3-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

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

Hashes for fa2svg-0.1.3.tar.gz
Algorithm Hash digest
SHA256 6175d70297451688c12fa1548a9857915938f2436931ec8d74deb10973cb8f50
MD5 69fd207ba2c4b8437346f635befb33b5
BLAKE2b-256 853fb973d5a6f90e48d5e3e630d404678e9df7779ca1255ad3991bd9562529ec

See more details on using hashes here.

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

Hashes for fa2svg-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f8ffe9341ad8c02fdfa77f30f8238a81b474a877108ab2f3fcb577181a3614b6
MD5 e93216e5fab5ea17a78bd1ac77b60ad3
BLAKE2b-256 d3b65ec456136d45965dd9def8da488ae46688430ba39532697d9ec7cb766773

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