zsx

package module
v0.0.0-...-3095aa2 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: EUPL-1.2 Imports: 8 Imported by: 6

Documentation

Overview

Package zsx contains zettel data handling as sx expressions.

Index

Constants

View Source
const DefaultAttribute = "-"

DefaultAttribute is the value of the key of the default attribute

View Source
const (
	// SyntaxSVG specifies the special syntax "svg", because a BLOB node
	// with this syntax will *not* encode its data.
	SyntaxSVG = "svg"
)

Some additional constants.

Variables

View Source
var (
	// Symbols for Metanodes
	SymBlock  = sx.MakeSymbol("BLOCK")
	SymInline = sx.MakeSymbol("INLINE")

	// Symbols for Zettel node types.
	SymBLOB            = sx.MakeSymbol("BLOB")
	SymCell            = sx.MakeSymbol("CELL")
	SymCite            = sx.MakeSymbol("CITE")
	SymDescription     = sx.MakeSymbol("DESCRIPTION")
	SymEmbed           = sx.MakeSymbol("EMBED")
	SymEmbedBLOB       = sx.MakeSymbol("EMBED-BLOB")
	SymEndnote         = sx.MakeSymbol("ENDNOTE")
	SymFormatEmph      = sx.MakeSymbol("FORMAT-EMPH")
	SymFormatDelete    = sx.MakeSymbol("FORMAT-DELETE")
	SymFormatInsert    = sx.MakeSymbol("FORMAT-INSERT")
	SymFormatMark      = sx.MakeSymbol("FORMAT-MARK")
	SymFormatQuote     = sx.MakeSymbol("FORMAT-QUOTE")
	SymFormatSpan      = sx.MakeSymbol("FORMAT-SPAN")
	SymFormatSub       = sx.MakeSymbol("FORMAT-SUB")
	SymFormatSuper     = sx.MakeSymbol("FORMAT-SUPER")
	SymFormatStrong    = sx.MakeSymbol("FORMAT-STRONG")
	SymHard            = sx.MakeSymbol("HARD")
	SymHeading         = sx.MakeSymbol("HEADING")
	SymLink            = sx.MakeSymbol("LINK")
	SymListOrdered     = sx.MakeSymbol("ORDERED")
	SymListUnordered   = sx.MakeSymbol("UNORDERED")
	SymListQuote       = sx.MakeSymbol("QUOTATION")
	SymLiteralCode     = sx.MakeSymbol("LITERAL-CODE")
	SymLiteralComment  = sx.MakeSymbol("LITERAL-COMMENT")
	SymLiteralInput    = sx.MakeSymbol("LITERAL-INPUT")
	SymLiteralMath     = sx.MakeSymbol("LITERAL-MATH")
	SymLiteralOutput   = sx.MakeSymbol("LITERAL-OUTPUT")
	SymMark            = sx.MakeSymbol("MARK")
	SymPara            = sx.MakeSymbol("PARA")
	SymRegionBlock     = sx.MakeSymbol("REGION-BLOCK")
	SymRegionQuote     = sx.MakeSymbol("REGION-QUOTE")
	SymRegionVerse     = sx.MakeSymbol("REGION-VERSE")
	SymSoft            = sx.MakeSymbol("SOFT")
	SymTable           = sx.MakeSymbol("TABLE")
	SymText            = sx.MakeSymbol("TEXT")
	SymThematic        = sx.MakeSymbol("THEMATIC")
	SymTransclude      = sx.MakeSymbol("TRANSCLUDE")
	SymUnknown         = sx.MakeSymbol("UNKNOWN")
	SymVerbatimCode    = sx.MakeSymbol("VERBATIM-CODE")
	SymVerbatimComment = sx.MakeSymbol("VERBATIM-COMMENT")
	SymVerbatimEval    = sx.MakeSymbol("VERBATIM-EVAL")
	SymVerbatimHTML    = sx.MakeSymbol("VERBATIM-HTML")
	SymVerbatimMath    = sx.MakeSymbol("VERBATIM-MATH")
	SymVerbatimZettel  = sx.MakeSymbol("VERBATIM-ZETTEL")

	// Constant symbols for reference states.
	SymRefStateExternal = sx.MakeSymbol("EXTERNAL") // e.g. https://t73f.de/links/software
	SymRefStateHosted   = sx.MakeSymbol("HOSTED")   // e.g. ./foo ../foo /foo /foo/bar
	SymRefStateInvalid  = sx.MakeSymbol("INVALID")  // e.g. :t73f.de/r/zsx
	SymRefStateSelf     = sx.MakeSymbol("SELF")     // e.g. . .#ext #ext

	// Special symbol for later splicing nodes in a list.
	//
	// Spicing may occur, if a Walk Visitor wants to return more than one
	// value. The walking processes will (recursively) flatten a splice node
	// into a (flat) list of nodes.
	SymSpecialSplice = sx.MakeSymbol("*SPLICE-NODES*")
)

