Ver código fonte

feat: add ID to figures to make them linkable (#1475)

Generates linkable IDs for figures by anchorizing the caption and namespacing the figure ID by prefixing it with `figure-` to help prevent conflicts with other existing IDs.
beckerjohannes 5 anos atrás
pai
commit
f9794e9f09
1 arquivos alterados com 1 adições e 1 exclusões
  1. 1 1
      layouts/shortcodes/figure.html

+ 1 - 1
layouts/shortcodes/figure.html

@@ -18,7 +18,7 @@
 {{/* Get caption. Support legacy `title` option. */}}
 {{ $caption := .Get "title" | default (.Get "caption") | default "" }}
 
-<figure{{ with .Get "class" }} class="{{.}}"{{ end }}>
+<figure{{ with .Get "class" }} class="{{.}}"{{ end }} {{ with $caption }}id="figure-{{ anchorize . }}"{{ end }}>
 
 {{ if $lightbox }}
   <a data-fancybox="{{$group}}" href="{{$image_src}}" {{ with $caption }}data-caption="{{ .|markdownify|emojify }}"{{ end }}>