mirror of
https://github.com/NohamR/hugo-asm-shortcode.git
synced 2026-04-08 07:59:58 +00:00
Add IDA-style asm display mode
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{{- /* Assembly code block shortcode - supports multiple display modes */ -}}
|
||||
{{- /* Parameters:
|
||||
- mode: "raw" (syntax highlighted), "hex" (hex + asm), "full" (addr + hex + asm)
|
||||
- mode: "raw" (syntax highlighted), "hex" (hex + asm), "full" (addr + hex + asm), "ida" (IDA-style addr + asm)
|
||||
- arch: "x86" or "arm" (default: "x86")
|
||||
- capitalize: "true" to uppercase hex bytes and addresses (default: "false")
|
||||
*/ -}}
|
||||
@@ -86,5 +86,37 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{- else if eq $mode "ida" -}}
|
||||
{{- /* IDA-style: section:address label | instruction (format: SECTION:ADDR label | INSTRUCTION) */ -}}
|
||||
<div class="highlight">
|
||||
<div class="asm-ida">
|
||||
<pre tabindex="0" class="chroma"><code>{{- range split $content "\n" -}}
|
||||
{{- if . -}}
|
||||
<span class="asm-line">
|
||||
{{- $parts := split . "|" -}}
|
||||
{{- if ge (len $parts) 2 -}}
|
||||
{{- /* Extract section:address and optional label */ -}}
|
||||
{{- $addrPart := index $parts 0 | strings.TrimSpace -}}
|
||||
{{- /* Extract instruction */ -}}
|
||||
{{- $instruction := index $parts 1 | strings.TrimSpace -}}
|
||||
{{- /* Optionally capitalize address */ -}}
|
||||
{{- if eq $capitalize "true" -}}
|
||||
{{- $addrPart = upper $addrPart -}}
|
||||
{{- end -}}
|
||||
{{- /* Apply syntax highlighting to instruction */ -}}
|
||||
{{- $lang := cond (eq $arch "arm") "armasm" "nasm" -}}
|
||||
{{- $highlighted := highlight $instruction $lang "" -}}
|
||||
{{- /* Strip wrapper divs from highlighted output */ -}}
|
||||
<span class="ida-address">{{ $addrPart }}</span><span class="ida-separator">|</span>{{ $highlighted | replaceRE "<div class=\"highlight\"><pre[^>]*><code[^>]*>" "" | replaceRE "</code></pre></div>" "" | safeHTML }}
|
||||
{{- else -}}
|
||||
{{ . }}
|
||||
{{- end -}}
|
||||
</span>
|
||||
{{- end -}}
|
||||
{{- end -}}</code></pre>
|
||||
<button class="copy-code">copy</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{- end -}}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user