Skip to main content

yafg - Yet Another Figure Generator

yafg is yet another figure generator plugin for Python's Markdown. It's written and tested with Python 2.7 and Python 3.6 as well as Markdown 3.1.1, but aims at supporting as many versions as possible. If you encounter any problems with the given versions or find yourself using yafg without problems with any others, please give me a hint using the e-mail address listed below.

It uses the title attribute given to an image within Markdown to generate a <figure> environment with a <figcaption> containing the title's text, e.g.:

![Alt text](/path/to/image.png "This is the title of the image.")

becomes

<figure>
<img alt="Alt text" src="/path/to/image.png" title="This is the title of the image." />
<figcaption>This is the title of the image.</figcaption>
</figure>

How?

Install

yafg can be installed via PyPI using:

pip install yafg

Standard Usage

When parsing your input, you can add yafg to Markdown as follows:

import yafg

# ...

outputString = markdown.markdown(inputString, extensions = [yafg.YafgExtension(stripTitle=False)])

Pelican

Pelican users can add yafg to their generator process by adding it to the MARKDOWN variable in the pelicanconf.py as follows:

MARKDOWN = {
    'extensions_configs': {
        'yafg': {
            'stripTitle': 'False',
        },
    },
}

Options

Currently supported options are listed below:

  • stripTitle (default: False):

    Removes the original title attribute from the <img /> element. Since its usage is discouraged anyways (see below), this may be an option worth considering.

  • figureClass (default: ""):

    The CSS class to add to the generated <figure /> element.

  • figcaptionClass (default: ""):

    The CSS class to add to the generated <figcaption /> element.

Why?

yafg arose from the dissatisfaction with the existing solutions, namely:

  • markdown_captions which uses the alt attribute for the <figcaption>.
  • markdown-figcap which uses a cryptic syntax that doesn't integrate well into Markdown, IMHO.
  • figureAltCaption which cannot handle multi-line descriptions and uses the alt attribute for the <figcaption>.

Using the alt attribute to fill the <figcaption> is not correct, because as the standard states

[...] the alternative text is a replacement for the image, not a description [...]

for the most common case of a text accompanied by an augmenting image. It should be used for an exact reproduction of what can be seen on the image for those who cannot see it, for example because they're blind or their internet connection is too slow. A figure's caption in turn should provide a description helping to understand the content of the image.

The title attribute on the other hand should contain "[a]dvisory information associated with the element (W3C Core Attribute List). This is rather vague and often used by browser vendors to show tooltips containing the title. Since tooltips are highly problematic for a11y reasons and the browser support varies, "[r]elying on the title attribute is currently discouraged" (HTML Living Standard). This makes it an ideal candidate to store the wanted figcaption inside of the standard Markdown syntax.

Author

yafg has been written by:

License

yafg has been published under a GPL 3.0 or later license. See the LICENSE file for more information.

Metadata

Release files for yafg 0.2

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

Source distribution (sdist)

Source distribution for yafg 0.2
File Size Uploaded
yafg-0.2.tar.gz 4.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for yafg 0.2
File Interpreter ABI Platform
yafg-0.2-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 22.8 kB

Release files / yafg-0.2.tar.gz

Download URL yafg-0.2.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
d730d5fb35a3e4cc197bfa0c18694bb69801d513fc561033838a0e6887183b50
BLAKE2b-256 checksum
How to use checksums
e961763d8dccefc14bcd6629df553d99ef084e9c064c99fd0b037ec6bd50be5f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.8

Release files / yafg-0.2-py2.py3-none-any.whl

Download URL yafg-0.2-py2.py3-none-any.whl
Size 17.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
5f4a549fceff843ecac41252e6de46a767c4b18796bfdaf6e6c55501786a8b0c
BLAKE2b-256 checksum
How to use checksums
2cfb55ff724b96ab3d4d664a4947a269ee78fc0aacd635561a29a06d0f9c181b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.8

Release history Release notifications | RSS feed

0.4

2 release files

0.3

2 release files

This release

0.2 This release

2 release files

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