GithubHelp home page GithubHelp logo

jekyll-figure's Introduction

jekyll-figure

A liquid tag for Jekyll that generates <figure> elements.

Gem version Build status

Installation

  1. Add gem 'jekyll-figure' to your site’s Gemfile and run bundle
  2. Add the following to your site’s _config.yml:
plugins:
  - jekyll-figure

Note: If you are using a Jekyll version less than 3.5.0, use the gems key instead of plugins.

Usage

This plugin provides a liquid tag that enables you to generate a <figure> element. It takes optional caption and class parameters.

{% figure [caption:"Caption (markdown)"] [class:"class1 class2"] %}
Figure content (markdown)
{% endfigure %}

Examples

In simplest usage:

{% figure %}
Content
{% endfigure %}
<figure>
  <p>Content</p>
</figure>

You can provide a caption, for which any markdown will be rendered:

{% figure caption:"*Markdown* caption" %}
Content
{% endfigure %}
<figure>
  <p>Content</p>
  <figcaption><em>Markdown</em> caption</figcaption>
</figure>

You can also provide a class name(s) for CSS styling:

{% figure caption:"A caption" class:"classname" %}
Content
{% endfigure %}
<figure class="classname">
  <p>Content</p>
  <figcaption>A caption</figcaption>
</figure>

The caption parameter also accepts liquid markup:

{% figure caption:"{{ page.title }}" %}
Content
{% endfigure %}
<figure>
  <p>Content</p>
  <figcaption>The title of my page</figcaption>
</figure>

You can also add labels and reference them:

{% figure caption:"A caption." label:example %}
An example figure that can be referenced later.
{% endfigure %}

You can see an example in {% figref example %}.
<figure id="example">
  <p>An example figure that can be referenced later.</p>
  <figcaption><em>Figure 1:</em> A caption.</figcaption>
</figure>

<p>You can see an example in <a href="#example">figure 1</a></p>

The word ‘Figure’ in the figcaption is translated according to the lang you set in the yaml header of your post. If your language is not supported simple set figure to the yaml header of your post to the value you want to use instead of ‘Figure’.

Configuration

Any markdown provided within the {% figure %} block is rendered using Jekyll’s Markdown parser, Kramdown. However, this means images and other content will be wrapped within <p> tags, like so:

<figure>
  <p><img src="/path/to/image.jpg" alt="Image"></p>
</figure>

To disable this behaviour, in your Jekyll configuration set the paragraphs value for this plugin to false:

plugins:
  - jekyll-figure

jekyll-figure:
  paragraphs: false

Note however that this will remove all paragraph tags, even those nested within other elements.

Testing

  1. bundle install
  2. bundle exec rake spec

Contributing

  1. Fork the project
  2. Create a descriptively named feature branch
  3. Add your feature
  4. Submit a pull request

jekyll-figure's People

Contributors

dependabot[bot] avatar grauschnabel avatar kenman345 avatar paulrobertlloyd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

jekyll-figure's Issues

cannot load such file -- jekyll-figure

Dependency Error: Yikes! It looks like you don't have jekyll-figure or one of its dependencies installed. In order to use Jekyll as currently configured, you'll need to install this gem. The full error message from Ruby is: 'cannot load such file -- jekyll-figure' If you run into trouble, you can find helpful resources at https://jekyllrb.com/help/!
I added gem to gemfile and did a bundle install ...Still got error message

Liquid Exception: undefined method `[]' for nil:NilClass

I installed the version 0.2.0 of jekyll-figure and got this error while trying to serve the site locally:

 Liquid Exception: undefined method `[]' for nil:NilClass in /home/<USER>/Documents/notes/_posts/2024-03-02-ecg.md
/mnt/secondary/cache/bundle/ruby/3.0.0/gems/jekyll-figure-0.2.0/lib/utils.rb:42:in `print_reference': undefined method `[]' for nil:NilClass (NoMethodError)

I have these plugins in my config.yml:

plugins:
  - jekyll-mermaid
  - jekyll-feed
  - jekyll/scholar
  - jekyll-figure

On the blog post that it references, I am trying to add figures like this:

{% figure caption:"Theoretical Schematic of an ECG circuit." label:"fig_schematic "%}
![Theoretical Schematic of the ECG circuit.]({{ site.baseurl }}/assets/images/2024/2024-03-02-ecg/ecg/ecg_simple.svg){: width="80%" }
{% endfigure %}

And call them with figref: {% figref fig_schematic %}

Any ideas how to fix this?

Using in ordered list leads to wrong rendering

When I put following markdown

---
layout: null
---
# Test

{% figure caption:"First Figure" %}
Content of first figure
{% endfigure %}

1. First step
2. Second step with figure

   {% figure caption:"Second Figure" %}
   Content of second figure
   {% endfigure %}

3. Third step

I would expect the second figure being nested in the second item - and that the third item is rendered as third item.

The result, however, is different:

grafik

<h1 id="test">Test</h1>

<figure>
Content of first figure
  <figcaption>First Figure</figcaption>
</figure>

