aciccarello / ciccarello.me

Personal website hosted at https://www.ciccarello.me
2 stars 1 forks source link

Use plugin to format images #18

Open aciccarello opened 4 years ago

aciccarello commented 4 years ago

The current include for images makes markdown editing harder. I would prefer to use the title option of markdown links as the caption. By using a plugin to re-write the image tag, we could red the title attibute and use that in the output. That still leaves the width formatting (full width, float), however some markdown processors allow a {:attrName="attrValue"} syntax which adds modifiers to the image. We could use this to pass the values. One complication is that we want to support markdown in the caption.

Current syntax

{% include image.html
    file="/assets/img/peru-andean-cock-of-the-rock.jpg"
    alt="bird with a bright orange body and head, black wings and a gray back"
    caption="Andean cock-of-the-rock -- [Photo by Jerry Thompson](https://commons.wikimedia.org/wiki/File:Rupicola_peruviana_%28male%29\_-San_Diego_Zoo-8a.jpg) [[CC BY 2.0](https://creativecommons.org/licenses/by/2.0)]"
    display="float"
%}

Desired syntax

![bird with a bright orange body and head, black wings and a gray back](/assets/img/peru-andean-cock-of-the-rock.jpg "Andean cock-of-the-rock -- [Photo by Jerry Thompson](https://commons.wikimedia.org/wiki/File:Rupicola_peruviana_%28male%29\_-San_Diego_Zoo-8a.jpg) [[CC BY 2.0](https://creativecommons.org/licenses/by/2.0)]"){:display="float"}

![there are options to split onto multiple lines](
  /assets/img/peru-andean-cock-of-the-rock.jpg
  "Andean cock-of-the-rock -- [Photo by Jerry Thompson](https://commons.wikimedia.org/wiki/File:Rupicola_peruviana_%28male%29\_-San_Diego_Zoo-8a.jpg) [[CC BY 2.0](https://creativecommons.org/licenses/by/2.0)]"
){:display="float"}

Expected Output

<figure class="post-img--float">
    <img src="/assets/img/peru-andean-cock-of-the-rock.jpg" alt="bird with a bright orange body and head, black wings and a gray back">
    <figcaption class="mdc-typography--caption">
        Andean cock-of-the-rock – <a href="https://commons.wikimedia.org/wiki/File:Rupicola_peruviana_%28male%29\_-San_Diego_Zoo-8a.jpg">Photo by Jerry Thompson</a> [<a href="https://creativecommons.org/licenses/by/2.0">CC BY 2.0</a>]

    </figcaption>
</figure>

Blocked by aciccarello/aciccarello.github.io#30

References

aciccarello commented 4 years ago

Could be done via a markdown plugin instead of eleventy. markdown-it-implicit-figures seems like an option.

aciccarello commented 2 years ago

This would probably involve implementing arve0/markdown-it-implicit-figures#20 or using markdown-it-image-figures

aciccarello commented 2 years ago

An alternative would to use a paired shortcode to combine markdown and liquid.

Advantage

Disadvantage

{% image
    "Andean cock-of-the-rock -- [Photo by Jerry Thompson](https://commons.wikimedia.org/wiki/File:Rupicola_peruviana_%28male%29\_-San_Diego_Zoo-8a.jpg) [[CC BY 2.0](https://creativecommons.org/licenses/by/2.0)]"
    "float"
%}
![bird with a bright orange body and head, black wings and a gray back](/assets/img/peru-andean-cock-of-the-rock.jpg)
{% endimage %}
aciccarello commented 3 weeks ago

Wrong issue number...