Documentation
¶
Overview ¶
Package zsx contains zettel data handling as sx expressions.
Index ¶
- Constants
- Variables
- func GetBLOB(node *sx.Pair) (*sx.Pair, string, []byte, *sx.Pair)
- func GetBLOBuncode(node *sx.Pair) (*sx.Pair, string, string, *sx.Pair)
- func GetBlock(node *sx.Pair) *sx.Pair
- func GetCell(node *sx.Pair) (*sx.Pair, *sx.Pair)
- func GetCite(node *sx.Pair) (*sx.Pair, string, *sx.Pair)
- func GetDescription(node *sx.Pair) (*sx.Pair, *sx.Pair)
- func GetEmbed(node *sx.Pair) (*sx.Pair, *sx.Pair, string, *sx.Pair)
- func GetEmbedBLOB(node *sx.Pair) (*sx.Pair, string, []byte, *sx.Pair)
- func GetEmbedBLOBuncode(node *sx.Pair) (*sx.Pair, string, string, *sx.Pair)
- func GetEndnote(node *sx.Pair) (*sx.Pair, *sx.Pair)
- func GetFormat(node *sx.Pair) (*sx.Symbol, *sx.Pair, *sx.Pair)
- func GetHeading(node *sx.Pair) (int, *sx.Pair, *sx.Pair, string, string)
- func GetInline(node *sx.Pair) *sx.Pair
- func GetLink(node *sx.Pair) (*sx.Pair, *sx.Pair, *sx.Pair)
- func GetList(node *sx.Pair) (*sx.Symbol, *sx.Pair, *sx.Pair)
- func GetLiteral(node *sx.Pair) (*sx.Symbol, *sx.Pair, string)
- func GetMark(node *sx.Pair) (string, string, string, *sx.Pair)
- func GetPara(node *sx.Pair) *sx.Pair
- func GetReference(ref *sx.Pair) (*sx.Symbol, string)
- func GetRegion(node *sx.Pair) (*sx.Symbol, *sx.Pair, *sx.Pair, *sx.Pair)
- func GetTable(node *sx.Pair) (*sx.Pair, *sx.Pair, *sx.Pair)
- func GetText(node *sx.Pair) string
- func GetThematic(node *sx.Pair) *sx.Pair
- func GetTransclusion(node *sx.Pair) (*sx.Pair, *sx.Pair, *sx.Pair)
- func GetVerbatim(node *sx.Pair) (*sx.Symbol, *sx.Pair, string)
- func GetWalkList(alst *sx.Pair) *sx.Pair
- func GetWalkPos(alst *sx.Pair) int
- func GoValue(obj sx.Object) string
- func MakeBLOB(attrs *sx.Pair, syntax string, data []byte, description *sx.Pair) *sx.Pair
- func MakeBLOBuncode(attrs *sx.Pair, syntax string, data string, description *sx.Pair) *sx.Pair
- func MakeBlock(blocks ...*sx.Pair) *sx.Pair
- func MakeBlockList(blocks *sx.Pair) *sx.Pair
- func MakeCell(attrs *sx.Pair, inlines *sx.Pair) *sx.Pair
- func MakeCite(attrs *sx.Pair, text string, inlines *sx.Pair) *sx.Pair
- func MakeEmbed(attrs *sx.Pair, ref sx.Object, syntax string, text *sx.Pair) *sx.Pair
- func MakeEmbedBLOB(attrs *sx.Pair, syntax string, data []byte, inlines *sx.Pair) *sx.Pair
- func MakeEmbedBLOBuncode(attrs *sx.Pair, syntax string, data string, inlines *sx.Pair) *sx.Pair
- func MakeEndnote(attrs, inlines *sx.Pair) *sx.Pair
- func MakeFormat(sym *sx.Symbol, attrs, inlines *sx.Pair) *sx.Pair
- func MakeHard() *sx.Pair
- func MakeHeading(level int, attrs, text *sx.Pair, slug, fragment string) *sx.Pair
- func MakeInline(inlines ...*sx.Pair) *sx.Pair
- func MakeInlineList(inlines *sx.Pair) *sx.Pair
- func MakeLink(attrs *sx.Pair, ref *sx.Pair, text *sx.Pair) *sx.Pair
- func MakeList(sym *sx.Symbol, attrs *sx.Pair, items *sx.Pair) *sx.Pair
- func MakeLiteral(sym *sx.Symbol, attrs *sx.Pair, text string) *sx.Pair
- func MakeMark(mark string, slug, fragment string, inlines *sx.Pair) *sx.Pair
- func MakePara(inlines ...*sx.Pair) *sx.Pair
- func MakeParaList(inlines *sx.Pair) *sx.Pair
- func MakeReference(sym *sx.Symbol, val string) *sx.Pair
- func MakeRegion(sym *sx.Symbol, attrs *sx.Pair, blocks *sx.Pair, inlines *sx.Pair) *sx.Pair
- func MakeSoft() *sx.Pair
- func MakeText(text string) *sx.Pair
- func MakeThematic(attrs *sx.Pair) *sx.Pair
- func MakeTransclusion(attrs *sx.Pair, ref *sx.Pair, text *sx.Pair) *sx.Pair
- func MakeVerbatim(sym *sx.Symbol, attrs *sx.Pair, content string) *sx.Pair
- func ScanEntity(inp *input.Input) (res string, success bool)
- func Walk(v Visitor, node *sx.Pair, alst *sx.Pair) sx.Object
- func WalkIt(v VisitorIt, node *sx.Pair, alst *sx.Pair)
- func WalkItList(v VisitorIt, lst *sx.Pair, skip int, alst *sx.Pair)
- type Attributes
- func (a Attributes) Add(key, value string) Attributes
- func (a Attributes) AddClass(class string) Attributes
- func (a Attributes) AsAssoc() *sx.Pair
- func (a Attributes) Clone() Attributes
- func (a Attributes) Get(key string) (string, bool)
- func (a Attributes) GetClasses() []string
- func (a Attributes) Has(key, value string) bool
- func (a Attributes) HasClass(s string) bool
- func (a Attributes) HasDefault() bool
- func (a Attributes) IsEmpty() bool
- func (a Attributes) Keys() []string
- func (a Attributes) Remove(key string) Attributes
- func (a Attributes) RemoveDefault() Attributes
- func (a Attributes) Set(key, value string) Attributes
- func (a Attributes) Values(key string) []string
- type Visitor
- type VisitorIt
Constants ¶
const DefaultAttribute = "-"
DefaultAttribute is the value of the key of the default attribute
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 ¶
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.
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 ¶
GetBLOB returns all elements of a block BLOB node.
func GetBLOBuncode ¶
GetBLOBuncode returns all elements of a block BLOB node and does not decode the BLOB data.
func GetBlock ¶
GetBlock returns all elements of a block node.
func GetCell ¶
GetCell returns all elements of a table cell node.
func GetCite ¶
GetCite returns alle elements of a cite node.
func GetDescription ¶
GetDescription returns the elements of a description list node.
func GetEmbed ¶
GetEmbed returns the elements of an embed node.
func GetEmbedBLOB ¶
GetEmbedBLOB returns all elements of an inline BLOB node.
func GetEmbedBLOBuncode ¶
GetEmbedBLOBuncode returns all elements of an inline BLOB node. It does not decode the content data.
func GetEndnote ¶
GetEndnote returns the elements of an endnote node.
func GetFormat ¶
GetFormat returns the elements of a formatting node.
func GetHeading ¶
GetHeading returns the elements of a heading node.
func GetInline ¶
GetInline returns all elements of an inline node.
func GetLink ¶
GetLink returns the elements of a link node.
func GetList ¶
GetList returns the elements of a list node.
func GetLiteral ¶
GetLiteral returns the elements of a literal node.
func GetMark ¶
GetMark returns the elements of a mark node.
func GetPara ¶
GetPara returns all elements of a paragraph node.
func GetReference ¶
GetReference returns the reference symbol and value.
func GetRegion ¶
GetRegion returns the elements of a region node.
func GetTable ¶
GetTable returns the elements of a table.
func GetThematic ¶
GetThematic returns the elements of a thematic break node.
func GetTransclusion ¶
GetTransclusion returns all elements of a tranclude node.
func GetVerbatim ¶
GetVerbatim returns the elements of a verbatim node.
func GetWalkList ¶
GetWalkList returns the list of the current node and all subsequent nodes.
func GetWalkPos ¶
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 ¶
GoValue returns the string value of the sx.Object suitable for Go processing.
func MakeBLOB ¶
MakeBLOB builds a block BLOB node.
func MakeBLOBuncode ¶
MakeBLOBuncode builds a block BLOB node, but assumes already encoded data.
func MakeBlockList ¶
MakeBlockList builds a block node from a list of blocks.
func MakeCell ¶
MakeCell builds a table cell node.
func MakeCite ¶
MakeCite builds a node that specifies a citation.
func MakeEmbed ¶
MakeEmbed builds a embed node.
func MakeEmbedBLOB ¶
MakeEmbedBLOB builds an embedded inline BLOB node.
func MakeEmbedBLOBuncode ¶
MakeEmbedBLOBuncode builds an embedded inline BLOB node, and does not encode binary content data.
func MakeEndnote ¶
MakeEndnote builds an endnote node.
func MakeFormat ¶
MakeFormat builds an inline formatting node.
func MakeHeading ¶
MakeHeading builds a heading node.
func MakeInlineList ¶
MakeInlineList builds an inline node from a list of inlines.
func MakeLink ¶
MakeLink builds a link node.
func MakeList ¶
MakeList builds a list node.
func MakeLiteral ¶
MakeLiteral builds a inline node with literal text.
func MakeMark ¶
MakeMark builds a mark note.
func MakeParaList ¶
MakeParaList builds a paragraph node.
func MakeReference ¶
MakeReference builds a reference node.
func MakeRegion ¶
MakeRegion builds a region node.
func MakeThematic ¶
MakeThematic builds a node to implement a thematic break.
func MakeTransclusion ¶
MakeTransclusion builds a transclude node.
func MakeVerbatim ¶
MakeVerbatim builds a node for verbatim text.
func ScanEntity ¶
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 ¶
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 ¶
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.
Types ¶
type Attributes ¶
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) 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