Documentation
¶
Overview ¶
Package markdown implements Code snippet/section extraction from markdown sources. As it uses github.com/yuin/goldmark it is compliant with CommonMark 0.30.
It can deal with all 3 different types of code sections defined in CommonMark:
- inline code spans, referred to as Kind Inline
- indented code blocks, referred to as Kind Block
- fenced code blocks, referred to as Kind BlockWithLang
Check the example to see what data is collected for each Code in CodeSections.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Log = slog.Default()
Log is the logger used within markdown and can be overwritten by package users to achieve alternative logging behavior such as different outputs or a different level. Uses log/slog for structured logs.
Functions ¶
This section is empty.
Types ¶
type Code ¶
type Code struct { // Description is the closest text to the code snippet which describes the snippet. Description string `json:"description" yaml:"description"` // [Kind] provides the type of markdown code section. Kind Kind `json:"kind" yaml:"kind"` // [Position] in the source file, includes the Description source. Position Position `json:"pos" yaml:"pos"` // Language contains the language defined for the code section. // If no language was defined it is "". Language string `json:"language,omitempty" yaml:"language,omitempty"` // Text contains the complete text of the code section. // This can be multiple lines and will always end with "\n". Text string `json:"code" yaml:"code"` }
Code describes a Code section extracted from a markdown source.
type CodeSections ¶
type CodeSections []*Code
CodeSections contain multiple Code sections.
func ExtractCodeSections ¶
func ExtractCodeSections(source []byte) (CodeSections, error)
ExtractCodeSections parses and walks the provided markdown source to extract all Code sections within.
type Kind ¶
type Kind int
A Kind is used to identify the type of Code section. See package doc for references to the CommonMark spec. The methods are managed by github.com/alvaroloes/enumer.
func KindString ¶
KindString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.
func (Kind) IsAKind ¶
IsAKind returns "true" if the value is listed in the enum definition. "false" otherwise
func (Kind) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface for Kind
func (Kind) MarshalYAML ¶
MarshalYAML implements a YAML Marshaler for Kind
func (*Kind) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface for Kind
func (*Kind) UnmarshalYAML ¶
UnmarshalYAML implements a YAML Unmarshaler for Kind