fence

package
v1.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package fence is the one grammar for ":::" directive fence lines. The Goldmark container parsers (through blockutil), sarde check-syntax and the content_lint plugin all classify lines with it, so a fence means the same thing to the renderer and to the tools that check content before a build.

Index

Constants

This section is empty.

Variables

View Source
var AsideTypes = []string{
	"note", "tip", "info", "danger", "warning", "important", "caution",
	"gh-note", "gh-tip", "gh-important", "gh-warning", "gh-caution",
}

AsideTypes lists the aside names the aside extension opens. The aside parser's ValidTypes set is built from it, and ":::/aside" closes any of them.

Functions

func Closes

func Closes(closer, opener string) bool

Closes reports whether ":::/closer" closes a block opened as ":::opener". Names compare case-insensitively.

func FindClosable

func FindClosable(names []string, closer string) int

FindClosable returns the index of the innermost (last) name in names that closer closes, or -1.

Types

type CodeFence

type CodeFence struct {
	// contains filtered or unexported fields
}

CodeFence tracks fenced code blocks line by line. An opener is a run of three or more backticks or tildes; the closer is a run of the same character at least as long, alone on its line.

func (*CodeFence) Feed

func (c *CodeFence) Feed(trimmed string) bool

Feed reports whether trimmed is inside a fenced code block, counting the opening and closing fence lines themselves.

func (*CodeFence) Inside

func (c *CodeFence) Inside() bool

Inside reports whether the tracker is currently inside a code block.

type Fence

type Fence struct {
	Kind   Kind
	Name   string // lowercased; empty for a bare closer or a nameless Malformed
	Colons int
}

Fence describes one classified line.

func Classify

func Classify(trimmed string) Fence

Classify reads a whitespace-trimmed line. The opener name is the run of word characters and hyphens after the colons and optional spaces; a named closer must end right after its name.

type Kind

type Kind int

Kind classifies a trimmed line.

const (
	// None is a line that is not a fence.
	None Kind = iota
	// Open is ":::name ..." with three or more colons.
	Open
	// Close is a bare ":::" or a named ":::/name" with nothing else on the line.
	Close
	// Malformed is ":::/" followed by something the parsers reject, such as
	// ":::/ note" or ":::/note extra". Parsers treat it as content; the
	// checker reports it.
	Malformed
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL