git.sr.ht/~pingoo/stdx@v0.0.0-20240218134121-094174641f6e/goldmark-highlighting/README.md (about)

     1  goldmark-highlighting
     2  =========================
     3  
     4  goldmark-highlighting is an extension for the [goldmark](http://github.com/yuin/goldmark) 
     5  that adds syntax-highlighting to the fenced code blocks.
     6  
     7  goldmark-highlighting uses [chroma](https://github.com/alecthomas/chroma) as a
     8  syntax highlighter.
     9  
    10  Installation
    11  --------------------
    12  
    13  ```
    14  go get github.com/yuin/goldmark-highlighting/v2
    15  ```
    16  
    17  Usage
    18  --------------------
    19  
    20  ```go
    21  import (
    22      "bytes"
    23      "fmt"
    24      "github.com/alecthomas/chroma/formatters/html"
    25      "github.com/yuin/goldmark"
    26      "github.com/yuin/goldmark/extension"
    27      "github.com/yuin/goldmark/parser"
    28      "github.com/yuin/goldmark-highlighting/v2"
    29  
    30  )
    31  
    32  func main() {
    33      markdown := goldmark.New(
    34          goldmark.WithExtensions(
    35              highlighting.Highlighting,
    36          ),
    37      )
    38      var buf bytes.Buffer
    39      if err := markdown.Convert([]byte(source), &buf); err != nil {
    40          panic(err)
    41      }
    42      fmt.Print(title)
    43  }
    44  ```
    45  
    46  
    47  ```go
    48      markdown := goldmark.New(
    49          goldmark.WithExtensions(
    50              highlighting.NewHighlighting(
    51                 highlighting.WithStyle("monokai"),
    52                 highlighting.WithFormatOptions(
    53                     html.WithLineNumbers(),
    54                 ),
    55              ),
    56          ),
    57      )
    58  ```
    59  
    60  License
    61  --------------------
    62  MIT
    63  
    64  Author
    65  --------------------
    66  Yusuke Inuzuka