highlight: support highlighting lines in the default writer
The hl_lines key is specifically the same as Hugo's key.
This commit is contained in:
parent
9b56fc914c
commit
ab8d3bc16a
6 changed files with 97 additions and 2 deletions
|
@ -63,7 +63,14 @@ func highlightCodeBlock(source, lang string, inline bool, params map[string]stri
|
|||
}
|
||||
l = chroma.Coalesce(l)
|
||||
it, _ := l.Tokenise(nil, source)
|
||||
_ = html.New().Format(&w, styles.Get("github"), it)
|
||||
options := []html.Option{}
|
||||
if params[":hl_lines"] != "" {
|
||||
ranges := org.ParseRanges(params[":hl_lines"])
|
||||
if ranges != nil {
|
||||
options = append(options, html.HighlightLines(ranges))
|
||||
}
|
||||
}
|
||||
_ = html.New(options...).Format(&w, styles.Get("github"), it)
|
||||
if inline {
|
||||
return `<div class="highlight-inline">` + "\n" + w.String() + "\n" + `</div>`
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue