
Permalinks for fenced code blocks
Another quick Jekyll plugin - https://github.com/jaygooby/jekyll-permalink-for-fenced-code-blocks.git which creates unique IDs for your fenced code blocks so you can link to them or easily hook ClipboardJS.
A fenced code block like:
```
echo "wat"
```
will render in html as
<code id="code-1">
echo "wat"
</code>
And then you can link to it using <a href="#code-1">
or add a ClipboardJS hook using the #code-1
ID attribute.
Usage
Drop permalink-for-fenced-code-blocks.rb
into your Jekyll _plugins
folder. By default, you’ll also get a <button>
element for each code block, that looks like:
<button class="copy-code" data-clipboard-target="#code-1">copy to clipboard</button>
which you can hook up with ClipboardJS data-clipboard-target
. If you don’t want this button
element, start Jekyll like this:
NO_COPY_BUTTON=1 jekyll serve -w
You should be able to see it in action in any of the above code blocks.
All links, in order of mention:
- Jekyll: https://jekyllrb.com/
- https://github.com/jaygooby/jekyll-permalink-for-fenced-code-blocks.git: https://github.com/jaygooby/jekyll-permalink-for-fenced-code-blocks
- ClipboardJS: https://clipboardjs.com
- : #code-1
- ClipboardJS data-clipboard-target: https://clipboardjs.com/#usage
Recent posts:
- Patch for aarch64 (aka arm64) openssl 1.0.2 'relocation R_AARCH64_PREL64 against symbol OPENSSL_armcap_P error'
- TIL: the `NO_COLOR` informal standard to suppress ANSI colour escape codes
- Copy the contents of a branch into an existing git branch without merging
- Adding search to a static Jekyll site using pagefind
- asdf, python and automatically enabling virtual envs