Documentation ¶
Overview ¶
Package brashtag provides parser for parsing files written in brashtag notation.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bag ¶
type Bag struct {
// contains filtered or unexported fields
}
Bag has a tag and children.
type Node ¶
func Parse ¶
Parse parses the text and returns its brashtag tree.
Example ¶
package main import ( "fmt" "strings" ) func main() { text := strings.Join([]string{ "#div{", " #b{A very short story}", " #p{Lorem and impsum met for a coffee.}", " ` print 'Hello' `", "}", }, "\n") tree, _ := Parse(text) fmt.Println(toHTML(tree)) // Input: /* #div{ #b{A very short story} #p{Lorem and impsum met for a coffee.} ` print 'Hello' ` } */ } func toHTML(r Node) string { s := "" switch x := r.(type) { case Blob: return x.Text() case Code: return fmt.Sprintf("<code>%s</code>", x.Text()) case Bag: s := "" for _, kid := range x.Kids() { s += toHTML(kid) } if x.Tag() != "" { return fmt.Sprintf("<%s>%s</%s>", x.Tag(), s, x.Tag()) } return s } return s }
Output: <div> <b>A very short story</b> <p>Lorem and impsum met for a coffee.</p> <code> print 'Hello' </code> </div>
Click to show internal directories.
Click to hide internal directories.