diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2022-03-09 10:45:02 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2022-03-09 11:33:13 +0100 |
commit | a360cab75a073c2a8d47dcd27f52a6847e8d8d13 (patch) | |
tree | 46d139073a7e77950698f8dcd1172201b31e1ee1 /markup/highlight/highlight.go | |
parent | c97fed08f90b3758c85d3f67f038cd1f794d16fc (diff) |
markup/highlight: Add hl_inline option
If set to true, the highlighted code will not be wrapped in any div.
Closes #9442
Diffstat (limited to 'markup/highlight/highlight.go')
-rw-r--r-- | markup/highlight/highlight.go | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/markup/highlight/highlight.go b/markup/highlight/highlight.go index 892cb72ee..7d108ebe1 100644 --- a/markup/highlight/highlight.go +++ b/markup/highlight/highlight.go @@ -75,11 +75,24 @@ func (h chromaHighlighter) Highlight(code, lang string, opts interface{}) (strin } var b strings.Builder - if _, _, err := highlight(&b, code, lang, nil, cfg); err != nil { + low, high, err := highlight(&b, code, lang, nil, cfg) + + if err != nil { return "", err } - return b.String(), nil + if !cfg.Hl_inline { + return b.String(), nil + } + + hr := HightlightResult{ + highlighted: template.HTML(b.String()), + innerLow: low, + innerHigh: high, + } + + return string(hr.Inner()), nil + } func (h chromaHighlighter) HighlightCodeBlock(ctx hooks.CodeblockContext, opts interface{}) (HightlightResult, error) { |