<ol>
  <li>First step</li>
  <li>
    <p>Second step with figure</p>

    <figure>
Content of second figure

</figure>
  </li>
</ol>
<figcaption>Second Figure</figcaption>
<p>&lt;/figure&gt;</p>

<ol>
  <li>Third step</li>
</ol>

CC @grauschnabel

Figure numbering?

Hi there,

is there an easy way to automatically add "Figure X" to the caption, where X is an incrementing number? So it works fine if we add more figures to have the numbers right?

And can I link to that figure number with a reference?

Thanks,
Martin

Does not render on serve -w

Hi there,

I usually use bundle exec jekyll serve -low when I create new posts to see how it acutally looks like. The figure environment in the html is rendered great by the first rendering, but for any unknown reason the figure html tag is not there when changing something in the file, and jekyll renders it again.

What can i do here? I read your code, but cannot figure out whats wrong...

  • Martin

Liquid Exception: undefined method `cache_dir'

Running into exceptions on first use of plugin.

Spent a long time trying to get imagemagik installed before giving up and attempting to use the docker image, jekyll/jekyll.

Has anyone experience of this error?

bundle exec jekyll build --trace

  Liquid Exception: undefined method `cache_dir' for #<Jekyll::Site:0x0000556f88257d38> in /_layouts/collection.html
