highlight: Expose node params so we can pass options to Chroma
This commit is contained in:
parent
3c938e7e43
commit
9b56fc914c
3 changed files with 6 additions and 6 deletions
|
@ -55,7 +55,7 @@ func getWriter() org.Writer {
|
||||||
return w
|
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
|
var w strings.Builder
|
||||||
l := lexers.Get(lang)
|
l := lexers.Get(lang)
|
||||||
if l == nil {
|
if l == nil {
|
||||||
|
|
2
main.go
2
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
|
var w strings.Builder
|
||||||
l := lexers.Get(lang)
|
l := lexers.Get(lang)
|
||||||
if l == nil {
|
if l == nil {
|
||||||
|
|
|
@ -19,7 +19,7 @@ import (
|
||||||
// HTMLWriter exports an org document into a html document.
|
// HTMLWriter exports an org document into a html document.
|
||||||
type HTMLWriter struct {
|
type HTMLWriter struct {
|
||||||
ExtendingWriter Writer
|
ExtendingWriter Writer
|
||||||
HighlightCodeBlock func(source, lang string, inline bool) string
|
HighlightCodeBlock func(source, lang string, inline bool, params map[string]string) string
|
||||||
PrettyRelativeLinks bool
|
PrettyRelativeLinks bool
|
||||||
|
|
||||||
strings.Builder
|
strings.Builder
|
||||||
|
@ -66,7 +66,7 @@ func NewHTMLWriter() *HTMLWriter {
|
||||||
document: &Document{Configuration: defaultConfig},
|
document: &Document{Configuration: defaultConfig},
|
||||||
log: defaultConfig.Log,
|
log: defaultConfig.Log,
|
||||||
htmlEscape: true,
|
htmlEscape: true,
|
||||||
HighlightCodeBlock: func(source, lang string, inline bool) string {
|
HighlightCodeBlock: func(source, lang string, inline bool, params map[string]string) string {
|
||||||
if inline {
|
if inline {
|
||||||
return fmt.Sprintf("<div class=\"highlight-inline\">\n<pre>\n%s\n</pre>\n</div>", html.EscapeString(source))
|
return fmt.Sprintf("<div class=\"highlight-inline\">\n<pre>\n%s\n</pre>\n</div>", html.EscapeString(source))
|
||||||
}
|
}
|
||||||
|
@ -129,7 +129,7 @@ func (w *HTMLWriter) WriteBlock(b Block) {
|
||||||
if len(b.Parameters) >= 1 {
|
if len(b.Parameters) >= 1 {
|
||||||
lang = strings.ToLower(b.Parameters[0])
|
lang = strings.ToLower(b.Parameters[0])
|
||||||
}
|
}
|
||||||
content = w.HighlightCodeBlock(content, lang, false)
|
content = w.HighlightCodeBlock(content, lang, false, params)
|
||||||
w.WriteString(fmt.Sprintf("<div class=\"src src-%s\">\n%s\n</div>\n", lang, content))
|
w.WriteString(fmt.Sprintf("<div class=\"src src-%s\">\n%s\n</div>\n", lang, content))
|
||||||
case "EXAMPLE":
|
case "EXAMPLE":
|
||||||
w.WriteString(`<pre class="example">` + "\n" + html.EscapeString(content) + "\n</pre>\n")
|
w.WriteString(`<pre class="example">` + "\n" + html.EscapeString(content) + "\n</pre>\n")
|
||||||
|
@ -159,7 +159,7 @@ func (w *HTMLWriter) WriteInlineBlock(b InlineBlock) {
|
||||||
switch b.Name {
|
switch b.Name {
|
||||||
case "src":
|
case "src":
|
||||||
lang := strings.ToLower(b.Parameters[0])
|
lang := strings.ToLower(b.Parameters[0])
|
||||||
content = w.HighlightCodeBlock(content, lang, true)
|
content = w.HighlightCodeBlock(content, lang, true, nil)
|
||||||
w.WriteString(fmt.Sprintf("<div class=\"src src-inline src-%s\">\n%s\n</div>", lang, content))
|
w.WriteString(fmt.Sprintf("<div class=\"src src-inline src-%s\">\n%s\n</div>", lang, content))
|
||||||
case "export":
|
case "export":
|
||||||
if strings.ToLower(b.Parameters[0]) == "html" {
|
if strings.ToLower(b.Parameters[0]) == "html" {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue