Skip to content

Commit

Permalink
Add unescape param to code shortcode
Browse files Browse the repository at this point in the history
  • Loading branch information
willfaught committed Jul 21, 2024
1 parent 972356e commit 25b9e4b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,8 @@ The `paige/code` shortcode provides highlighted code.
```
{{< paige/code
lang=""
options="" >}}
options=""
unescape=false >}}
{{< /paige/code >}}
```
Expand All @@ -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.
Expand Down
32 changes: 32 additions & 0 deletions exampleSite/content/shortcodes/code.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions layouts/shortcodes/paige/code.html
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit 25b9e4b

Please sign in to comment.