Add ability to style images via the URL (fix #22)

This commit is contained in:
David Lapshin
2024-05-12 18:13:28 +03:00
parent a697ff01bd
commit 703bc99a0d
3 changed files with 20 additions and 13 deletions

View File

@ -170,13 +170,21 @@ Variables should be comma-separated and be inside the brackets.
``` ```
{{ image(url="https://i1.theportalwiki.net/img/2/23/Ashpd_blueprint.jpg", alt="Portal Gun blueprint", no_hover=true) }} {{ image(url="https://i1.theportalwiki.net/img/2/23/Ashpd_blueprint.jpg", alt="Portal Gun blueprint", no_hover=true) }}
<figcaption>Image with an alt text and without zoom on hover</figcaption> <figcaption>Image with an alt text and without zoom on hover</figcaption>
{{ image(url="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg", url_min="https://upload.wikimedia.org/wikipedia/commons/3/38/JPEG_example_JPG_RIP_010.jpg", alt="The gravestone of J.P.G.", no_hover=true) }} {{ image(url="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg", url_min="https://upload.wikimedia.org/wikipedia/commons/3/38/JPEG_example_JPG_RIP_010.jpg", alt="The gravestone of J.P.G.", no_hover=true) }}
<figcaption>Image with compressed version, an alt text, and without zoom on hover</figcaption> <figcaption>Image with compressed version, an alt text, and without zoom on hover</figcaption>
Alternatively, you can append the following url anchors. It can be more handy in some cases, e.g such images will render normally in any Markdown editor, opposed to the Zola shortcodes.
- `#full`: Forces image/video to be full-width.
- `#pixels`: Uses nearest neighbor algorithm for scaling, useful for keeping pixel-art sharp.
- `#transparent`: Removes rounded corners and shadow, useful for transparent images.
- `#no-hover`: Removes zoom on hover.
![Toolbx header image](https://containertoolbx.org/assets/toolbx.gif#full#pixels#transparent#no-hover)
<figcaption>Full-width image with an alt text, pixel-art rendering, no shadow and rounded corners, and no zoom on hover</figcaption>
#### Video #### Video
Same as images, but with a few differences: `no_hover` and `url_min` are not available. Same as images, but with a few differences: `no_hover` and `url_min` are not available.
@ -186,7 +194,6 @@ Same as images, but with a few differences: `no_hover` and `url_min` are not ava
``` ```
{{ video(url="https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.webm", alt="Red flower wakes up") }} {{ video(url="https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.webm", alt="Red flower wakes up") }}
<figcaption>WebM video example from MDN</figcaption> <figcaption>WebM video example from MDN</figcaption>
#### CRT #### CRT
@ -228,16 +235,14 @@ Alright, this one doesn't simplify anything, it just adds a CRT-like effect arou
## Captions ## Captions
Media can have additional text description using the `<figcaption>` HTML tag. Media can have additional text description using the `<figcaption>` HTML tag directly under it.
```markdown ```markdown
![Image](image.pmg) ![The Office](https://i.ibb.co/MPDJRsT/ImMAXM3.png)
<figcaption>The image caption</figcaption> <figcaption>The image caption</figcaption>
``` ```
![The Office](https://i.ibb.co/MPDJRsT/ImMAXM3.png) ![The Office](https://i.ibb.co/MPDJRsT/ImMAXM3.png)
<figcaption>The Office where Stanley works, it has yellow floor and beige walls</figcaption> <figcaption>The Office where Stanley works, it has yellow floor and beige walls</figcaption>
## Accordion ## Accordion

View File

@ -254,7 +254,6 @@ mark {
} }
figcaption { figcaption {
display: block;
color: var(--fg-muted-4); color: var(--fg-muted-4);
font-size: 0.8rem; font-size: 0.8rem;
text-align: center; text-align: center;

View File

@ -2,11 +2,11 @@ img {
transition-duration: var(--transition-longer); transition-duration: var(--transition-longer);
transition-property: transform, box-shadow, border-radius; transition-property: transform, box-shadow, border-radius;
&:not(.no-hover) { &:not(.no-hover, &[src*="#no-hover"]) {
cursor: zoom-in; cursor: zoom-in;
} }
&:not(.no-hover):hover { &:not(.no-hover, &[src*="#no-hover"]):hover {
transform: scale(1.1); transform: scale(1.1);
box-shadow: var(--shadow-raised); box-shadow: var(--shadow-raised);
border-radius: 0; border-radius: 0;
@ -21,15 +21,18 @@ video {
border-radius: var(--rounded-corner); border-radius: var(--rounded-corner);
max-width: 100%; max-width: 100%;
&.full { &.full,
&[src*="#full"] {
width: 100%; width: 100%;
} }
&.pixels { &.pixels,
&[src*="#pixels"] {
image-rendering: pixelated; image-rendering: pixelated;
} }
&.transparent { &.transparent,
&[src*="#transparent"] {
box-shadow: none; box-shadow: none;
border-radius: 0; border-radius: 0;