bundler: failed to load command: jekyll (/usr/gem/bin/jekyll)
NoMethodError: undefined method `cache_dir' for #<Jekyll::Site:0x0000556f88257d38>
  /usr/gem/gems/jekyll_picture_tag-1.12.0/lib/jekyll_picture_tag/cache/base.rb:43:in `base_directory'
  /usr/gem/gems/jekyll_picture_tag-1.12.0/lib/jekyll_picture_tag/cache/base.rb:55:in `filename'
  /usr/gem/gems/jekyll_picture_tag-1.12.0/lib/jekyll_picture_tag/cache/base.rb:33:in `data'
  /usr/gem/gems/jekyll_picture_tag-1.12.0/lib/jekyll_picture_tag/cache/base.rb:12:in `[]'
  /usr/gem/gems/jekyll_picture_tag-1.12.0/lib/jekyll_picture_tag/source_image.rb:71:in `check_cache'
  /usr/gem/gems/jekyll_picture_tag-1.12.0/lib/jekyll_picture_tag/source_image.rb:17:in `initialize'
  /usr/gem/gems/jekyll_picture_tag-1.12.0/lib/jekyll_picture_tag/instructions/set.rb:63:in `new'
  /usr/gem/gems/jekyll_picture_tag-1.12.0/lib/jekyll_picture_tag/instructions/set.rb:63:in `build_source_images'
  /usr/gem/gems/jekyll_picture_tag-1.12.0/lib/jekyll_picture_tag/instructions/set.rb:34:in `source_images'
  /usr/gem/gems/jekyll_picture_tag-1.12.0/lib/jekyll_picture_tag/router.rb:48:in `source_images'
  /usr/gem/gems/jekyll_picture_tag-1.12.0/lib/jekyll_picture_tag/utils.rb:51:in `count_srcsets'
  /usr/gem/gems/jekyll_picture_tag-1.12.0/lib/jekyll_picture_tag/output_formats/auto.rb:7:in `new'
  /usr/gem/gems/jekyll_picture_tag-1.12.0/lib/jekyll_picture_tag.rb:68:in `render'
  /usr/gem/gems/liquid-4.0.3/lib/liquid/block_body.rb:103:in `render_node_to_output'
  /usr/gem/gems/liquid-4.0.3/lib/liquid/block_body.rb:91:in `render'
  /usr/gem/gems/liquid-4.0.3/lib/liquid/tags/for.rb:160:in `block (2 levels) in render_segment'
  /usr/gem/gems/liquid-4.0.3/lib/liquid/tags/for.rb:158:in `each'
  /usr/gem/gems/liquid-4.0.3/lib/liquid/tags/for.rb:158:in `block in render_segment'
  /usr/gem/gems/liquid-4.0.3/lib/liquid/context.rb:123:in `stack'
  /usr/gem/gems/liquid-4.0.3/lib/liquid/tags/for.rb:150:in `render_segment'
  /usr/gem/gems/liquid-4.0.3/lib/liquid/tags/for.rb:79:in `render'
  /usr/gem/gems/liquid-4.0.3/lib/liquid/block_body.rb:103:in `render_node_to_output'
  /usr/gem/gems/liquid-4.0.3/lib/liquid/block_body.rb:82:in `render'
  /usr/gem/gems/liquid-4.0.3/lib/liquid/template.rb:208:in `block in render'
  /usr/gem/gems/liquid-4.0.3/lib/liquid/template.rb:242:in `with_profiling'
  /usr/gem/gems/liquid-4.0.3/lib/liquid/template.rb:207:in `render'
  /usr/gem/gems/liquid-4.0.3/lib/liquid/template.rb:220:in `render!'
  /usr/gem/gems/jekyll-3.8.7/lib/jekyll/liquid_renderer/file.rb:30:in `block (2 levels) in render!'
  /usr/gem/gems/jekyll-3.8.7/lib/jekyll/liquid_renderer/file.rb:42:in `measure_bytes'
  /usr/gem/gems/jekyll-3.8.7/lib/jekyll/liquid_renderer/file.rb:29:in `block in render!'
  /usr/gem/gems/jekyll-3.8.7/lib/jekyll/liquid_renderer/file.rb:49:in `measure_time'
  /usr/gem/gems/jekyll-3.8.7/lib/jekyll/liquid_renderer/file.rb:28:in `render!'
  /usr/gem/gems/jekyll-3.8.7/lib/jekyll/tags/include.rb:140:in `block in render'
  /usr/gem/gems/liquid-4.0.3/lib/liquid/context.rb:123:in `stack'
  /usr/gem/gems/jekyll-3.8.7/lib/jekyll/tags/include.rb:137:in `render'
  /usr/gem/gems/liquid-4.0.3/lib/liquid/block_body.rb:103:in `render_node_to_output'
  /usr/gem/gems/liquid-4.0.3/lib/liquid/block_body.rb:91:in `render'
  /usr/gem/gems/liquid-4.0.3/lib/liquid/template.rb:208:in `block in render'
  /usr/gem/gems/liquid-4.0.3/lib/liquid/template.rb:242:in `with_profiling'
  /usr/gem/gems/liquid-4.0.3/lib/liquid/template.rb:207:in `render'
  /usr/gem/gems/liquid-4.0.3/lib/liquid/template.rb:220:in `render!'
  /usr/gem/gems/jekyll-3.8.7/lib/jekyll/liquid_renderer/file.rb:30:in `block (2 levels) in render!'
  /usr/gem/gems/jekyll-3.8.7/lib/jekyll/liquid_renderer/file.rb:42:in `measure_bytes'
  /usr/gem/gems/jekyll-3.8.7/lib/jekyll/liquid_renderer/file.rb:29:in `block in render!'
  /usr/gem/gems/jekyll-3.8.7/lib/jekyll/liquid_renderer/file.rb:49:in `measure_time'
  /usr/gem/gems/jekyll-3.8.7/lib/jekyll/liquid_renderer/file.rb:28:in `render!'
  /usr/gem/gems/jekyll-3.8.7/lib/jekyll/renderer.rb:126:in `render_liquid'
  /usr/gem/gems/jekyll-3.8.7/lib/jekyll/renderer.rb:195:in `render_layout'
  /usr/gem/gems/jekyll-3.8.7/lib/jekyll/renderer.rb:158:in `place_in_layouts'
  /usr/gem/gems/jekyll-3.8.7/lib/jekyll/renderer.rb:88:in `render_document'
  /usr/gem/gems/jekyll-3.8.7/lib/jekyll/renderer.rb:62:in `run'
  /usr/gem/gems/jekyll-3.8.7/lib/jekyll/site.rb:479:in `render_regenerated'
  /usr/gem/gems/jekyll-3.8.7/lib/jekyll/site.rb:464:in `block (2 levels) in render_docs'
  /usr/gem/gems/jekyll-3.8.7/lib/jekyll/site.rb:463:in `each'
  /usr/gem/gems/jekyll-3.8.7/lib/jekyll/site.rb:463:in `block in render_docs'
  /usr/gem/gems/jekyll-3.8.7/lib/jekyll/site.rb:462:in `each_value'
  /usr/gem/gems/jekyll-3.8.7/lib/jekyll/site.rb:462:in `render_docs'
  /usr/gem/gems/jekyll-3.8.7/lib/jekyll/site.rb:191:in `render'
  /usr/gem/gems/jekyll-3.8.7/lib/jekyll/site.rb:71:in `process'
  /usr/gem/gems/jekyll-3.8.7/lib/jekyll/command.rb:28:in `process_site'
  /usr/gem/gems/jekyll-3.8.7/lib/jekyll/commands/build.rb:65:in `build'
  /usr/gem/gems/jekyll-3.8.7/lib/jekyll/commands/build.rb:36:in `process'
  /usr/gem/gems/jekyll-3.8.7/lib/jekyll/commands/build.rb:18:in `block (2 levels) in init_with_program'
  /usr/gem/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `block in execute'
  /usr/gem/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `each'
  /usr/gem/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `execute'
  /usr/gem/gems/mercenary-0.3.6/lib/mercenary/program.rb:42:in `go'
  /usr/gem/gems/mercenary-0.3.6/lib/mercenary.rb:19:in `program'
  /usr/gem/gems/jekyll-3.8.7/exe/jekyll:15:in `<top (required)>'
  /usr/gem/bin/jekyll:23:in `load'
  /usr/gem/bin/jekyll:23:in `<top (required)>'

Add support for images with reference-style URLs

Right now jekyll-figure strips <p> markup surrounding images with inline-style URLs:

![Image](/path/to/image.jpg)

It would be great to add support for images with reference-style URLs:

![Image][image-path]

[image-path]: /path/to/image.jpg

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.