Various constants for Zettel data. They are technically variables.

View Source
var (
	SymAttrAlign    = sx.MakeSymbol("align")
	AttrAlignCenter = sx.MakeString("center")
	AttrAlignLeft   = sx.MakeString("left")
	AttrAlignRight  = sx.MakeString("right")
)

Constants for attributes and their values

Functions

func GetBLOB

func GetBLOB(node *sx.Pair) (*sx.Pair, string, []byte, *sx.Pair)

GetBLOB returns all elements of a block BLOB node.

func GetBLOBuncode

func GetBLOBuncode(node *sx.Pair) (*sx.Pair, string, string, *sx.Pair)

GetBLOBuncode returns all elements of a block BLOB node and does not decode the BLOB data.

func GetBlock

func GetBlock(node *sx.Pair) *sx.Pair

GetBlock returns all elements of a block node.

func GetCell

func GetCell(node *sx.Pair) (*sx.Pair, *sx.Pair)

GetCell returns all elements of a table cell node.

func GetCite

func GetCite(node *sx.Pair) (*sx.Pair, string, *sx.Pair)

GetCite returns alle elements of a cite node.

func GetDescription

func GetDescription(node *sx.Pair) (*sx.Pair, *sx.Pair)

GetDescription returns the elements of a description list node.

func GetEmbed

func GetEmbed(node *sx.Pair) (*sx.Pair, *sx.Pair, string, *sx.Pair)

GetEmbed returns the elements of an embed node.

func GetEmbedBLOB

func GetEmbedBLOB(node *sx.Pair) (*sx.Pair, string, []byte, *sx.Pair)

GetEmbedBLOB returns all elements of an inline BLOB node.

func GetEmbedBLOBuncode

func GetEmbedBLOBuncode(node *sx.Pair) (*sx.Pair, string, string, *sx.Pair)

GetEmbedBLOBuncode returns all elements of an inline BLOB node. It does not decode the content data.

func GetEndnote

func GetEndnote(node *sx.Pair) (*sx.Pair, *sx.Pair)

GetEndnote returns the elements of an endnote node.

func GetFormat

func GetFormat(node *sx.Pair) (*sx.Symbol, *sx.Pair, *sx.Pair)

GetFormat returns the elements of a formatting node.

func GetHeading

func GetHeading(node *sx.Pair) (int, *sx.Pair, *sx.Pair, string, string)

GetHeading returns the elements of a heading node.

func GetInline

func GetInline(node *sx.Pair) *sx.Pair

GetInline returns all elements of an inline node.

func GetLink(node *sx.Pair) (*sx.Pair, *sx.Pair, *sx.Pair)

GetLink returns the elements of a link node.

func GetList

func GetList(node *sx.Pair) (*sx.Symbol, *sx.Pair, *sx.Pair)

GetList returns the elements of a list node.

func GetLiteral

func GetLiteral(node *sx.Pair) (*sx.Symbol, *sx.Pair, string)

GetLiteral returns the elements of a literal node.

func GetMark

func GetMark(node *sx.Pair) (string, string, string, *sx.Pair)

GetMark returns the elements of a mark node.

func GetPara

func GetPara(node *sx.Pair) *sx.Pair

GetPara returns all elements of a paragraph node.

func GetReference

func GetReference(ref *sx.Pair) (*sx.Symbol, string)

GetReference returns the reference symbol and value.

func GetRegion

func GetRegion(node *sx.Pair) (*sx.Symbol, *sx.Pair, *sx.Pair, *sx.Pair)

GetRegion returns the elements of a region node.

func GetTable

func GetTable(node *sx.Pair) (*sx.Pair, *sx.Pair, *sx.Pair)

GetTable returns the elements of a table.

func GetText

func GetText(node *sx.Pair) string

GetText returns the element of a text node.

func GetThematic

func GetThematic(node *sx.Pair) *sx.Pair

GetThematic returns the elements of a thematic break node.

func GetTransclusion

func GetTransclusion(node *sx.Pair) (*sx.Pair, *sx.Pair, *sx.Pair)

GetTransclusion returns all elements of a tranclude node.

func GetVerbatim

func GetVerbatim(node *sx.Pair) (*sx.Symbol, *sx.Pair, string)

GetVerbatim returns the elements of a verbatim node.

func GetWalkList

func GetWalkList(alst *sx.Pair) *sx.Pair

GetWalkList returns the list of the current node and all subsequent nodes.

func GetWalkPos

func GetWalkPos(alst *sx.Pair) int

GetWalkPos returns the position of the current element in it parent list. It will return -1, if there is no indication about the position.

func GoValue

func GoValue(obj sx.Object) string

GoValue returns the string value of the sx.Object suitable for Go processing.

