From 9b56fc914c80f6b8a6f6dde9c19d70ff7e79a89b Mon Sep 17 00:00:00 2001 From: Kisaragi Hiu Date: Mon, 18 Jul 2022 03:51:04 +0900 Subject: [PATCH] highlight: Expose node params so we can pass options to Chroma --- blorg/util.go | 2 +- main.go | 2 +- org/html_writer.go | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/blorg/util.go b/blorg/util.go index 05d74e2..e24ea9a 100644 --- a/blorg/util.go +++ b/blorg/util.go @@ -55,7 +55,7 @@ func getWriter() org.Writer { return w } -func highlightCodeBlock(source, lang string, inline bool) string { +func highlightCodeBlock(source, lang string, inline bool, params map[string]string) string { var w strings.Builder l := lexers.Get(lang) if l == nil { diff --git a/main.go b/main.go index 0b0a21a..c400d56 100644 --- a/main.go +++ b/main.go @@ -119,7 +119,7 @@ func render(args []string) { } } -func highlightCodeBlock(source, lang string, inline bool) string { +func highlightCodeBlock(source, lang string, inline bool, params map[string]string) string { var w strings.Builder l := lexers.Get(lang) if l == nil { diff --git a/org/html_writer.go b/org/html_writer.go index fc0780a..5f388d9 100644 --- a/org/html_writer.go +++ b/org/html_writer.go @@ -19,7 +19,7 @@ import ( // HTMLWriter exports an org document into a html document. type HTMLWriter struct { ExtendingWriter Writer - HighlightCodeBlock func(source, lang string, inline bool) string + HighlightCodeBlock func(source, lang string, inline bool, params map[string]string) string PrettyRelativeLinks bool strings.Builder @@ -66,7 +66,7 @@ func NewHTMLWriter() *HTMLWriter { document: &Document{Configuration: defaultConfig}, log: defaultConfig.Log, htmlEscape: true, - HighlightCodeBlock: func(source, lang string, inline bool) string { + HighlightCodeBlock: func(source, lang string, inline bool, params map[string]string) string { if inline { return fmt.Sprintf("
\n
\n%s\n
\n
", html.EscapeString(source)) } @@ -129,7 +129,7 @@ func (w *HTMLWriter) WriteBlock(b Block) { if len(b.Parameters) >= 1 { lang = strings.ToLower(b.Parameters[0]) } - content = w.HighlightCodeBlock(content, lang, false) + content = w.HighlightCodeBlock(content, lang, false, params) w.WriteString(fmt.Sprintf("
\n%s\n
\n", lang, content)) case "EXAMPLE": w.WriteString(`
` + "\n" + html.EscapeString(content) + "\n
\n") @@ -159,7 +159,7 @@ func (w *HTMLWriter) WriteInlineBlock(b InlineBlock) { switch b.Name { case "src": lang := strings.ToLower(b.Parameters[0]) - content = w.HighlightCodeBlock(content, lang, true) + content = w.HighlightCodeBlock(content, lang, true, nil) w.WriteString(fmt.Sprintf("
\n%s\n
", lang, content)) case "export": if strings.ToLower(b.Parameters[0]) == "html" {