package components
import "shirakumo.org/markless/components"
Component types to represent the abstract syntax tree of a parsed Markless document.
If you would like to create your own component types, you must implement the Component interface. To help with that, you may want to embed the ParentComponent or LeafComponent structs, which will take care of most of the mundane interface methods for you.
You must always however implement Name and Kind itself in order to inform the component mapping.
Index
- Constants
- type Align
- type Alignment
- type Blockquote
- type BlockquoteHeader
- type Bold
- type Code
- type CodeBlock
- type Comment
- type Component
- type Compound
- type EmDash
- type Embed
- type EnDash
- type Footnote
- type FootnoteReference
- type Header
- type HorizontalRule
- type Instruction
- type Italic
- type Kind
- type LeafComponent
- type Newline
- type Option
- type OrderedList
- type OrderedListItem
- type Paragraph
-
type ParentComponent
- func (c *ParentComponent) AsParent() *ParentComponent
- func (c *ParentComponent) Condense() *ParentComponent
- func (c *ParentComponent) IsParent() bool
- func (c *ParentComponent) Kind() Kind
- func (c *ParentComponent) Name() string
- func (c *ParentComponent) Pop() *ParentComponent
- func (c *ParentComponent) Push(child Component) *ParentComponent
- func (c *ParentComponent) PushFront(child Component) *ParentComponent
- func (c *ParentComponent) Replace(child Component, replacement Component) *ParentComponent
- func (c *ParentComponent) Text() string
- type Root
- type Strikethrough
- type Subtext
- type Supertext
- type Text
- type URL
- type Underline
- type UnitOption
- type UnorderedList
- type UnorderedListItem
- type ValueOption
Constants
const ( AlignLeft = 0 AlignRight = 1 Center = 2 Justify = 3 )
const ( Undefined = 0 Block = 1 Inline = 2 )
Types
type Align
type Align struct { ParentComponent Alignment Alignment }
func NewAlign
func NewAlign(alignment Alignment) *Align
func (*Align) Kind
func (c *Align) Kind() Kind
func (*Align) Name
func (c *Align) Name() string
type Alignment
type Alignment int
The alignments that can be used in an Align component. Should be one of AlignLeft, AlignRight, Center, or Justify.
type Blockquote
type Blockquote struct { ParentComponent Source *BlockquoteHeader Indentation int }
func NewBlockquote
func NewBlockquote(source *BlockquoteHeader, indentation int) *Blockquote
func (*Blockquote) Kind
func (c *Blockquote) Kind() Kind
func (*Blockquote) Name
func (c *Blockquote) Name() string
type BlockquoteHeader
type BlockquoteHeader struct { ParentComponent }
func NewBlockquoteHeader
func NewBlockquoteHeader() *BlockquoteHeader
func (*BlockquoteHeader) Kind
func (c *BlockquoteHeader) Kind() Kind
func (*BlockquoteHeader) Name
func (c *BlockquoteHeader) Name() string
type Bold
type Bold struct { ParentComponent }
func NewBold
func NewBold() *Bold
func (*Bold) Kind
func (c *Bold) Kind() Kind
func (*Bold) Name
func (c *Bold) Name() string
type Code
type Code struct { ParentComponent }
func NewCode
func NewCode() *Code
func (*Code) Kind
func (c *Code) Kind() Kind
func (*Code) Name
func (c *Code) Name() string
type CodeBlock
type CodeBlock struct { LeafComponent Content string Language string Options []string Depth int Inset int }
func NewCodeBlock
func NewCodeBlock(language string, options []string, depth int, inset int) *CodeBlock
func (*CodeBlock) Kind
func (c *CodeBlock) Kind() Kind
func (*CodeBlock) Name
func (c *CodeBlock) Name() string
func (*CodeBlock) Text
func (c *CodeBlock) Text() string
type Comment
type Comment struct { LeafComponent // contains filtered or unexported fields }
func NewComment
func NewComment(text string) *Comment
func (*Comment) Kind
func (c *Comment) Kind() Kind
func (*Comment) Name
func (c *Comment) Name() string
func (*Comment) Text
func (c *Comment) Text() string
type Component
type Component interface { Name() string Kind() Kind IsParent() bool AsParent() *ParentComponent Text() string }
Representation of a node in the AST of a Markless document.
type Compound
type Compound struct { ParentComponent Options []Option }
func NewCompound
func NewCompound() *Compound
func (*Compound) Kind
func (c *Compound) Kind() Kind
func (*Compound) Name
func (c *Compound) Name() string
type EmDash
type EmDash struct { LeafComponent }
func NewEmDash
func NewEmDash() *EmDash
func (*EmDash) Kind
func (c *EmDash) Kind() Kind
func (*EmDash) Name
func (c *EmDash) Name() string
func (*EmDash) Text
func (c *EmDash) Text() string
type Embed
type Embed struct { LeafComponent Type string Target string Options []Option }
func NewEmbed
func NewEmbed(kind string, target string, options []Option) *Embed
func (*Embed) Kind
func (c *Embed) Kind() Kind
func (*Embed) Name
func (c *Embed) Name() string
func (*Embed) Text
func (c *Embed) Text() string
type EnDash
type EnDash struct { LeafComponent }
func NewEnDash
func NewEnDash() *EnDash
func (*EnDash) Kind
func (c *EnDash) Kind() Kind
func (*EnDash) Name
func (c *EnDash) Name() string
func (*EnDash) Text
func (c *EnDash) Text() string
type Footnote
type Footnote struct { ParentComponent Target int }
func NewFootnote
func NewFootnote(target int) *Footnote
func (*Footnote) Kind
func (c *Footnote) Kind() Kind
func (*Footnote) Name
func (c *Footnote) Name() string
type FootnoteReference
type FootnoteReference struct { LeafComponent Target int }
func NewFootnoteReference
func NewFootnoteReference(target int) *FootnoteReference
func (*FootnoteReference) Kind
func (c *FootnoteReference) Kind() Kind
func (*FootnoteReference) Name
func (c *FootnoteReference) Name() string
func (*FootnoteReference) Text
func (c *FootnoteReference) Text() string
type Header
type Header struct { ParentComponent Level int }
func NewHeader
func NewHeader(level int) *Header
func (*Header) Kind
func (c *Header) Kind() Kind
func (*Header) Name
func (c *Header) Name() string
type HorizontalRule
type HorizontalRule struct { LeafComponent }
func NewHorizontalRule
func NewHorizontalRule() *HorizontalRule
func (*HorizontalRule) Kind
func (c *HorizontalRule) Kind() Kind
func (*HorizontalRule) Name
func (c *HorizontalRule) Name() string
type Instruction
type Instruction struct { LeafComponent Type string Arguments []string }
func NewInstruction
func NewInstruction(kind string, arguments []string) *Instruction
func (*Instruction) Kind
func (c *Instruction) Kind() Kind
func (*Instruction) Name
func (c *Instruction) Name() string
func (*Instruction) Text
func (c *Instruction) Text() string
type Italic
type Italic struct { ParentComponent }
func NewItalic
func NewItalic() *Italic
func (*Italic) Kind
func (c *Italic) Kind() Kind
func (*Italic) Name
func (c *Italic) Name() string
type Kind
type Kind int
The kind of components that can exist. Should be one of Block or Inline for any actual components, or Undefined for helpers.
type LeafComponent
type LeafComponent struct { }
Helper mixin for Component types that cannot contain other components
func NewLeafComponent
func NewLeafComponent() *LeafComponent
Constructs a standalone LeafComponent Useful for injecting placeholder components.
func (*LeafComponent) AsParent
func (c *LeafComponent) AsParent() *ParentComponent
Casts the component to a ParentComponent if possible, or returns nil if not. Returns nil.
func (*LeafComponent) IsParent
func (c *LeafComponent) IsParent() bool
Whether the component can be cast to a ParentComponent via [AsParent]. Always false.
func (*LeafComponent) Kind
func (c *LeafComponent) Kind() Kind
The kind of component this is. Should be one of Block or Inline for any actual components, or Undefined for helpers.
func (*LeafComponent) Name
func (c *LeafComponent) Name() string
Returns the markless-standardised name of the component type. This is usually an all-lowercase name composed of alphabetic characters and dashes.
func (*LeafComponent) Text
func (c *LeafComponent) Text() string
Returns an empty string.
type Newline
type Newline struct { LeafComponent }
func NewNewline
func NewNewline() *Newline
func (*Newline) Kind
func (c *Newline) Kind() Kind
func (*Newline) Name
func (c *Newline) Name() string
func (*Newline) Text
func (c *Newline) Text() string
type Option
type Option interface { Name() string }
Interface for any option in embed or compound directives.
type OrderedList
type OrderedList struct { ParentComponent }
func NewOrderedList
func NewOrderedList() *OrderedList
func (*OrderedList) Kind
func (c *OrderedList) Kind() Kind
func (*OrderedList) Name
func (c *OrderedList) Name() string
type OrderedListItem
type OrderedListItem struct { ParentComponent Number int }
func NewOrderedListItem
func NewOrderedListItem(number int) *OrderedListItem
func (*OrderedListItem) Kind
func (c *OrderedListItem) Kind() Kind
func (*OrderedListItem) Name
func (c *OrderedListItem) Name() string
type Paragraph
type Paragraph struct { ParentComponent Indentation int }
func NewParagraph
func NewParagraph(indentation int) *Paragraph
func (*Paragraph) Kind
func (c *Paragraph) Kind() Kind
func (*Paragraph) Name
func (c *Paragraph) Name() string
type ParentComponent
type ParentComponent struct { // Array of child components contained Children []Component }
Helper mixin for Component types that can contain other components
func (*ParentComponent) AsParent
func (c *ParentComponent) AsParent() *ParentComponent
Casts the component to a ParentComponent if possible, or returns nil if not. Returns the component again.
func (*ParentComponent) Condense
func (c *ParentComponent) Condense() *ParentComponent
Condenses the children in the component subtree down to remove pointless intermediaries. This will flatten out base [ParentComponent]s, remove base [LeafComponent]s, remove [Comment]s and [Instruction]s, and merge adjacent Text. Finally returns the same parent component again.
func (*ParentComponent) IsParent
func (c *ParentComponent) IsParent() bool
Whether the component can be cast to a ParentComponent via [AsParent]. Always true.
func (*ParentComponent) Kind
func (c *ParentComponent) Kind() Kind
The kind of component this is. Should be one of Block or Inline for any actual components, or Undefined for helpers.
func (*ParentComponent) Name
func (c *ParentComponent) Name() string
Returns the markless-standardised name of the component type. This is usually an all-lowercase name composed of alphabetic characters and dashes.
func (*ParentComponent) Pop
func (c *ParentComponent) Pop() *ParentComponent
Pops off the last child of the component, if any, and returns the parent again.
func (*ParentComponent) Push
func (c *ParentComponent) Push(child Component) *ParentComponent
Pushes the child to the back of the children in this component and returns the parent again.
func (*ParentComponent) PushFront
func (c *ParentComponent) PushFront(child Component) *ParentComponent
Pushes the child to the front of the children in this component and returns the parent again.
func (*ParentComponent) Replace
func (c *ParentComponent) Replace(child Component, replacement Component) *ParentComponent
Replaces the child with the replacement and returns the parent again. If the child is not contained in the parent, this does nothing.
func (*ParentComponent) Text
func (c *ParentComponent) Text() string
Returns the textual content of the entire subtree encompassed by the component.
type Root
type Root struct { ParentComponent Labels map[string]*Component Author string Copyright string Language string }
func NewRoot
func NewRoot() *Root
func (*Root) Kind
func (c *Root) Kind() Kind
func (*Root) Name
func (c *Root) Name() string
type Strikethrough
type Strikethrough struct { ParentComponent }
func NewStrikethrough
func NewStrikethrough() *Strikethrough
func (*Strikethrough) Kind
func (c *Strikethrough) Kind() Kind
func (*Strikethrough) Name
func (c *Strikethrough) Name() string
type Subtext
type Subtext struct { ParentComponent }
func NewSubtext
func NewSubtext() *Subtext
func (*Subtext) Kind
func (c *Subtext) Kind() Kind
func (*Subtext) Name
func (c *Subtext) Name() string
type Supertext
type Supertext struct { ParentComponent }
func NewSupertext
func NewSupertext() *Supertext
func (*Supertext) Kind
func (c *Supertext) Kind() Kind
func (*Supertext) Name
func (c *Supertext) Name() string
type Text
type Text string
Strings must be encapsulated in this text type that implements the Component interface.
func (Text) AsParent
func (c Text) AsParent() *ParentComponent
Returns nil.
func (Text) IsParent
func (c Text) IsParent() bool
Returns false.
func (Text) Kind
func (c Text) Kind() Kind
Returns Inline.
func (Text) Name
func (c Text) Name() string
Returns "string".
func (Text) Text
func (c Text) Text() string
Returns the string.
type URL
type URL struct { LeafComponent Target string }
func NewURL
func NewURL(target string) *URL
func (*URL) Kind
func (c *URL) Kind() Kind
func (*URL) Name
func (c *URL) Name() string
func (*URL) Text
func (c *URL) Text() string
type Underline
type Underline struct { ParentComponent }
func NewUnderline
func NewUnderline() *Underline
func (*Underline) Kind
func (c *Underline) Kind() Kind
func (*Underline) Name
func (c *Underline) Name() string
type UnitOption
type UnitOption struct { Unit string Value float32 }
Helper mixin for Option types that represent a unit/size value. See ParseUnitOption to parse the option from its string representation.
func ParseUnitOption
func ParseUnitOption(args string) *UnitOption
Parses a unit representation from the given string. If the parse fails, nil is returned. A unit is an integer or rational, followed by the unit type, which can be either "px", "em", "pt", or "%".
type UnorderedList
type UnorderedList struct { ParentComponent }
func NewUnorderedList
func NewUnorderedList() *UnorderedList
func (*UnorderedList) Kind
func (c *UnorderedList) Kind() Kind
func (*UnorderedList) Name
func (c *UnorderedList) Name() string
type UnorderedListItem
type UnorderedListItem struct { ParentComponent }
func NewUnorderedListItem
func NewUnorderedListItem() *UnorderedListItem
func (*UnorderedListItem) Kind
func (c *UnorderedListItem) Kind() Kind
func (*UnorderedListItem) Name
func (c *UnorderedListItem) Name() string
type ValueOption
type ValueOption struct { Value string }
Helper mixin for Option types that represent a single value string.