All Projects → OleVik → grav-plugin-imgcaptions

OleVik / grav-plugin-imgcaptions

Licence: MIT License
Turns the title-attribute in img-elements into figure-elements with a figcaption

Programming Languages

PHP
23972 projects - #3 most used programming language
Twig
543 projects

Grav Img Captions Plugin

Wraps images in <figure> and captions in <figcaption> based on the title-attribute of the img-element. From this Markdown:

![Street view](street.jpg "Street view from the east")

Which outputs this HTML:

<p><img title="Street view from the east" alt="Street view" src="street.jpg"></p>

To this:

<figure><img title="Street view from the east" alt="Street view" src="street.jpg"><figcaption>Street view from the east</figcaption></figure>

Note: The plugin unwraps images from paragraphs, ie. removes enclosing <p>-elements from <img>-elements, as <figure>-elements are invalid HTML within paragraphs.

Installation and Configuration

  1. Download the zip version of this repository and unzip it under /your/site/grav/user/plugins.
  2. Rename the folder to imgcaptions.

You should now have all the plugin files under

/your/site/grav/user/plugins/imgcaptions

The plugin is enabled by default, and can be disabled by copying user/plugins/imgcaptions/imgcaptions.yaml into user/config/plugins/imgcaptions.yaml and setting enabled: false.

New in 3.0.0

The Page-instance, and thus Media-instance, is now available to the partials/figure.html.twig-template. This means more interoperability between the figure and the Page, such as getting the URL to the full image with {{ page.media[filename].url }}.

NOTE: This is with a few caveats: You must use a normal syntax for Image Linking, your filenames should generally not contain whitespace or special characters, and be identical in both Markdown and in your files. Lastly, Grav-streams are currently not supported.

TODO

  • Revise tests and test-data
  • Implement DOM-parser

Running tests

Run composer update to install the testing dependencies. Then run composer test in the root folder. Finally, run composer update --no-dev to uninstall the testing dependencies.

MIT License 2017-2019 by Ole Vik.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].