Skip to content

OleVik/grav-plugin-imgcaptions

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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.

About

Turns the title-attribute in img-elements into figure-elements with a figcaption

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •