{{- /* Assembly code block shortcode - supports multiple display modes */ -}} {{- /* Parameters: - mode: "raw" (syntax highlighted), "hex" (hex + asm), "full" (addr + hex + asm) - arch: "x86" or "arm" (default: "x86") - capitalize: "true" to uppercase hex bytes and addresses (default: "false") */ -}} {{- $mode := .Get "mode" | default "raw" -}} {{- $arch := .Get "arch" | default "x86" -}} {{- $capitalize := .Get "capitalize" | default "false" -}} {{- $content := .Inner | strings.TrimSpace -}}
{{- if eq $mode "raw" -}} {{- /* Raw assembly with syntax highlighting only */ -}}
{{- if eq $arch "x86" -}} {{- highlight $content "nasm" "" -}} {{- else if eq $arch "arm" -}} {{- highlight $content "armasm" "" -}} {{- else -}} {{- highlight $content "asm" "" -}} {{- end -}}
{{- else if eq $mode "hex" -}} {{- /* Hex bytes + assembly on same line (format: HEX | INSTRUCTION) */ -}}
{{- range split $content "\n" -}}
{{- if . -}}

  {{- $parts := split . "|" -}}
  {{- if eq (len $parts) 2 -}}
    {{- /* Extract and optionally capitalize hex bytes */ -}}
    {{- $hexBytes := index $parts 0 | strings.TrimSpace -}}
    {{- if eq $capitalize "true" -}}
      {{- $hexBytes = upper $hexBytes -}}
    {{- end -}}
    {{- /* Extract instruction and apply syntax highlighting */ -}}
    {{- $instruction := index $parts 1 | strings.TrimSpace -}}
    {{- $lang := cond (eq $arch "arm") "armasm" "nasm" -}}
    {{- $highlighted := highlight $instruction $lang "" -}}
    {{- /* Strip wrapper divs from highlighted output */ -}}
{{ $hexBytes }}{{ $highlighted | replaceRE "
]*>]*>" "" | replaceRE "
" "" | safeHTML }} {{- else -}} {{ . }} {{- end -}} {{- end -}} {{- end -}}
{{- else if eq $mode "full" -}} {{- /* Address + hex bytes + assembly (format: ADDRESS | HEX | INSTRUCTION) */ -}}
{{- range split $content "\n" -}}
{{- if . -}}

  {{- $parts := split . "|" -}}
  {{- if eq (len $parts) 3 -}}
    {{- /* Extract address and hex bytes */ -}}
    {{- $address := index $parts 0 | strings.TrimSpace -}}
    {{- $hexBytes := index $parts 1 | strings.TrimSpace -}}
    {{- /* Optionally capitalize address and hex bytes */ -}}
    {{- if eq $capitalize "true" -}}
      {{- $address = upper $address -}}
      {{- $hexBytes = upper $hexBytes -}}
    {{- end -}}
    {{- /* Extract instruction and apply syntax highlighting */ -}}
    {{- $instruction := index $parts 2 | strings.TrimSpace -}}
    {{- $lang := cond (eq $arch "arm") "armasm" "nasm" -}}
    {{- $highlighted := highlight $instruction $lang "" -}}
    {{- /* Strip wrapper divs from highlighted output */ -}}
{{ $address }}{{ $hexBytes }}{{ $highlighted | replaceRE "
]*>]*>" "" | replaceRE "
" "" | safeHTML }} {{- else -}} {{ . }} {{- end -}} {{- end -}} {{- end -}}
{{- end -}}