diff --git a/CHANGELOG.md b/CHANGELOG.md index aba5b7d4df..3fa85f4bb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,8 +21,13 @@ For a list of issues targeted for the next release, see the [23Q1][] milestone. - Dropped `$primary-light`. - Dropped `color-diff()`. -- **[Adaptation of shortcode 'cardpane'][1376]. renamed CSS class `td-card-deck` - to `td-card-group`. +- **[Adaptation of shortcodes for diplay of cards (#1376)][1376]: + - shortcode `cardpane`: renamed CSS class `td-card-deck` to `td-card-group`. + - shortcode `card`, `card-code`: markup of inner content (html/markdown) + now depends on the syntax of the calling shortcode, not on extension + of page file any more [#906](906). + - shortcode `card-code` is now deprecated, use shortcode `card` with named + parameter `code=true` instead. **Other changes**: diff --git a/layouts/shortcodes/card-code.html b/layouts/shortcodes/card-code.html index 0e1b668e05..1039147024 100644 --- a/layouts/shortcodes/card-code.html +++ b/layouts/shortcodes/card-code.html @@ -1,20 +1,15 @@ +{{ $lang := default "" ($.Get "lang") -}} +{{ $highlight := default "" ($.Get "highlight") -}} +
- {{ $lang := "" }} - {{ with $.Get "lang" }} - {{ $lang = $.Get "lang" }} - {{ end }} - {{ $highlight := "" }} - {{ with $.Get "highlight" }} - {{ $highlight = $.Get "highlight" }} - {{ end }} - {{- with $.Get "header" -}} + {{ with $.Get "header" -}}
- {{- $.Get "header" | markdownify -}} + {{ . | markdownify -}}
- {{end}} + {{ end -}}
- {{ with $.Inner }} - {{- highlight $.Inner $lang $highlight -}} - {{ end }} + {{ with $.Inner -}} + {{ highlight . $lang $highlight -}} + {{ end -}}
diff --git a/layouts/shortcodes/card.html b/layouts/shortcodes/card.html index bf97c14d7b..a50a6f68c8 100644 --- a/layouts/shortcodes/card.html +++ b/layouts/shortcodes/card.html @@ -1,49 +1,44 @@ +{{/* Check parameter type */ -}} +{{ with .Get "code" -}} + {{ if ne ( printf "%T" . ) "bool" -}} + {{ errorf "shortcode card: parameter 'code' must be either true or false" -}} + {{ end -}} +{{ end -}} + +{{ $code := default false (.Get "code") -}} +{{ $lang := default "" (.Get "lang") -}} +{{ $highlight := default "" (.Get "highlight") -}} +
- {{ with $.Get "header" }} -
- {{ if eq $.Page.File.Ext "md" }} - {{ $.Get "header" | markdownify }} - {{ else }} - {{ $.Get "header" | htmlUnescape | safeHTML }} - {{ end }} +{{ with $.Get "header" -}} +
+ {{ . | markdownify }}
- {{ end }} -
- {{ with $.Get "title" }} +{{ end -}} +
+ {{ with $.Get "title" -}}
- {{ if eq $.Page.File.Ext "md" }} - {{ $.Get "title" | markdownify }} - {{ else }} - {{ $.Get "title" | htmlUnescape | safeHTML }} - {{ end }} + {{ . | markdownify -}}
- {{ end }} - {{ with $.Get "subtitle" }} + {{ end -}} + {{ with $.Get "subtitle" -}}
- {{ if eq $.Page.File.Ext "md" }} - {{ $.Get "subtitle" | markdownify }} - {{ else }} - {{ $.Get "subtitle" | htmlUnescape | safeHTML }} - {{ end }} + {{ . | markdownify -}}
- {{ end }} - {{ with $.Inner }} + {{ end -}} + {{ with $.Inner -}} + {{ if $code -}} + {{ highlight . $lang $highlight -}} + {{ else -}}

- {{ if eq $.Page.File.Ext "md" }} - {{ $.Inner | markdownify }} - {{ else }} - {{ $.Inner | htmlUnescape | safeHTML }} - {{ end }} + {{ . -}}

- {{ end }} + {{ end -}} + {{ end -}}
- {{ with $.Get "footer" }} + {{ with $.Get "footer" -}} - {{ end }} + {{ end -}}
diff --git a/userguide/content/en/docs/adding-content/shortcodes/index.md b/userguide/content/en/docs/adding-content/shortcodes/index.md index 2eda403c90..653a1028bb 100644 --- a/userguide/content/en/docs/adding-content/shortcodes/index.md +++ b/userguide/content/en/docs/adding-content/shortcodes/index.md @@ -113,7 +113,7 @@ For announcement of latest features etc. | ---------------- |------------| ------------| | height | | See above. | color | | See above. -| type | | Specify "section" if you want a general container, omit this parameter if you want this section to contain a horizontal row of features. +| type | | Specify "section" if you want a general container, omit this parameter if you want this section to contain a horizontal row of features. ### blocks/feature @@ -424,7 +424,7 @@ This code translates to the right aligned tabbed pane below, showing a `Welcome! Herzlich willkommen! Flag Germany {{< /tab >}} - {{% tab header="Swahili" lang="sw" %}} + {{% tab header="Swahili" lang="sw" %}} ![Flag Tanzania](flags/tz.png) **Karibu sana!** {{% /tab %}} @@ -435,9 +435,9 @@ This code translates to the right aligned tabbed pane below, showing a `Welcome! Tabbed panes are implemented using two shortcodes: * The `tabpane` shortcode, which is the container element for the tabs. This shortcode can hold the optional named parameters `lang`, `highlight` and `right`. The value of the optional parameters `lang` and `highlight` are passed on as second `LANG` and third `OPTIONS` arguments to Hugo's built-in [`highlight`](https://gohugo.io/functions/highlight/) function which is used to render the code blocks of the individual tabs. Specify `right=true` if you want to right align your tabs. In case the header text of the tab equals the language used in the tab's code block (as in the first tabbed pane example above), you may specify `langEqualsHeader=true` in the surrounding `tabpane` shortcode. Then, the header text of the individual tab is automatically set as `lang` parameter of the respective tab. -* The various `tab` shortcodes represent the tabs you would like to show. Specify the named parameter `header` for each tab in order to set the header text of the tab. If the `header` parameter is the only parameter inside your tab shortcode, you can specify the header as unnamed parameter, something like `{ tab "My header" }} … {{ /tab }}`. If your `tab` shortcode does not have any parameters, the header of the tab will default to `Tab n`. To split the panes into a left aligned and a right aligned tab group, specify `right=true` in the dividing tab. By giving `right=true` several times, you can even render multiple tab groups. You can disable a tab by specifying the parameter `disabled=true`. For enabled tabs, there are two modes for content display, `code` representation and _textual_ representation: +* The various `tab` shortcodes represent the tabs you would like to show. Specify the named parameter `header` for each tab in order to set the header text of the tab. If the `header` parameter is the only parameter inside your tab shortcode, you can specify the header as unnamed parameter, something like `{{< tab "My header" >}} … {{< /tab >}}`. If your `tab` shortcode does not have any parameters, the header of the tab will default to `Tab n`. To split the panes into a left aligned and a right aligned tab group, specify `right=true` in the dividing tab. By giving `right=true` several times, you can even render multiple tab groups. You can disable a tab by specifying the parameter `disabled=true`. For enabled tabs, there are two modes for content display, `code` representation and _textual_ representation: * By default, the tab's content is rendered as `code block`. In order to get proper syntax highlighting, specify the named parameter `lang` --and optionally the parameter `highlight`-- for each tab. Parameters set in the parent `tabpane` shortcode will be overwritten. - * If the contents of your tabs should be rendered as text with different styles and with optional images, specify `text=true` as parameter of your `tabpane` (or your `tab`). If your content is markdown, use the percent sign `%` as outermost delimiter of your `tab` shortcode, your markup should look like `{{%/* tab */%}}`Your \*\*markdown\*\* content`{{%/* /tab */%}}`. In case of HTML content, use square brackets `<>` as outermost delimiters: `{{}}`Your <b>HTML</b> content`{{}}`. + * If the contents of your tabs should be rendered as text with different styles and with optional images, specify `text=true` as parameter of your `tabpane` (or your `tab`). If your content is markdown, use the percent sign `%` as outermost delimiter of your `tab` shortcode, your markup should look like `{{%/* tab */%}}Your **markdown** content{{%/* /tab */%}}`. In case of HTML content, use square brackets `<>` as outermost delimiters: `{{}}Your HTML content{{}}`. {{% alert title="Info" %}} By default, the language of the selected tab is stored and preserved between different browser sessions. If the content length within your tabs differs greatly, this may lead to unwanted scrolling when switching between tabs. To disable this unwanted behaviour, specify `persistLang=false` within your `tabpane` shortcode. @@ -447,30 +447,29 @@ By default, the language of the selected tab is stored and preserved between dif When authoring content, it's sometimes very useful to put similar text blocks or code fragments on card like elements, which can be optionally presented side by side. Let's showcase this feature with the following sample card group which shows the first four Presidents of the United States: -{{< cardpane >}} -{{< card header="**George Washington**" title="\*1732     †1799" subtitle="**President:** 1789 – 1797" footer="![SignatureGeorgeWashington](https://upload.wikimedia.org/wikipedia/commons/thumb/2/2e/George_Washington_signature.svg/320px-George_Washington_signature.svg.png 'Signature George Washington')">}} +{{% cardpane %}} +{{% card header="**George Washington**" title="\*1732     †1799" subtitle="**President:** 1789 – 1797" footer="![SignatureGeorgeWashington](https://upload.wikimedia.org/wikipedia/commons/thumb/2/2e/George_Washington_signature.svg/320px-George_Washington_signature.svg.png 'Signature George Washington')" %}} ![PortraitGeorgeWashington](https://upload.wikimedia.org/wikipedia/commons/thumb/b/b6/Gilbert_Stuart_Williamstown_Portrait_of_George_Washington.jpg/633px-Gilbert_Stuart_Williamstown_Portrait_of_George_Washington.jpg "Portrait George Washington") -{{< /card >}} -{{< card header="**John Adams**" title="\* 1735     † 1826" subtitle="**President:** 1797 – 1801" footer="![SignatureJohnAdams](https://upload.wikimedia.org/wikipedia/commons/thumb/e/e8/John_Adams_Sig_2.svg/320px-John_Adams_Sig_2.svg.png 'Signature John Adams')" >}} +{{% /card %}} +{{% card header="**John Adams**" title="\* 1735     † 1826" subtitle="**President:** 1797 – 1801" footer="![SignatureJohnAdams](https://upload.wikimedia.org/wikipedia/commons/thumb/e/e8/John_Adams_Sig_2.svg/320px-John_Adams_Sig_2.svg.png 'Signature John Adams')" %}} ![PortraitJohnAdams](https://upload.wikimedia.org/wikipedia/commons/thumb/f/ff/Gilbert_Stuart%2C_John_Adams%2C_c._1800-1815%2C_NGA_42933.jpg/633px-Gilbert_Stuart%2C_John_Adams%2C_c._1800-1815%2C_NGA_42933.jpg "Portrait John Adams") -{{< /card >}} -{{< card header="**Thomas Jefferson**" title="\* 1743     † 1826" subtitle="**President:** 1801 – 1809" footer="![SignatureThomasJefferson](https://upload.wikimedia.org/wikipedia/commons/thumb/0/0d/Thomas_Jefferson_Signature.svg/320px-Thomas_Jefferson_Signature.svg.png 'Signature Thomas Jefferson')" >}} +{{% /card %}} +{{% card header="**Thomas Jefferson**" title="\* 1743     † 1826" subtitle="**President:** 1801 – 1809" footer="![SignatureThomasJefferson](https://upload.wikimedia.org/wikipedia/commons/thumb/0/0d/Thomas_Jefferson_Signature.svg/320px-Thomas_Jefferson_Signature.svg.png 'Signature Thomas Jefferson')" %}} ![PortraitThomasJefferson](https://upload.wikimedia.org/wikipedia/commons/thumb/b/b1/Official_Presidential_portrait_of_Thomas_Jefferson_%28by_Rembrandt_Peale%2C_1800%29%28cropped%29.jpg/390px-Official_Presidential_portrait_of_Thomas_Jefferson_%28by_Rembrandt_Peale%2C_1800%29%28cropped%29.jpg "Portrait Thomas Jefferson") -{{< /card >}} -{{< card header="**James Madison**" title="\* 1751     † 1836" subtitle="**President:** 1809 – 1817" footer="![SignatureJamesMadison](https://upload.wikimedia.org/wikipedia/commons/thumb/3/39/James_Madison_sig.svg/320px-James_Madison_sig.svg.png 'Signature James Madison')" >}} +{{% /card %}} +{{% card header="**James Madison**" title="\* 1751     † 1836" subtitle="**President:** 1809 – 1817" footer="![SignatureJamesMadison](https://upload.wikimedia.org/wikipedia/commons/thumb/3/39/James_Madison_sig.svg/320px-James_Madison_sig.svg.png 'Signature James Madison')" %}} ![PortraitJamesMadison](https://upload.wikimedia.org/wikipedia/commons/thumb/2/20/James_Madison%28cropped%29%28c%29.jpg/393px-James_Madison%28cropped%29%28c%29.jpg "Portrait James Madison") -{{< /card >}} -{{< /cardpane >}} +{{% /card %}} +{{% /cardpane %}} Docsy supports creating such card panes via different shortcodes: * The `cardpane` shortcode which is the container element for the various cards to be presented. -* The `card` shortcodes, with each shortcode representing an individual card. While cards are often presented inside a card group, a single card may stand on its own, too. A `card` shortcode can hold text, images or any other arbitrary kind of markdown or HTML markup as content. If your content is programming code, you are advised to make use of the `card-code` shortcode, a special kind of card with code-highlighting and other optional features like line numbers, highlighting of certain lines, …. +* The `card` shortcodes, with each shortcode representing an individual card. While cards are often presented inside a card group, a single card may stand on its own, too. A `card` shortcode can hold programming code, text, images or any other arbitrary kind of markdown or HTML markup as content. In case of programming code, cards provide automatic code-highlighting and other optional features like line numbers, highlighting of certain lines, …. -### Shortcode `card` (for text, images, …) +### Shortcode `card`: textual content -As stated above, a card is coded using one of the shortcode `card` or `card-code`. -If your content is any kind of text other than programming code, use the universal `card`shortcode. The following code sample demonstrates how to code a card element: +Make use of the `card` shortcode to display a card. The following code sample demonstrates how to code a card element: ```go-html-template {{}} -{{< card header="**Imagine**" title="Artist and songwriter: John Lennon" subtitle="Co-writer: Yoko Ono" footer="![SignatureJohnLennon](https://upload.wikimedia.org/wikipedia/commons/thumb/5/51/Firma_de_John_Lennon.svg/320px-Firma_de_John_Lennon.svg.png 'Signature John Lennon')">}} +{{% cardpane %}} +{{< card header="**Imagine**" title="Artist and songwriter: John Lennon" subtitle="Co-writer: Yoko Ono" footer="![SignatureJohnLennon](https://upload.wikimedia.org/wikipedia/commons/thumb/5/51/Firma_de_John_Lennon.svg/320px-Firma_de_John_Lennon.svg.png 'Signature John Lennon')" >}} Imagine there's no heaven, It's easy if you try
No hell below us, above us only sky
Imagine all the people living for today… @@ -501,19 +500,19 @@ Imagine all the people sharing all the world… You may say I'm a dreamer, but I'm not the only one
I hope someday you'll join us and the world will live as one {{< /card >}} -{{< card header="**Header**: specified via named parameter `Header`" title="**Card title**: specified via named parameter `title`" subtitle="**Card subtitle**: specified via named parameter `subtitle`" footer="**Footer**: specified via named parameter `footer`" >}} - **Content**: inner content of the shortcode, this may be formatted text, images, videos, … . If the extension of your page file equals `.md`, markdown format is expected, otherwise, your content will be treated as plain HTML. -{{< /card >}} -{{< /cardpane >}} +{{% card header="**Header**: specified via named parameter `Header`" title="**Card title**: specified via named parameter `title`" subtitle="**Card subtitle**: specified via named parameter `subtitle`" footer="**Footer**: specified via named parameter `footer`" %}} + **Content**: inner content of the shortcode, this may be plain text or formatted text, images, videos, … . If your content is markdown, use the percent sign `%` as outermost delimiter of your `card` shortcode, your markup should look like `{{%/* card */%}}Your **markdown** content{{%/* /card */%}}`. In case of HTML content, use square brackets `<>` as outermost delimiters: `{{}}Your HTML content{{}}` +{{% /card %}} +{{% /cardpane %}} While the main content of the card is taken from the inner markup of the `card` shortcode, the optional elements `footer`, `header`, `title`, and `subtitle` are all specified as named parameters of the shortcode. -### Shortcode `card-code` (for programming code) +### Shortcode `card`: programming code -In case you want to display programming code on your card, a special shortcode `card-code` is provided for this purpose. The following sample demonstrates how to code a card element with the famous `Hello world!`application coded in C: +If you want to display programming code on your card, set the named parameter `code` of the card to `true`. The following sample demonstrates how to code a card element with the famous `Hello world!` application coded in C: ```go-html-template -{{}} +{{}} #include #include @@ -522,12 +521,12 @@ int main(void) puts("Hello World!"); return EXIT_SUCCESS; } -{{}} +{{}} ``` This code translates to the card shown below: -{{< card-code header="**C**" lang="C" highlight="" >}} +{{< card code=true header="**C**" lang="C" highlight="" >}} #include #include @@ -536,9 +535,9 @@ int main(void) puts("Hello World!"); return EXIT_SUCCESS; } -{{< /card-code >}} +{{< /card >}} -
The `card-code` shortcode can optionally hold the named parameters `lang` and/or `highlight`. The values of these optional parameters are passed on as second `LANG` and third `OPTIONS` arguments to Hugo's built-in [`highlight`](https://gohugo.io/functions/highlight/) function which is used to render the code block presented on the card. +
If called with parameter `code=true`, the `card` shortcode can optionally hold the named parameters `lang` and/or `highlight`. The values of these optional parameters are passed on as second `LANG` and third `OPTIONS` arguments to Hugo's built-in [`highlight`](https://gohugo.io/functions/highlight/) function which is used to render the code block presented on the card. ### Card groups @@ -562,18 +561,18 @@ The general markup of a card group resembles closely the markup of a tabbed pane Contrary to tabs, cards are presented side by side, however. This is especially useful it you want to compare different programming techniques (traditional vs. modern) on two cards, like demonstrated in the example above: {{< cardpane >}} -{{< card-code header="**Java 5**" >}} +{{< card code=true header="**Java 5**" >}} File[] hiddenFiles = new File("directory_name") .listFiles(new FileFilter() { public boolean accept(File file) { return file.isHidden(); } }); -{{< /card-code >}} -{{< card-code header="**Java 8, Lambda expression**" >}} +{{< /card >}} +{{< card code=true header="**Java 8, Lambda expression**" >}} File[] hiddenFiles = new File("directory_name") .listFiles(File::isHidden); -{{< /card-code >}} +{{< /card >}} {{< /cardpane >}} ## Include external files @@ -672,7 +671,7 @@ You must use `{{}}` delimiters for the code highlighting to work correctly. {{% /alert %}} -The "file" parameter is the relative path to the file. Only relative paths +The `file` parameter is the relative path to the file. Only relative paths under the parent file's working directory are supported. For files outside the current working directory you can use an absolute path