Inline Highlight shortcode

I would like to inline syntax highlight super short code snippets where possible.

I am attempting to inline

1(message "this highlight shortcode")
. But it is creating a paragraph break around it.

Is there a way to fix it, may be using some custom shortcode?

Using a shortcode using .Inner

ref

I am attempting to inline

(message "this hl2 shortcode")
. But it is creating a paragraph break around it.

Using Inline Shortcode

Inline shortcodes

I am attempting to inline

(message "this hl3 shortcode")
, but still no luck.

Using a custom shortcode that hacks the HTML

I am attempting to inline (message "this hl4 shortcode"). And this!! finally works.

hl4 Shortcode definition

{{/* Replace the <div> tag with <span>,
     and remove the <pre> tag entirely. */}}
{{- transform.Highlight .Inner (.Get 0) (.Get 1 | default "")
    | replaceRE `^<div class="highlight"><pre [^>]+>(.*)</pre></div>$`
                `<span class="highlight-inline">${1}</span>`
    | safeHTML -}}

<2022-03-09 Wed> Testing hl_inline option on Hugo v0.94.x

Hugo PR # 9634

Using highlight shortcode

something

(message
"this highlight shortcode")
something

Using a custom shortcode using the transform.Highlight method

something

(message "this highlight
shortcode")
something

Using a custom shortcode using the highlight function

something

(message "this highlight
shortcode")
something

What’s next?

@bep I hope you can add a feature to the highlight shortcode where a boolean arg like “inline” would do that same as the above shortcode hack does.

References

To reproduce this page/issue

git clone https://gitlab.com/hugo-mwe/hugo-mwe
cd hugo-mwe
git checkout inline-highlight-sc-attempt
./srv.sh
            
Markdown source of this page | Built with Hugo 0.93.3

Go Up | Back to Home | Source code repo