func MakeBLOB

func MakeBLOB(attrs *sx.Pair, syntax string, data []byte, description *sx.Pair) *sx.Pair

MakeBLOB builds a block BLOB node.

func MakeBLOBuncode

func MakeBLOBuncode(attrs *sx.Pair, syntax string, data string, description *sx.Pair) *sx.Pair

MakeBLOBuncode builds a block BLOB node, but assumes already encoded data.

func MakeBlock

func MakeBlock(blocks ...*sx.Pair) *sx.Pair

MakeBlock builds a block node.

func MakeBlockList

func MakeBlockList(blocks *sx.Pair) *sx.Pair

MakeBlockList builds a block node from a list of blocks.

func MakeCell

func MakeCell(attrs *sx.Pair, inlines *sx.Pair) *sx.Pair

MakeCell builds a table cell node.

func MakeCite

func MakeCite(attrs *sx.Pair, text string, inlines *sx.Pair) *sx.Pair

MakeCite builds a node that specifies a citation.

func MakeEmbed

func MakeEmbed(attrs *sx.Pair, ref sx.Object, syntax string, text *sx.Pair) *sx.Pair

MakeEmbed builds a embed node.

func MakeEmbedBLOB

func MakeEmbedBLOB(attrs *sx.Pair, syntax string, data []byte, inlines *sx.Pair) *sx.Pair

MakeEmbedBLOB builds an embedded inline BLOB node.

func MakeEmbedBLOBuncode

func MakeEmbedBLOBuncode(attrs *sx.Pair, syntax string, data string, inlines *sx.Pair) *sx.Pair

MakeEmbedBLOBuncode builds an embedded inline BLOB node, and does not encode binary content data.

func MakeEndnote

func MakeEndnote(attrs, inlines *sx.Pair) *sx.Pair

MakeEndnote builds an endnote node.

func MakeFormat

func MakeFormat(sym *sx.Symbol, attrs, inlines *sx.Pair) *sx.Pair

MakeFormat builds an inline formatting node.

func MakeHard

func MakeHard() *sx.Pair

MakeHard builds a node for a hard line break.

func MakeHeading

func MakeHeading(level int, attrs, text *sx.Pair, slug, fragment string) *sx.Pair

MakeHeading builds a heading node.

func MakeInline

func MakeInline(inlines ...*sx.Pair) *sx.Pair

MakeInline builds an inline node.

func MakeInlineList

func MakeInlineList(inlines *sx.Pair) *sx.Pair

MakeInlineList builds an inline node from a list of inlines.

func MakeLink(attrs *sx.Pair, ref *sx.Pair, text *sx.Pair) *sx.Pair

MakeLink builds a link node.

func MakeList

func MakeList(sym *sx.Symbol, attrs *sx.Pair, items *sx.Pair) *sx.Pair

MakeList builds a list node.

func MakeLiteral

func MakeLiteral(sym *sx.Symbol, attrs *sx.Pair, text string) *sx.Pair

MakeLiteral builds a inline node with literal text.

func MakeMark

func MakeMark(mark string, slug, fragment string, inlines *sx.Pair) *sx.Pair

MakeMark builds a mark note.

func MakePara

func MakePara(inlines ...*sx.Pair) *sx.Pair

MakePara builds a paragraph node.

func MakeParaList

func MakeParaList(inlines *sx.Pair) *sx.Pair

MakeParaList builds a paragraph node.

func MakeReference

func MakeReference(sym *sx.Symbol, val string) *sx.Pair

MakeReference builds a reference node.

func MakeRegion

func MakeRegion(sym *sx.Symbol, attrs *sx.Pair, blocks *sx.Pair, inlines *sx.Pair) *sx.Pair

MakeRegion builds a region node.

func MakeSoft

func MakeSoft() *sx.Pair

MakeSoft builds a node for a soft line break.

func MakeText

func MakeText(text string) *sx.Pair

MakeText builds a text node.

func MakeThematic

func MakeThematic(attrs *sx.Pair) *sx.Pair

MakeThematic builds a node to implement a thematic break.

func MakeTransclusion

func MakeTransclusion(attrs *sx.Pair, ref *sx.Pair, text *sx.Pair) *sx.Pair

MakeTransclusion builds a transclude node.

func MakeVerbatim

func MakeVerbatim(sym *sx.Symbol, attrs *sx.Pair, content string) *sx.Pair

MakeVerbatim builds a node for verbatim text.

func ScanEntity

func ScanEntity(inp *input.Input) (res string, success bool)

ScanEntity scans either a named or a numbered entity and returns it as a string.

