Separate figure and code shortcodes
This commit is contained in:
10
README.md
10
README.md
@@ -408,11 +408,7 @@ Parameters: None.
|
||||
The `paige/code` shortcode provides a figure with code.
|
||||
|
||||
```
|
||||
{{< paige/code
|
||||
caption="My caption"
|
||||
lang="html"
|
||||
options="linenos=true"
|
||||
>}}
|
||||
{{< paige/code lang="html" options="linenos=true" >}}
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<body>
|
||||
@@ -427,16 +423,12 @@ Inner content: Required. String. The code.
|
||||
Parameters:
|
||||
|
||||
<dl>
|
||||
<dt><code>caption</code></dt>
|
||||
<dd>Optional. String. Markdown. Descriptive text below the code.</dd>
|
||||
<dt><code>lang</code></dt>
|
||||
<dd>Optional. Position 0. String. Chroma language code. Defaults to <code>plaintext</code>. See the <a href="https://gohugo.io/content-management/syntax-highlighting/#list-of-chroma-highlighting-languages">codes</a>.</dd>
|
||||
<dt><code>options</code></dt>
|
||||
<dd>Optional. String. Hugo highlight options. See the <a href="https://gohugo.io/content-management/syntax-highlighting/#highlight-shortcode">options</a>.</dd>
|
||||
</dl>
|
||||
|
||||
It has the other parameters of the `paige/figure` shortcode.
|
||||
|
||||
### Image
|
||||
|
||||
The `paige/image` shortcode provides a figure with an image.
|
||||
|
@@ -11,6 +11,8 @@ Paige provides a `paige/code` shortcode for displaying code.
|
||||
|
||||
<!--more-->
|
||||
|
||||
## Basic
|
||||
|
||||
Code:
|
||||
|
||||
```go-text-template
|
||||
@@ -77,12 +79,12 @@ Result:
|
||||
--XXXXXXXXXXXXXXXXXX-
|
||||
{{< /paige/code >}}
|
||||
|
||||
---
|
||||
## Lang parameter
|
||||
|
||||
Code:
|
||||
|
||||
```go-text-template
|
||||
{{</* paige/code lang="c" options="linenos=true,hl_lines=10" */>}}
|
||||
{{</* paige/code lang="c" */>}}
|
||||
float Q_rsqrt( float number )
|
||||
{
|
||||
long i;
|
||||
@@ -103,7 +105,7 @@ float Q_rsqrt( float number )
|
||||
|
||||
Result:
|
||||
|
||||
{{< paige/code lang="c" options="linenos=true,hl_lines=10" >}}
|
||||
{{< paige/code lang="c" >}}
|
||||
float Q_rsqrt( float number )
|
||||
{
|
||||
long i;
|
||||
@@ -120,3 +122,68 @@ float Q_rsqrt( float number )
|
||||
return y;
|
||||
}
|
||||
{{< /paige/code >}}
|
||||
|
||||
|
||||
## Options parameter
|
||||
|
||||
Code:
|
||||
|
||||
```go-text-template
|
||||
{{</* paige/code options="linenos=true,hl_lines=10" */>}}
|
||||
float Q_rsqrt( float number )
|
||||
{
|
||||
long i;
|
||||
float x2, y;
|
||||
const float threehalfs = 1.5F;
|
||||
|
||||
x2 = number * 0.5F;
|
||||
y = number;
|
||||
i = * ( long * ) &y;
|
||||
i = 0x5f3759df - ( i >> 1 );
|
||||
y = * ( float * ) &i;
|
||||
y = y * ( threehalfs - ( x2 * y * y ) );
|
||||
|
||||
return y;
|
||||
}
|
||||
{{</* /paige/code */>}}
|
||||
```
|
||||
|
||||
Result:
|
||||
|
||||
{{< paige/code options="linenos=true,hl_lines=10" >}}
|
||||
float Q_rsqrt( float number )
|
||||
{
|
||||
long i;
|
||||
float x2, y;
|
||||
const float threehalfs = 1.5F;
|
||||
|
||||
x2 = number * 0.5F;
|
||||
y = number;
|
||||
i = * ( long * ) &y;
|
||||
i = 0x5f3759df - ( i >> 1 );
|
||||
y = * ( float * ) &i;
|
||||
y = y * ( threehalfs - ( x2 * y * y ) );
|
||||
|
||||
return y;
|
||||
}
|
||||
{{< /paige/code >}}
|
||||
|
||||
## Figure
|
||||
|
||||
Code:
|
||||
|
||||
```go-text-template
|
||||
{{</* paige/figure caption="Quine" */>}}
|
||||
{{</* paige/code options="linenos=true,hl_lines=10" */>}}
|
||||
q = 'q = %r; print(q %% q)'; print(q % q)
|
||||
{{</* /paige/code */>}}
|
||||
{{</* /paige/figure */>}}
|
||||
```
|
||||
|
||||
Result:
|
||||
|
||||
{{< paige/figure caption="Quine" >}}
|
||||
{{< paige/code lang="python" >}}
|
||||
q = 'q = %r; print(q %% q)'; print(q % q)
|
||||
{{< /paige/code >}}
|
||||
{{< /paige/figure >}}
|
||||
|
@@ -1,27 +1,4 @@
|
||||
{{ $caption := .Get "caption" }}
|
||||
{{ $float := .Get "float" }}
|
||||
{{ $height := .Get "height" }}
|
||||
{{ $horizontal := .Get "horizontal" }}
|
||||
{{ $lang := .Get 0 | default (.Get "lang") | default "plaintext" }}
|
||||
{{ $maxwidth := .Get "maxwidth" }}
|
||||
{{ $number := .Get "number" }}
|
||||
{{ $numbered := .Get "numbered" }}
|
||||
{{ $options := .Get "options" }}
|
||||
{{ $vertical := .Get "vertical" }}
|
||||
{{ $width := .Get "width" }}
|
||||
|
||||
{{ $content := highlight (.Inner | replaceRE "^\n" "") $lang $options }}
|
||||
|
||||
{{ partial "paige/figure.html" (dict
|
||||
"caption" $caption
|
||||
"content" $content
|
||||
"float" $float
|
||||
"gap" 2
|
||||
"height" $height
|
||||
"horizontal" $horizontal
|
||||
"maxwidth" $maxwidth
|
||||
"number" $number
|
||||
"numbered" $numbered
|
||||
"vertical" $vertical
|
||||
"width" $width
|
||||
) }}
|
||||
<div class="paige-code">{{ highlight (.Inner | replaceRE "^\n" "") $lang $options }}</div>
|
||||
|
Reference in New Issue
Block a user