mycorrhiza/markup/mycomarkup.go
2020-12-15 23:59:36 +05:00

105 lines
1.6 KiB
Go

// This is not done yet
package markup
import (
"html"
"strings"
)
// A Mycomarkup-formatted document
type MycoDoc struct {
// data
hyphaName string
contents string
}
// Constructor
func Doc(hyphaName, contents string) *MycoDoc {
return &MycoDoc{
hyphaName: hyphaName,
contents: contents,
}
}
// AsHtml returns an html representation of the document
func (md *MycoDoc) AsHTML() string {
return ""
}
// OpenGraphHTML returns an html representation of og: meta tags.
func (md *MycoDoc) OpenGraphHTML() string {
return ""
}
/* The rest of this file is currently unused. TODO: use it I guess */
type BlockType int
const (
BlockH1 = iota
BlockH2
BlockH3
BlockH4
BlockH5
BlockH6
BlockRocket
BlockPre
BlockQuote
BlockPara
)
type CrawlWhere int
const (
inSomewhere = iota
inPre
inEnd
)
func crawl(name, content string) []string {
stateStack := []CrawlWhere{inSomewhere}
startsWith := func(token string) bool {
return strings.HasPrefix(content, token)
}
pop := func() {
stateStack = stateStack[:len(stateStack)-1]
}
push := func(s CrawlWhere) {
stateStack = append(stateStack, s)
}
readln := func(c string) (string, string) {
parts := strings.SplitN(c, "\n", 1)
return parts[0], parts[1]
}
preAcc := ""
line := ""
for {
switch stateStack[0] {
case inSomewhere:
switch {
case startsWith("```"):
push(inPre)
_, content = readln(content)
default:
}
case inPre:
switch {
case startsWith("```"):
pop()
_, content = readln(content)
default:
line, content = readln(content)
preAcc += html.EscapeString(line)
}
}
}
return []string{}
}