document

package
v3.2.5 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultAttributeParser = newFailoverAttributeParser(
	[]attributeParser{
		&jsonParser{},
		&babikMLParser{},
	},
	&jsonParser{},
)
View Source
var ErrFrontmatterInvalid = stderrors.New("invalid frontmatter")

Functions

func CountTrailingLineBreaks

func CountTrailingLineBreaks(source []byte, lineBreak []byte) int

func DetectLineBreak

func DetectLineBreak(source []byte) []byte

Types

type Attributes

type Attributes map[string]string

type Block

type Block interface {
	Kind() BlockKind
	Unwrap() ast.Node
	Value() []byte
}

type BlockKind

type BlockKind int
const (
	InnerBlockKind BlockKind = iota + 1
	CodeBlockKind
	MarkdownBlockKind
)

type Blocks

type Blocks []Block

type CodeBlock

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

func (*CodeBlock) Attributes

func (b *CodeBlock) Attributes() map[string]string

func (*CodeBlock) Background

func (b *CodeBlock) Background() bool

func (*CodeBlock) Categories

func (b *CodeBlock) Categories() []string

func (*CodeBlock) Clone

func (b *CodeBlock) Clone() *CodeBlock

func (*CodeBlock) Content

func (b *CodeBlock) Content() []byte

func (*CodeBlock) Cwd

func (b *CodeBlock) Cwd() string

func (*CodeBlock) Document

func (b *CodeBlock) Document() *Document

func (*CodeBlock) ExcludeFromRunAll

func (b *CodeBlock) ExcludeFromRunAll() bool

func (*CodeBlock) FirstLine added in v3.2.5

func (b *CodeBlock) FirstLine() string

func (*CodeBlock) ID

func (b *CodeBlock) ID() string

func (*CodeBlock) Interactive

func (b *CodeBlock) Interactive() bool

func (*CodeBlock) Interpreter

func (b *CodeBlock) Interpreter() string

func (*CodeBlock) Intro

func (b *CodeBlock) Intro() string

func (*CodeBlock) IsUnknown

func (b *CodeBlock) IsUnknown() bool

func (*CodeBlock) IsUnnamed

func (b *CodeBlock) IsUnnamed() bool

func (CodeBlock) Kind

func (CodeBlock) Kind() BlockKind

func (*CodeBlock) Language

func (b *CodeBlock) Language() string

func (*CodeBlock) Lines

func (b *CodeBlock) Lines() []string

func (*CodeBlock) MarshalJSON added in v3.2.5

func (b *CodeBlock) MarshalJSON() ([]byte, error)

func (*CodeBlock) Name

func (b *CodeBlock) Name() string

func (*CodeBlock) PromptEnv

func (b *CodeBlock) PromptEnv() bool

func (*CodeBlock) SetLine

func (b *CodeBlock) SetLine(p int, v string)

func (*CodeBlock) TextRange

func (b *CodeBlock) TextRange() (textRange TextRange)

func (*CodeBlock) Unwrap

func (b *CodeBlock) Unwrap() ast.Node

func (*CodeBlock) Value

func (b *CodeBlock) Value() []byte

type CodeBlocks

type CodeBlocks []*CodeBlock

func CollectCodeBlocks

func CollectCodeBlocks(node *Node) (result CodeBlocks)

func (CodeBlocks) Names

func (b CodeBlocks) Names() (result []string)

type Document

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

func New

func New(source []byte, identityResolver identityResolver) *Document

func (*Document) Content

func (d *Document) Content() []byte

func (*Document) ContentOffset

func (d *Document) ContentOffset() int

ContentOffset returns the position of source from which the actual content starts. If a value <0 is returned, it means that the source is not parsed yet.

Frontmatter is not a part of the content.

func (*Document) Frontmatter

func (d *Document) Frontmatter() (*Frontmatter, error)

func (*Document) Parse

func (d *Document) Parse() error

func (*Document) Root

func (d *Document) Root() (*Node, error)

func (*Document) RootAST

func (d *Document) RootAST() (ast.Node, error)

func (*Document) TrailingLineBreaksCount

func (d *Document) TrailingLineBreaksCount() int

type Frontmatter

type Frontmatter struct {
	Runme       RunmeMetadata `yaml:"runme,omitempty"`
	Shell       string        `yaml:"shell"`
	Cwd         string        `yaml:"cwd"`
	Category    string        `yaml:"category"`
	SkipPrompts bool          `yaml:"skipPrompts,omitempty"`
	// contains filtered or unexported fields
}

func ParseFrontmatter

func ParseFrontmatter(raw []byte) (*Frontmatter, error)

TODO(adamb): it should be removed when the complete refactoring of the project is finished.

func (*Frontmatter) Marshal

func (f *Frontmatter) Marshal(requireIdentity bool) ([]byte, error)

Marshal returns a marshaled frontmatter including triple-dashed lines. If the identity is required, but Frontmatter is nil, a new one is created.

type InnerBlock

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

InnerBlock represents a non-leaf block. It helps to handle nested fenced code blocks for block quotes and list items.

func (InnerBlock) Kind

func (InnerBlock) Kind() BlockKind

func (*InnerBlock) Unwrap

func (b *InnerBlock) Unwrap() ast.Node

func (*InnerBlock) Value

func (b *InnerBlock) Value() []byte

type MarkdownBlock

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

func (MarkdownBlock) Kind

func (MarkdownBlock) Kind() BlockKind

func (*MarkdownBlock) Unwrap

func (b *MarkdownBlock) Unwrap() ast.Node

func (*MarkdownBlock) Value

func (b *MarkdownBlock) Value() []byte

type Node

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

func FindNode

func FindNode(node *Node, fn func(*Node) bool) *Node

func (*Node) Bytes

func (n *Node) Bytes() []byte

func (*Node) Children

func (n *Node) Children() []*Node

func (*Node) Index

func (n *Node) Index() int

func (*Node) InsertAt

func (n *Node) InsertAt(idx int, item Block) *Node

func (*Node) Item

func (n *Node) Item() Block

func (*Node) Parent

func (n *Node) Parent() *Node

func (*Node) Remove

func (n *Node) Remove(nodeToRemove *Node) bool

func (*Node) String

func (n *Node) String() string

type ParsedSections

type ParsedSections struct {
	FrontMatter   []byte
	Content       []byte
	ContentOffset int
}

func ParseSections

func ParseSections(source []byte) (result ParsedSections, _ error)

type RunmeMetadata

type RunmeMetadata struct {
	ID       string                `yaml:"id,omitempty" json:"id,omitempty" toml:"id,omitempty"`
	Version  string                `yaml:"version,omitempty" json:"version,omitempty" toml:"version,omitempty"`
	Document RunmeMetadataDocument `yaml:"document,omitempty" json:"document,omitempty" toml:"document,omitempty"`
	Session  RunmeMetadataSession  `yaml:"session,omitempty" json:"session,omitempty" toml:"session,omitempty"`
}

type RunmeMetadataDocument

type RunmeMetadataDocument struct {
	RelativePath string `yaml:"relativePath,omitempty" json:"relativePath,omitempty" toml:"relativePath,omitempty"`
}

type RunmeMetadataSession

type RunmeMetadataSession struct {
	ID      string `yaml:"id,omitempty" json:"id,omitempty" toml:"id,omitempty"`
	Updated string `yaml:"updated,omitempty" json:"updated,omitempty" toml:"updated,omitempty"`
}

type TextRange

type TextRange struct {
	Start int
	End   int
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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