package
0.0.0-20241226145920-483c662f7ff1
Repository: https://github.com/pingooio/stdx.git
Documentation: pkg.go.dev

# README

goldmark-highlighting

goldmark-highlighting is an extension for the goldmark that adds syntax-highlighting to the fenced code blocks.

goldmark-highlighting uses chroma as a syntax highlighter.

Installation

go get github.com/yuin/goldmark-highlighting/v2

Usage

import (
    "bytes"
    "fmt"
    "github.com/alecthomas/chroma/formatters/html"
    "github.com/yuin/goldmark"
    "github.com/yuin/goldmark/extension"
    "github.com/yuin/goldmark/parser"
    "github.com/yuin/goldmark-highlighting/v2"

)

func main() {
    markdown := goldmark.New(
        goldmark.WithExtensions(
            highlighting.Highlighting,
        ),
    )
    var buf bytes.Buffer
    if err := markdown.Convert([]byte(source), &buf); err != nil {
        panic(err)
    }
    fmt.Print(title)
}
    markdown := goldmark.New(
        goldmark.WithExtensions(
            highlighting.NewHighlighting(
               highlighting.WithStyle("monokai"),
               highlighting.WithFormatOptions(
                   html.WithLineNumbers(),
               ),
            ),
        ),
    )

License

MIT

Author

Yusuke Inuzuka

# Functions

NewConfig returns a new Config with defaults.
NewHighlighting returns a new extension with given options.
NewHTMLRenderer builds a new HTMLRenderer with given options and returns it.
WithCodeBlockOptions is a functional option that sets CodeBlockOptions that allows setting Chroma options per code block.
WithCSSWriter is a functional option that sets io.Writer for CSS data.
WithStyle is a functional option that changes highlighting style.
WithFormatOptions is a functional option that wraps chroma HTML formatter options.
WithGuessLanguage is a functional option that toggles language guessing if none provided.
WithHTMLOptions is functional option that wraps goldmark HTMLRenderer options.
WithStyle is a functional option that changes highlighting style.
WithWrapperRenderer is a functional option that sets WrapperRenderer that renders wrapper elements like div, pre, etc.

# Variables

Highlighting is a goldmark.Extender implementation.

# Structs

Config struct holds options for the extension.
HTMLRenderer struct is a renderer.NodeRenderer implementation for the extension.

# Interfaces

CodeBlockContext holds contextual information of code highlighting.
ImmutableAttributes is a read-only interface for ast.Attributes.
Option interface is a functional option interface for the extension.

# Type aliases

CodeBlockOptions creates Chroma options per code block.
WrapperRenderer renders wrapper elements like div, pre, etc.