Add unescape param to code shortcode

master
Will Faught 12 months ago
parent 972356e7aa
commit 25b9e4b43d

@ -431,7 +431,8 @@ The `paige/code` shortcode provides highlighted code.
```
{{< paige/code
lang=""
options="" >}}
options=""
unescape=false >}}
{{< /paige/code >}}
```
@ -443,6 +444,8 @@ Parameters:
<dd>Optional. Position 0. String. Chroma <a href="https://gohugo.io/content-management/syntax-highlighting/#list-of-chroma-highlighting-languages">language code</a>. Default is <code>plaintext</code>.</dd>
<dt><code>options</code></dt>
<dd>Optional. String. Hugo <a href="https://gohugo.io/content-management/syntax-highlighting/#highlight-shortcode">highlight options</a>.</dd>
<dt><code>unescape</code></dt>
<dd>Optional. Boolean. Whether to reverse the HTML escaping in the body. Useful for when the request shortcode is used in the body.</dd>
</dl>
Body: Required. String. The code.

@ -167,6 +167,38 @@ float Q_rsqrt( float number )
}
{{< /paige/code >}}
## Unescape parameter
Code:
```go-html-template
{{</* paige/code unescape=false */>}}
{{</* paige/request "[...]" */>}}
{{</* /paige/code */>}}
```
Result:
{{< paige/code unescape=false >}}
{{< paige/request "https://gist.githubusercontent.com/willfaught/fe6f6a8b9715e70112b6894935ecbecd/raw/64f41b7eb47ed5a60172217f8ba3868c23f69d21/qrsqrt.c" >}}
{{< /paige/code >}}
---
Code:
```go-html-template
{{</* paige/code unescape=true */>}}
{{</* paige/request "[...]" */>}}
{{</* /paige/code */>}}
```
Result:
{{< paige/code unescape=true >}}
{{< paige/request "https://gist.githubusercontent.com/willfaught/fe6f6a8b9715e70112b6894935ecbecd/raw/64f41b7eb47ed5a60172217f8ba3868c23f69d21/qrsqrt.c" >}}
{{< /paige/code >}}
## Figure
Code:

@ -1,9 +1,14 @@
{{ $content := .InnerDeindent | strings.TrimLeft "\f\n\r\v" | strings.TrimRight "\f\n\r\t\v " }}
{{ $lang := .Get 0 | default (.Get "lang") | default "plaintext" }}
{{ $options := .Get "options" }}
{{ $unescape := .Get "unescape" }}
{{ if not $content }}
{{ errorf "layouts/shortcodes/paige/code.html: no content" }}
{{ end }}
{{ if $unescape }}
{{ $content = htmlUnescape $content }}
{{ end }}
<div class="paige-code">{{ highlight $content $lang $options }}</div>

Loading…
Cancel
Save