Skip to main content

Figure and figcaption generator markdown extension

Project description

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.

  • figureNumbering (default: False):

    Adds a figure number like "Figure 1:" in front of the caption. It's wrapped in a <span /> for easier styling.

  • figureNumberClass (default: ""):

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

  • figureNumberText (default: "Figure"):

    The text to show in front of the figure number. A final non-breaking space is inserted between the content of figureNumberText and the actual figure number.

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.

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

yafg-0.4.tar.gz (19.8 kB view details)

Uploaded Source

Built Distribution

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

yafg-0.4-py2.py3-none-any.whl (19.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file yafg-0.4.tar.gz.

File metadata

  • Download URL: yafg-0.4.tar.gz
  • Upload date:
  • Size: 19.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for yafg-0.4.tar.gz
Algorithm Hash digest
SHA256 f43513dd8f0b88469219c3c8d084fedf3fc191c83352219fd5cd81b2b8d5bea4
MD5 f37a9e098c8c0e36efc9f262083c318c
BLAKE2b-256 63ed37595509ef72a11a115ce936c838d27337b911395a639090e885d601f949

See more details on using hashes here.

File details

Details for the file yafg-0.4-py2.py3-none-any.whl.

File metadata

  • Download URL: yafg-0.4-py2.py3-none-any.whl
  • Upload date:
  • Size: 19.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for yafg-0.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ecad8db110a803c9d2ac569af07c66434b2eeade929d9ae3864a4f83ba49b25c
MD5 a01cbb9cda74583977d3e22329e78617
BLAKE2b-256 11e5914d9b01412586f70fbf0f72031a6cc6b474c0b1500c529fdf37696bdacd

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