diff --git a/README.md b/README.md
index aaadda0ec3..173819fb47 100644
--- a/README.md
+++ b/README.md
@@ -25,7 +25,7 @@ The Relearn theme is a fork of the great [Learn theme](https://github.com/matcor
- Predefined light, dark and color variants
- [User selectable variants](https://mcshelby.github.io/hugo-theme-relearn/basics/customization#multiple-variants)
- [Stylesheet generator](https://mcshelby.github.io/hugo-theme-relearn/basics/generator)
- - [Configurable syntax highlighting](https://mcshelby.github.io/hugo-theme-relearn/cont/syntaxhighlight)
+ - [Configurable syntax highlighting](https://mcshelby.github.io/hugo-theme-relearn/shortcodes/highlight)
- **Unique theme features**
- [Print whole chapters or even the complete site](https://mcshelby.github.io/hugo-theme-relearn/basics/configuration#activate-print-support)
- In page search
diff --git a/exampleSite/config/_default/config.toml b/exampleSite/config/_default/config.toml
index 27c3c30640..efaa673f13 100644
--- a/exampleSite/config/_default/config.toml
+++ b/exampleSite/config/_default/config.toml
@@ -47,18 +47,20 @@ title = "Hugo Relearn Documentation"
[markup]
[markup.highlight]
+ # line numbers in a table layout will shift if code is wrapping, so better
+ # not use it; visually both layouts have the same look and behavior
+ lineNumbersInTable = false
+
# if `guessSyntax = true`, there will be no unstyled code even if no language
# was given BUT Mermaid and Math codefences will not work anymore! So this is a
# mandatory setting for your site if you want to use Mermaid or Math codefences
guessSyntax = false
- # here in this showcase we use our own modified chroma syntax highlightning style
- # which is imported in theme-relearn-light.css / theme-relearn-dark.css;
+ # the shipped variants come with their own modified chroma syntax highlightning
+ # style which is imported in theme-relearn-light.css, theme-relearn-dark.css, etc.;
# if you want to use a predefined style instead:
- # - remove the following `noClasses`
- # - set the following `style` to a predefined style name
- # - remove the `@import` of the self-defined chroma stylesheet from your CSS files
- # (here eg.: theme-relearn-light.css / theme-relearn-dark.css)
+ # - remove `noClasses` or set `noClasses = true`
+ # - set `style` to a predefined style name
noClasses = false
# style = "tango"
diff --git a/exampleSite/content/_index.en.md b/exampleSite/content/_index.en.md
index 486d3bc61b..bad1e4d24c 100644
--- a/exampleSite/content/_index.en.md
+++ b/exampleSite/content/_index.en.md
@@ -28,7 +28,7 @@ The theme is a fork of the great [Learn theme](https://github.com/matcornic/hugo
- Predefined light, dark and color variants
- [User selectable variants]({{%relref "basics/customization#multiple-variants" %}})
- [Stylesheet generator]({{%relref "basics/generator" %}})
- - [Configurable syntax highlighting]({{%relref "cont/syntaxhighlight" %}})
+ - [Configurable syntax highlighting]({{%relref "shortcodes/highlight" %}})
- **Unique theme features**
- [Print whole chapters or even the complete site]({{%relref "basics/configuration#activate-print-support" %}})
- In page search
diff --git a/exampleSite/content/basics/migration/_index.en.md b/exampleSite/content/basics/migration/_index.en.md
index 07a420b2b7..f7f28003e1 100644
--- a/exampleSite/content/basics/migration/_index.en.md
+++ b/exampleSite/content/basics/migration/_index.en.md
@@ -18,6 +18,14 @@ This document shows you what's new in the latest release. For a detailed list of
---
+## 5.17.0 (2023-06-20)
+
+- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} The new [`highlight` shortcode]({{% relref "shortcodes/highlight" %}}) replaces Hugo's default implementation and is fully compatible. So you don't need to change anything.
+
+ In addition it offers some extensions. Currently only the `wrap` extension option is provided to control whether a code block should be wrapped or scrolled if to long to fit.
+
+---
+
## 5.16.0 (2023-06-10)
- {{% badge style="note" title=" " %}}Change{{% /badge %}} The theme now provides warnings for deprecated or now unsupported features. The warnings include hints how to fix them and an additional link to the documenation.
diff --git a/exampleSite/content/cont/markdown.en.md b/exampleSite/content/cont/markdown.en.md
index a3358b22b4..07d2694cd1 100644
--- a/exampleSite/content/cont/markdown.en.md
+++ b/exampleSite/content/cont/markdown.en.md
@@ -323,7 +323,7 @@ If you want to gain more control of your code block you can enclose your code by
In GFM (GitHub Flavored Markdown) you can also add a language specifier directly after the opening fence, ` ```js `, and syntax highlighting will automatically be applied according to the selected language in the rendered HTML.
-See [Code Highlighting]({{% relref "syntaxhighlight" %}}) for additional documentation.
+See [Code Highlighting]({{% relref "shortcodes/highlight" %}}) for additional documentation.
````plaintext
```js
diff --git a/exampleSite/content/cont/syntaxhighlight.en.md b/exampleSite/content/cont/syntaxhighlight.en.md
deleted file mode 100644
index d881e7f6af..0000000000
--- a/exampleSite/content/cont/syntaxhighlight.en.md
+++ /dev/null
@@ -1,66 +0,0 @@
-+++
-title = "Code highlighting"
-weight = 4
-+++
-
-The Relearn theme uses [Hugo's built-in syntax highlighting](https://gohugo.io/content-management/syntax-highlighting/) for code.
-
-## Markdown syntax
-
-Wrap the code block with three backticks and the name of the language. Highlight will try to auto detect the language if one is not provided.
-
-
-````plaintext
-```json
-[
- {
- "title": "apples",
- "count": [12000, 20000],
- "description": {"text": "...", "sensitive": false}
- },
- {
- "title": "oranges",
- "count": [17500, null],
- "description": {"text": "...", "sensitive": false}
- }
-]
-```
-````
-
-
-Renders to:
-
-```json
-[
- {
- "title": "apples",
- "count": [12000, 20000],
- "description": {"text": "...", "sensitive": false}
- },
- {
- "title": "oranges",
- "count": [17500, null],
- "description": {"text": "...", "sensitive": false}
- }
-]
-```
-
-## Supported languages
-
-Hugo comes with a [remarkable list](https://gohugo.io/content-management/syntax-highlighting/#list-of-chroma-highlighting-languages) of supported languages.
-
-## Recommended configuration
-
-You can choose a color theme from the [list of supported themes](https://xyproto.github.io/splash/docs/all.html) and add it in your `config.toml`
-
-````toml
-[markup]
- [markup.highlight]
- # if `guessSyntax = true`, there will be no unstyled code even if no language
- # was given BUT Mermaid and Math codefences will not work anymore! So this is a
- # mandatory setting for your site if you want to use Mermaid or Math codefences
- guessSyntax = false
-
- # choose a color theme or create your own
- style = "base16-snazzy"
-````
diff --git a/exampleSite/content/cont/syntaxhighlight.pir.md b/exampleSite/content/cont/syntaxhighlight.pir.md
deleted file mode 100644
index 5478912939..0000000000
--- a/exampleSite/content/cont/syntaxhighlight.pir.md
+++ /dev/null
@@ -1,5 +0,0 @@
-+++
-title = "Code highlight'n"
-weight = 4
-+++
-{{< piratify >}}
\ No newline at end of file
diff --git a/exampleSite/content/shortcodes/highlight.en.md b/exampleSite/content/shortcodes/highlight.en.md
new file mode 100644
index 0000000000..d4e080eab8
--- /dev/null
+++ b/exampleSite/content/shortcodes/highlight.en.md
@@ -0,0 +1,186 @@
++++
+description = "Generate diagrams and flowcharts from text"
+title = "Highlight"
++++
+
+The `highlight` shortcode renders your code with a syntax highlighter.
+
+{{< highlight lineNos="table" type="py" wrap="true" >}}
+print("Hello World!")
+{{< /highlight >}}
+
+## Usage
+
+This shortcode is compatible with Hugo's [`highlight` shortcode](https://gohugo.io/content-management/syntax-highlighting/#highlight-shortcode) but offers some extensions.
+
+You can call it interchangeably in the same way as Hugo's own shortcode using positional parameter or by simply using codefences.
+
+You are free to also call this shortcode from your own partials. In this case it somewhat resemble Hugo's [`highlight` function](https://gohugo.io/functions/highlight/) syntax if you call this shortcode as a partial using compatiblity syntax.
+
+While the examples are using shortcodes with named parameter it is recommended to use codefences instead. This is because more and more other software supports codefences (eg. GitHub) and so your markdown becomes more portable.
+
+
+{{< tabs groupId="shortcode-parameter">}}
+{{% tab title="codefence" %}}
+
+````md
+```py { lineNos="table" wrap="true" }
+print("Hello World!")
+```
+````
+
+{{% /tab %}}
+{{% tab title="shortcode" %}}
+
+````go
+{{* highlight lineNos="table" type="py" wrap="true" */>}}
+print("Hello World!")
+{{* /highlight */>}}
+````
+
+{{% /tab %}}
+{{% tab title="shortcode (positional)" %}}
+
+````go
+{{* highlight py "lineNos=table,wrap=true" */>}}
+print("Hello World!")
+{{* /highlight */>}}
+````
+
+{{% /tab %}}
+{{% tab title="partial" %}}
+
+````go
+{{ partial "shortcodes/highlight.html" (dict
+ "context" .
+ "content" "print(\"Hello World!\")"
+ "lineNos" "table"
+ "type" "py"
+ "wrap" "true"
+)}}
+
+````
+
+{{% /tab %}}
+{{% tab title="partial (compat)" %}}
+
+````go
+{{ partial "shortcodes/highlight.html" (dict
+ "context" .
+ "content" "print(\"Hello World!\")"
+ "options" "lineNos=table,wrap=true"
+ "type" "py"
+)}}
+
+````
+
+{{% /tab %}}
+{{< /tabs >}}
+
+### Parameter
+
+| Name | Default | Notes |
+|:----------------------|:-----------------|:------------|
+| **type** | _<empty>_ | The language of the code to highlight. Choose from one of the [supported languages](https://gohugo.io/content-management/syntax-highlighting/#list-of-chroma-highlighting-languages). Case-insensitive. |
+| **wrap** | see notes | _Extension_. When `true` the content may wrap on long lines otherwise it will be scrollable.
The default value can be set in your `config.toml` and overwritten via frontmatter. [See below](#configuration). |
+| **options** | _<empty>_ | An optional, comma-separated list of zero or more [Hugo supported options](https://gohugo.io/functions/highlight/#options) as well as extension parameter from this table. |
+| _**<option>**_ | _<empty>_ | Any of [Hugo's supported options](https://gohugo.io/functions/highlight/#options). |
+| _**<content>**_ | _<empty>_ | Your code to highlight. |
+
+## Configuration
+
+Default values for [Hugo's supported options](https://gohugo.io/functions/highlight/#options) can be set via [goldmark settings](https://gohugo.io/getting-started/configuration-markup/#highlight) in your `config.toml`
+
+Default values for extension options can be set via params settings in your `config.toml` or be overwritten by frontmatter for each individual page.
+
+### Global Configuration File
+
+#### Recommended Settings
+
+````toml
+[markup]
+ [markup.highlight]
+ # line numbers in a table layout will shift if code is wrapping, so better
+ # use inline; besides that visually both layouts have the same look and behavior
+ lineNumbersInTable = false
+
+ # if `guessSyntax = true`, there will be no unstyled code even if no language
+ # was given BUT Mermaid and Math codefences will not work anymore! So this is a
+ # mandatory setting for your site if you want to use Mermaid or Math codefences
+ guessSyntax = false
+
+ # the shipped variants come with their own modified chroma syntax highlightning
+ # style which is imported in theme-relearn-light.css, theme-relearn-dark.css, etc.;
+ # if you want to use a predefined style instead:
+ # - remove `noClasses` or set `noClasses = true`
+ # - set `style` to a predefined style name
+ noClasses = false
+ # style = "tango"
+````
+
+#### Optional Settings
+
+````toml
+[params]
+ highlightWrap = true
+````
+
+### Page's Frontmatter
+
+````toml
++++
+highlightWrap = true
++++
+````
+
+## Examples
+
+### Line Numbers
+
+As mentioned above, line numbers in a `table` layout will shift if code is wrapping, so better use `inline`. To make things easier for you, set `lineNumbersInTable = false` in your `config.toml` and add `lineNos = true` when calling the shortcode instead of the specific values `table` or `inline`.
+
+````go
+{{* highlight lineNos="true" type="py" */>}}
+# Quicksort Python One-liner
+lambda L: [] if L==[] else qsort([x for x in L[1:] if x< L[0]]) + L[0:1] + qsort([x for x in L[1:] if x>=L[0]])
+# Some more stuff
+{{* /highlight */>}}
+````
+
+{{< highlight lineNos="true" type="py" >}}
+# Quicksort Python One-liner
+lambda L: [] if L==[] else qsort([x for x in L[1:] if x< L[0]]) + L[0:1] + qsort([x for x in L[1:] if x>=L[0]])
+# Some more stuff
+{{< /highlight >}}
+
+### With Wrap
+
+````go
+{{* highlight type="py" wrap="true" hl_lines="2" */>}}
+# Quicksort Python One-liner
+lambda L: [] if L==[] else qsort([x for x in L[1:] if x< L[0]]) + L[0:1] + qsort([x for x in L[1:] if x>=L[0]])
+# Some more stuff
+{{* /highlight */>}}
+````
+
+{{< highlight type="py" wrap="true" hl_lines="2" >}}
+# Quicksort Python One-liner
+lambda L: [] if L==[] else qsort([x for x in L[1:] if x< L[0]]) + L[0:1] + qsort([x for x in L[1:] if x>=L[0]])
+# Some more stuff
+{{< /highlight >}}
+
+### Without Wrap
+
+````go
+{{* highlight type="py" wrap="false" hl_lines="2" */>}}
+# Quicksort Python One-liner
+lambda L: [] if L==[] else qsort([x for x in L[1:] if x< L[0]]) + L[0:1] + qsort([x for x in L[1:] if x>=L[0]])
+# Some more stuff
+{{* /highlight */>}}
+````
+
+{{< highlight type="py" wrap="false" hl_lines="2">}}
+# Quicksort Python One-liner
+lambda L: [] if L==[] else qsort([x for x in L[1:] if x< L[0]]) + L[0:1] + qsort([x for x in L[1:] if x>=L[0]])
+# Some more stuff
+{{< /highlight >}}
diff --git a/exampleSite/content/shortcodes/highlight.pir.md b/exampleSite/content/shortcodes/highlight.pir.md
new file mode 100644
index 0000000000..5121bd2ca4
--- /dev/null
+++ b/exampleSite/content/shortcodes/highlight.pir.md
@@ -0,0 +1,5 @@
++++
+descrption = "Beaut'fl math and chemical formulae"
+title = "Highlight"
++++
+{{< piratify true >}}
\ No newline at end of file
diff --git a/exampleSite/content/tests/code/_index.en.md b/exampleSite/content/tests/code/_index.en.md
index 6bef0c0229..52913e0acf 100644
--- a/exampleSite/content/tests/code/_index.en.md
+++ b/exampleSite/content/tests/code/_index.en.md
@@ -64,7 +64,7 @@ Some preformatted stuff in HTML elements
#### <>
-{{< highlight json "linenos=table,hl_lines=1 2,anchorlinenos=true" >}}
+{{< highlight json "linenos=true,hl_lines=1 2,anchorlinenos=true" >}}
{
"Hello": "World" "Hello": "World" "Hello": "World"
}
@@ -95,7 +95,7 @@ Some preformatted stuff in HTML elements
#### <> %%
{{< tab title="json" >}}
-{{% highlight html "linenos=table,hl_lines=1 2,anchorlinenos=true" %}}
+{{% highlight html "linenos=true,hl_lines=1 2,anchorlinenos=true" %}}
{
"Hello": "World" "Hello": "World" "Hello": "World"
}
@@ -105,7 +105,7 @@ Some preformatted stuff in HTML elements
#### <> <>
{{< tab title="json" >}}
-{{< highlight html "linenos=table,hl_lines=1 2,anchorlinenos=true" >}}
+{{< highlight html "linenos=true,hl_lines=1 2,anchorlinenos=true" >}}
{
"Hello": "World" "Hello": "World" "Hello": "World"
}
@@ -118,7 +118,7 @@ Some preformatted stuff in HTML elements
{{% tabs %}}
{{% tab title="json" %}}
-{{% highlight html "linenos=table,hl_lines=1 2,anchorlinenos=true" %}}
+{{% highlight html "linenos=true,hl_lines=1 2,anchorlinenos=true" %}}
{
"Hello": "World" "Hello": "World" "Hello": "World"
}
@@ -130,7 +130,7 @@ Some preformatted stuff in HTML elements
{{% tabs %}}
{{% tab title="json" %}}
-{{< highlight html "linenos=table,hl_lines=1 2,anchorlinenos=true" >}}
+{{< highlight html "linenos=true,hl_lines=1 2,anchorlinenos=true" >}}
{
"Hello": "World" "Hello": "World" "Hello": "World"
}
@@ -142,7 +142,7 @@ Some preformatted stuff in HTML elements
{{% tabs %}}
{{< tab title="json" >}}
-{{% highlight html "linenos=table,hl_lines=1 2,anchorlinenos=true" %}}
+{{% highlight html "linenos=true,hl_lines=1 2,anchorlinenos=true" %}}
{
"Hello": "World" "Hello": "World" "Hello": "World"
}
@@ -154,7 +154,7 @@ Some preformatted stuff in HTML elements
{{% tabs %}}
{{< tab title="json" >}}
-{{< highlight html "linenos=table,hl_lines=1 2,anchorlinenos=true" >}}
+{{< highlight html "linenos=true,hl_lines=1 2,anchorlinenos=true" >}}
{
"Hello": "World" "Hello": "World" "Hello": "World"
}
@@ -166,7 +166,7 @@ Some preformatted stuff in HTML elements
{{< tabs >}}
{{% tab title="json" %}}
-{{% highlight html "linenos=table,hl_lines=1 2,anchorlinenos=true" %}}
+{{% highlight html "linenos=true,hl_lines=1 2,anchorlinenos=true" %}}
{
"Hello": "World" "Hello": "World" "Hello": "World"
}
@@ -178,7 +178,7 @@ Some preformatted stuff in HTML elements
{{< tabs >}}
{{% tab title="json" %}}
-{{< highlight html "linenos=table,hl_lines=1 2,anchorlinenos=true" >}}
+{{< highlight html "linenos=true,hl_lines=1 2,anchorlinenos=true" >}}
{
"Hello": "World" "Hello": "World" "Hello": "World"
}
@@ -190,7 +190,7 @@ Some preformatted stuff in HTML elements
{{< tabs >}}
{{< tab title="json" >}}
-{{% highlight html "linenos=table,hl_lines=1 2,anchorlinenos=true" %}}
+{{% highlight html "linenos=true,hl_lines=1 2,anchorlinenos=true" %}}
{
"Hello": "World" "Hello": "World" "Hello": "World"
}
@@ -202,10 +202,78 @@ Some preformatted stuff in HTML elements
{{< tabs >}}
{{< tab title="json" >}}
-{{< highlight html "linenos=table,hl_lines=1 2,anchorlinenos=true" >}}
+{{< highlight html "linenos=true,hl_lines=1 2,anchorlinenos=true" >}}
{
"Hello": "World" "Hello": "World" "Hello": "World"
}
{{< /highlight >}}
{{< /tab >}}
{{< /tabs >}}
+
+## With Wrap
+
+### LineNo Table
+
+{{< highlight lineNos="table" type="py" wrap="true" hl_lines="2" >}}
+# Quicksort Python One-liner
+lambda L: [] if L==[] else qsort([x for x in L[1:] if x< L[0]]) + L[0:1] + qsort([x for x in L[1:] if x>=L[0]])
+# Some more stuff
+{{< /highlight >}}
+
+### LineNo Inline
+
+{{< highlight lineNos="inline" type="py" wrap="true" hl_lines="2" >}}
+# Quicksort Python One-liner
+lambda L: [] if L==[] else qsort([x for x in L[1:] if x< L[0]]) + L[0:1] + qsort([x for x in L[1:] if x>=L[0]])
+# Some more stuff
+{{< /highlight >}}
+
+### No LineNo
+
+{{< highlight type="py" wrap="true" hl_lines="2" >}}
+# Quicksort Python One-liner
+lambda L: [] if L==[] else qsort([x for x in L[1:] if x< L[0]]) + L[0:1] + qsort([x for x in L[1:] if x>=L[0]])
+# Some more stuff
+{{< /highlight >}}
+
+### No Type
+
+{{< highlight wrap="true" hl_lines="2" >}}
+# Quicksort Python One-liner
+lambda L: [] if L==[] else qsort([x for x in L[1:] if x< L[0]]) + L[0:1] + qsort([x for x in L[1:] if x>=L[0]])
+# Some more stuff
+{{< /highlight >}}
+
+## Without Wrap
+
+### LineNo Table
+
+{{< highlight lineNos="table" type="py" wrap="false" hl_lines="2">}}
+# Quicksort Python One-liner
+lambda L: [] if L==[] else qsort([x for x in L[1:] if x< L[0]]) + L[0:1] + qsort([x for x in L[1:] if x>=L[0]])
+# Some more stuff
+{{< /highlight >}}
+
+### LineNo Inline
+
+{{< highlight lineNos="inline" type="py" wrap="false" hl_lines="2" >}}
+# Quicksort Python One-liner
+lambda L: [] if L==[] else qsort([x for x in L[1:] if x< L[0]]) + L[0:1] + qsort([x for x in L[1:] if x>=L[0]])
+# Some more stuff
+{{< /highlight >}}
+
+### No LineNo
+
+{{< highlight type="py" wrap="false" hl_lines="2" >}}
+# Quicksort Python One-liner
+lambda L: [] if L==[] else qsort([x for x in L[1:] if x< L[0]]) + L[0:1] + qsort([x for x in L[1:] if x>=L[0]])
+# Some more stuff
+{{< /highlight >}}
+
+### No Type
+
+{{< highlight wrap="false" hl_lines="2" >}}
+# Quicksort Python One-liner
+lambda L: [] if L==[] else qsort([x for x in L[1:] if x< L[0]]) + L[0:1] + qsort([x for x in L[1:] if x>=L[0]])
+# Some more stuff
+{{< /highlight >}}
diff --git a/layouts/_default/_markup/render-codeblock.html b/layouts/_default/_markup/render-codeblock.html
new file mode 100644
index 0000000000..fa5570d87c
--- /dev/null
+++ b/layouts/_default/_markup/render-codeblock.html
@@ -0,0 +1,7 @@
+{{- partial "shortcodes/highlight.html" (dict
+ "context" .Page
+ "attributes" .Attributes
+ "content" .Inner
+ "options" .Options
+ "type" .Type
+) }}
\ No newline at end of file
diff --git a/layouts/partials/shortcodes/highlight.html b/layouts/partials/shortcodes/highlight.html
new file mode 100644
index 0000000000..72f159b0cb
--- /dev/null
+++ b/layouts/partials/shortcodes/highlight.html
@@ -0,0 +1,60 @@
+{{- $context := .context }}
+{{- $attributes := dict }}
+{{- $otherAttributes := dict }}
+{{- $content := "" }}
+{{- $options := dict }}
+{{- $otherOptions := dict }}
+{{- $type := "" }}
+{{- range $k, $v := . }}
+ {{- if eq $k "context" }}
+ {{- else if eq $k "attributes" }}
+ {{- $attributes = $v }}
+ {{- else if eq $k "content" }}
+ {{- $content = trim $v "\n\r" }}
+ {{- else if eq $k "options" }}
+ {{- $options = $v }}
+ {{- else if eq $k "type" }}
+ {{- $type = $v }}
+ {{- else if eq $k "wrap" }}
+ {{- $otherAttributes = $otherAttributes | merge (dict $k $v) }}
+ {{- else }}
+ {{- $otherOptions = $otherOptions | merge (dict $k $v) }}
+ {{- end }}
+{{- end }}
+{{- $options = $options | merge $otherOptions }}
+{{- $otherOptions := dict }}
+{{- range $k, $v := $options }}
+ {{- if eq $k "wrap" }}
+ {{- $otherAttributes = (dict $k $v) | merge $otherAttributes }}
+ {{- else }}
+ {{- $otherOptions = $otherOptions | merge (dict $k $v) }}
+ {{- end }}
+{{- end }}
+{{- $options = $otherOptions }}
+{{- $attributes = $attributes | merge $otherAttributes }}
+{{- $params := slice }}
+{{- range $k, $v := $options }}
+ {{- $params = $params | append (printf "%s=%s" $k $v) }}
+{{- end }}
+{{- $params = delimit $params ", " }}
+{{- $wrap := true }}
+{{- if isset $context.Site.Params "highlightwrap" }}
+ {{- $wrap = $context.Site.Params.highlightWrap }}
+{{- end }}
+{{- if isset $context.Params "highlightwrap" }}
+ {{- $wrap = $context.Params.highlightWrap }}
+{{- end }}
+{{- range $k, $v := $attributes }}
+ {{- if eq $k "wrap" }}
+ {{- $wrap = $v }}
+ {{- end }}
+{{- end }}
+{{- if eq (printf "%T" $wrap) "string" }}
+ {{- $wrap = (eq $wrap "true") }}
+{{- end }}
+{{- $content = highlight $content $type $params }}
+{{- $content = replaceRE "^([\\s\\n\\r]*)(
${2}" $content }} +{{- if $wrap }} + {{- $content = replaceRE "^([\\s\\n\\r]*div table + .copy-to-clipboard-button, + div.highlight pre + .copy-to-clipboard-button, pre .copy-to-clipboard-button { border-color: rgba( 216, 216, 216, 1 ); /* var(--CODE-BLOCK-BORDER-color) */ color: rgba( 72, 106, 201, 1 ); /* var(--MAIN-LINK-color) */ } div.highlight > div table + .copy-to-clipboard-button:hover, + div.highlight pre + .copy-to-clipboard-button:hover, pre .copy-to-clipboard-button:hover { background-color: rgba( 72, 106, 201, 1 ); /* var(--MAIN-LINK-color) */ border-color: rgba( 72, 106, 201, 1 ); /* var(--MAIN-LINK-color) */ diff --git a/static/css/theme.css b/static/css/theme.css index 76d2e4966e..9b2a64c233 100644 --- a/static/css/theme.css +++ b/static/css/theme.css @@ -544,14 +544,19 @@ div.box > .box-content { #body table th > :last-child, #body table th > :last-child :last-child, +#body table th > div.highlight:last-child pre, #body table td > :last-child, #body table td > :last-child :last-child, +#body table td > div:last-child pre, #body div.box > .box-content > :last-child, #body div.box > .box-content > :last-child :last-child, +#body div.box > .box-content > div:last-child pre, #body div.expand > .expand-content-text > :last-child, #body div.expand > .expand-content-text > :last-child :last-child, +#body div.expand > .expand-content-text > div:last-child pre, #body div.tab-content > .tab-content-text > :last-child, -#body div.tab-content > .tab-content-text > :last-child :last-child { +#body div.tab-content > .tab-content-text > :last-child :last-child, +#body div.tab-content > .tab-content-text > div:last-child pre { margin-bottom: 0; } @@ -663,14 +668,15 @@ pre code { font-size: .9375rem; margin: 0; padding: 0; - white-space: inherit; } +div.highlight{ + position: relative; +} /* we may have special treatment if highlight shortcode was used in table lineno mode */ div.highlight > div{ border-style: solid; border-width: 1px; - position: relative; } /* remove default style for usual markdown tables */ div.highlight > div table{ @@ -700,9 +706,15 @@ div.highlight > div table{ display: block; overflow: auto; } -div.highlight > div td:not(:first-child):last-child pre code{ +div.highlight:not(.wrap-code) pre{ + overflow: auto; +} +div.highlight:not(.wrap-code) pre code{ white-space: pre; } +div.highlight.wrap-code pre code{ + white-space: pre-wrap; +} /* remove border from row cells if highlight shortcode was used in table lineno mode */ div.highlight > div td > pre { border-radius: 0; @@ -1101,12 +1113,14 @@ span > .copy-to-clipboard-button { } div.highlight > div table + .copy-to-clipboard-button > i, +div.highlight pre + .copy-to-clipboard-button > i, .copy-to-clipboard-code + .copy-to-clipboard-button > i { padding-left: 5px; padding-right: 5px; } div.highlight > div table + .copy-to-clipboard-button, +div.highlight pre + .copy-to-clipboard-button, pre > .copy-to-clipboard-button { background-color: rgba( 160, 160, 160, .2 ); border-radius: 2px; diff --git a/static/css/variant.css b/static/css/variant.css index 1721d2ae77..d3542a346a 100644 --- a/static/css/variant.css +++ b/static/css/variant.css @@ -273,12 +273,14 @@ table { } div.highlight > div table + .copy-to-clipboard-button, +div.highlight pre + .copy-to-clipboard-button, pre .copy-to-clipboard-button { border-color: var(--INTERNAL-CODE-BLOCK-BORDER-color); color: var(--INTERNAL-MAIN-LINK-color); } div.highlight > div table + .copy-to-clipboard-button:hover, +div.highlight pre + .copy-to-clipboard-button:hover, pre .copy-to-clipboard-button:hover { background-color: var(--INTERNAL-MAIN-LINK-color); border-color: var(--INTERNAL-MAIN-LINK-color); diff --git a/static/js/theme.js b/static/js/theme.js index 33d3c3933d..fb451f0fc6 100644 --- a/static/js/theme.js +++ b/static/js/theme.js @@ -577,6 +577,24 @@ function initCodeClipboard(){ table.dataset[ 'code' ] = text; table.parentNode.insertBefore( button, table.nextSibling ); } + else if( inPre ){ + var pre = code.parentNode; + pre.dataset[ 'code' ] = text; + var p = pre.parentNode; + // indented code blocks are missing the div + while( p != document && ( p.tagName.toLowerCase() != 'div' || !p.classList.contains( 'highlight' ) ) ){ + p = p.parentNode; + } + if( p == document ){ + var clone = pre.cloneNode( true ); + var div = document.createElement( 'div' ); + div.classList.add( 'highlight' ); + div.appendChild( clone ); + pre.parentNode.replaceChild( div, pre ); + pre = clone; + } + pre.parentNode.insertBefore( button, pre.nextSibling ); + } else{ code.dataset[ 'code' ] = text; code.parentNode.insertBefore( button, code.nextSibling );