diff --git a/layouts/shortcodes/codecaption.html b/layouts/shortcodes/codecaption.html
index 390fb0e..3560284 100644
--- a/layouts/shortcodes/codecaption.html
+++ b/layouts/shortcodes/codecaption.html
@@ -1,6 +1,14 @@
-{{ $codeIndex := (.Page.Scratch.Get "codeIndex") }}
-
- Code snippet {{ $codeIndex }}{{with .Get "lang"}} ({{ . }}){{end}}:
+{{- $codeIndex := (.Page.Scratch.Get "codeIndex") -}}
+{{- $id := (printf `code-%d` $codeIndex) -}}
+{{ with .Parent }}
+ {{- with .Get "id" -}}
+ {{- $id = . -}}
+ {{- end -}}
+{{- end -}}
+
+
+ Code snippet {{ $codeIndex }}{{with .Get "lang"}} ({{ . }}){{ end -}}
+ :
{{ .Inner | markdownify | safeHTML }}
{{- .Page.Scratch.Set "codeIndex" (add 1 $codeIndex) -}}
diff --git a/layouts/shortcodes/codefigure.html b/layouts/shortcodes/codefigure.html
index d12efee..ebf0138 100644
--- a/layouts/shortcodes/codefigure.html
+++ b/layouts/shortcodes/codefigure.html
@@ -1,3 +1,12 @@
-