For numbered entities (like { or ģ) html.UnescapeString returns sometimes other values as expected, if the number is not well-formed. This may happen because of some strange HTML parsing rules. But these do not apply to Zettelmarkup. Therefore, I parse the number here in the code.

func Walk

func Walk(v Visitor, node *sx.Pair, alst *sx.Pair) sx.Object

Walk a sx-based AST through a Visitor.

Walk returns an sx.Object (and not a *sx.Pair) because a Visitor may return something completely different to a list. For example, it may return a user-defined object, which consumes an SZ-based syntax tree.

func WalkIt

func WalkIt(v VisitorIt, node *sx.Pair, alst *sx.Pair)

WalkIt walks a sx-based AST with the guidance of a Visitor. It will never modify the AST. Only the Visitor's side effects count. Therefore, there is no need to return something.

func WalkItList

func WalkItList(v VisitorIt, lst *sx.Pair, skip int, alst *sx.Pair)

WalkItList will WalkIt for all elements of the list, after skipping the first elements.

Types

type Attributes

type Attributes map[string]string

Attributes store additional information about some node types.

func GetAttributes

func GetAttributes(seq *sx.Pair) (result Attributes)

GetAttributes traverses a s-expression list and returns an attribute structure.

func (Attributes) Add

func (a Attributes) Add(key, value string) Attributes

Add a value to an attribute key.

func (Attributes) AddClass

func (a Attributes) AddClass(class string) Attributes

AddClass adds a value to the class attribute.

func (Attributes) AsAssoc

func (a Attributes) AsAssoc() *sx.Pair

AsAssoc returns the attributes as an assoc list.

It is partly the reverse operation of GetAttributes: `maps.Equal(GetAttributes(a.AsAssoc()), a)`.

func (Attributes) Clone

func (a Attributes) Clone() Attributes

Clone returns a duplicate of the attribute.

func (Attributes) Get

func (a Attributes) Get(key string) (string, bool)

Get returns the attribute value of the given key and a succes value.

func (Attributes) GetClasses

func (a Attributes) GetClasses() []string

GetClasses returns the class values as a string slice

func (Attributes) Has

func (a Attributes) Has(key, value string) bool

Has the attribute key a value?

func (Attributes) HasClass

func (a Attributes) HasClass(s string) bool

HasClass returns true, if attributes contains the given class.

func (Attributes) HasDefault

func (a Attributes) HasDefault() bool

HasDefault returns true, if the default attribute "-" has been set.

func (Attributes) IsEmpty

func (a Attributes) IsEmpty() bool

IsEmpty returns true if there are no attributes.

func (Attributes) Keys

func (a Attributes) Keys() []string

Keys returns the sorted list of keys.

func (Attributes) Remove

func (a Attributes) Remove(key string) Attributes

Remove the key from the attributes.

func (Attributes) RemoveDefault

func (a Attributes) RemoveDefault() Attributes

RemoveDefault removes the default attribute

func (Attributes) Set

func (a Attributes) Set(key, value string) Attributes

Set changes the attribute that a given key has now a given value.

func (Attributes) Values

func (a Attributes) Values(key string) []string

Values are the space separated values of an attribute.

type Visitor

type Visitor interface {
	// VisitBefore is called before child nodes are traversed. If it returns
	// an object and a true value, the object is used as the result of the
	// (recursive) walking process. If any object and a false value is
	// returned, all child nodes are traversed and after that VisitAfter is
	// called.
	VisitBefore(node *sx.Pair, alst *sx.Pair) (sx.Object, bool)

	// VisitAfter is called, if the corresponding VisitBefore returned any
	// object and a false value, and when all child nodes were traversed.
	// The result of VisitAfter is the result of the walking process.
	VisitAfter(node *sx.Pair, alst *sx.Pair) sx.Object
}

Visitor is walking the SZ-based AST.

First, VisitBefore is called. If it returned a false value, all child nodes are traversed and then VisitAfter is called. If VisitBefore returned a true value, no child nodes will be traversed and VisitAfter will not be called.

type VisitorIt

type VisitorIt interface {
	// VisitItBefore is called before child nodes are traversed. If it returns
	// a true value, the (recursive) walking process ends. If a false value is
	// returned, all child nodes are traversed and after that VisitItAfter is
	// called.
	VisitItBefore(node *sx.Pair, alst *sx.Pair) bool

	// VisitItAfter is called, if the corresponding VisitBefore returned a
	// a false value, and when all child nodes were traversed.
	VisitItAfter(node *sx.Pair, alst *sx.Pair)
}

VisitorIt is for walking the SZ-based AST, but only for side-effects.

VisitItBefore and VisitItAfter have the same semantic as VisitBefore / VisitAfter in the Visitor interface, but no objects are returned.

Source Files

  • attrs.go
  • build.go
  • const.go
  • entity.go
  • walk.go
  • zsx.go

Directories

Path Synopsis
Package input provides an abstraction for data to be read.
Package input provides an abstraction for data to be read.

Jump to

Keyboard shortcuts

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