OleVik / grav-plugin-imgcaptions

Turns the title-attribute in img-elements into figure-elements with a figcaption
MIT License
17 stars 4 forks source link

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="https://github.com/OleVik/grav-plugin-imgcaptions/raw/master/street.jpg"></p>

To this:

<figure><img title="Street view from the east" alt="Street view" src="https://github.com/OleVik/grav-plugin-imgcaptions/raw/master/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

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.