Documentation ¶
Overview ¶
Package markdown renders the given goldmark AST to Markdown.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var GoCodeFormatter = CodeFormatter{ Name: "go", Aliases: []string{"Go"}, Format: formatGo, }
GoCodeFormatter is a CodeFormatter that reformats Go source code inside fenced code blocks tagged with 'go' or 'Go'.
```go func main() { } ```
Supply it to the renderer with WithCodeFormatters.
Functions ¶
This section is empty.
Types ¶
type CodeFormatter ¶
type CodeFormatter struct { // Name of the language. Name string // Aliases for the language, if any. Aliases []string // Function to format the code snippet. // In case of errors, format functions should typically return // the original string unchanged. Format func([]byte) []byte }
CodeFormatter reformats code samples found in the document, matching them by name.
type ListIndentStyle ¶ added in v3.1.0
type ListIndentStyle int
ListIndentStyle specifies how items nested inside lists should be indented.
const ( // ListIndentAligned specifies that items inside a list item // should be aligned to the content in the first item. // // - First paragraph. // // Second paragraph aligned with the first. // // This applies to ordered lists too. // // 1. First paragraph. // // Second paragraph aligned with the first. // // ... // // 10. Contents. // // Long lists indent content further. // // This is the default. ListIndentAligned ListIndentStyle = iota // ListIndentUniform specifies that items inside a list item // should be aligned uniformly with 4 spaces. // // For example: // // - First paragraph. // // Second paragraph indented 4 spaces. // // For ordered lists: // // 1. First paragraph. // // Second paragraph indented 4 spaces. // // ... // // 10. Contents. // // Always indented 4 spaces. ListIndentUniform )
type Option ¶
Option customizes the behavior of the markdown renderer.
func WithCodeFormatters ¶
func WithCodeFormatters(fs ...CodeFormatter) Option
WithCodeFormatters changes the functions used to reformat code blocks found in the original file.
formatters := []markdown.CodeFormatter{ markdown.GoCodeFormatter, // ... } r := NewRenderer() r.AddMarkdownOptions(WithCodeFormatters(formatters...))
Defaults to empty.
func WithEmphasisToken ¶
WithEmphasisToken specifies the character used to wrap emphasised text. Per the CommonMark spec, valid values are '*' and '_'.
Defaults to '*'.
func WithListIndentStyle ¶ added in v3.1.0
func WithListIndentStyle(style ListIndentStyle) Option
WithListIndentStyle specifies how contents nested under a list item should be indented.
Defaults to ListIndentAligned.
func WithSoftWraps ¶
func WithSoftWraps() Option
WithSoftWraps allows you to wrap lines even on soft line breaks.
func WithStrongToken ¶
WithStrongToken specifies the string used to wrap bold text. Per the CommonMark spec, valid values are '**' and '__'.
Defaults to repeating the emphasis token twice. See WithEmphasisToken for how to change that.
func WithUnderlineHeadings ¶
func WithUnderlineHeadings() Option
WithUnderlineHeadings configures the renderer to use Setext-style headers (=== and ---).
type Renderer ¶
type Renderer struct {
// contains filtered or unexported fields
}
Renderer allows to render markdown AST into markdown bytes in consistent format. Render is reusable across Renders, it holds configuration only.
func NewRenderer ¶
func NewRenderer() *Renderer
NewRenderer builds a new Markdown renderer with default settings. To use this with goldmark.Markdown, use the goldmark.WithRenderer option.
r := markdown.NewRenderer() md := goldmark.New(goldmark.WithRenderer(r)) md.Convert(src, w)
Alternatively, you can call Renderer.Render directly.
r := markdown.NewRenderer() r.Render(w, src, node)
Use Renderer.AddMarkdownOptions to customize the output of the renderer.
func (*Renderer) AddMarkdownOptions ¶
AddMarkdownOptions modifies the Renderer with the given options.
func (*Renderer) AddOptions ¶
AddOptions pulls Markdown renderer specific options from the given list, and applies them to the renderer.