func newHighlighting()

in src/docker_assets/convert.go [309:364]


func newHighlighting(cfg highlight.Config) goldmark.Extender {
	return hl.NewHighlighting(
		hl.WithStyle(cfg.Style),
		hl.WithGuessLanguage(cfg.GuessSyntax),
		hl.WithCodeBlockOptions(highlight.GetCodeBlockOptions()),
		hl.WithFormatOptions(
			cfg.ToHTMLOptions()...,
		),

		hl.WithWrapperRenderer(func(w util.BufWriter, ctx hl.CodeBlockContext, entering bool) {
			l, hasLang := ctx.Language()
			var language string
			if hasLang {
				language = string(l)
			}

			if entering {
				if !ctx.Highlighted() {
					w.WriteString(`<pre>`)
					highlight.WriteCodeTag(w, language)
					return
				}

				w.WriteString(`<div class="highlight`)

				var attributes []ast.Attribute
				if ctx.Attributes() != nil {
					attributes = ctx.Attributes().All()
				}

				if attributes != nil {
					class, found := ctx.Attributes().GetString("class")
					if found {
						w.WriteString(" ")
						w.Write(util.EscapeHTML(class.([]byte)))

					}
					_, _ = w.WriteString("\"")
					renderAttributes(w, true, attributes...)
				} else {
					_, _ = w.WriteString("\"")
				}

				w.WriteString(">")
				return
			}

			if !ctx.Highlighted() {
				w.WriteString(`</code></pre>`)
				return
			}

			w.WriteString("</div>")
		}),
	)
}