From 435b7f8a3c8543d8047e761e9a8237d862349f5f Mon Sep 17 00:00:00 2001 From: Nicola Belluti Date: Thu, 10 Sep 2026 15:31:38 +0200 Subject: [PATCH] Added `encoding-bits` field to `instruction` shortcode --- layouts/shortcodes/instruction.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/layouts/shortcodes/instruction.md b/layouts/shortcodes/instruction.md index 0e9b44f..d023373 100644 --- a/layouts/shortcodes/instruction.md +++ b/layouts/shortcodes/instruction.md @@ -13,6 +13,11 @@ formats, encoding diagram, high-level operation, and usage examples. @param {string} encoding-dark Optional dark mode variant of the encoding diagram. If set, `encoding` is only shown in light mode and this is shown in dark mode. +@param {string} encoding-bits Optional accessible bit-level breakdown of the + encoding, for screen readers and crawlers. Use + lines of "bits:value:meaning", one per row. + Separate multiple variants with a line + containing only "---". @param {string} operation High-level operation, typically pseudo-C. Use a backtick-quoted string for multiple lines. @param {string} examples Usage examples in LC-2 assembly. Use a @@ -54,6 +59,7 @@ result is negative, zero, or positive. {{- $formats := .Get "formats" -}} {{- $encoding := .Get "encoding" -}} {{- $encodingDark := .Get "encoding-dark" -}} +{{- $encodingBits := .Get "encoding-bits" -}} {{- $operation := .Get "operation" -}} {{- $examples := .Get "examples" -}} {{- $description := .Inner -}} @@ -88,6 +94,24 @@ Sligtly edited version of Hextra's `details` shortcode {{ $mnemonic }} instruction encoding {{ end }} +{{ if $encodingBits }} +{{ $variants := (split $encodingBits "---") }} +{{ $html := printf "
" ($mnemonic | lower) }} +{{ range $variantIndex, $variant := $variants }} + {{ $html = print $html "" }} + {{ $html = print $html (printf "" $mnemonic (cond (gt (len $variants) 1) (printf ", variant %d" (add $variantIndex 1)) "")) }} + {{ $html = print $html "" }} + {{ $html = print $html "" }} + {{ range (split (trim $variant "\n") "\n") }} + {{ $parts := split . "|" }} + {{ $html = print $html (printf "" (index $parts 0) (index $parts 1) (index $parts 2)) }} + {{ end }} + {{ $html = print $html "
%s encoding%s
BitsValueMeaning
%s%s%s
" }} +{{ end }} +{{ $html = print $html "
" }} +{{ $html | safeHTML }} +{{ end }} +

Operation

```c