mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2024-12-14 14:20:25 +00:00
32 lines
615 B
Go
32 lines
615 B
Go
|
package gemtext
|
||
|
|
||
|
import ()
|
||
|
|
||
|
const maxRecursionLevel = 3
|
||
|
|
||
|
type GemParserState struct {
|
||
|
recursionLevel int
|
||
|
}
|
||
|
|
||
|
func Parse(ast []Line, from, to int, state GemParserState) (html string) {
|
||
|
if state.recursionLevel > maxRecursionLevel {
|
||
|
return "Transclusion depth limit"
|
||
|
}
|
||
|
for _, line := range ast {
|
||
|
if line.id >= from && (line.id <= to || to == 0) {
|
||
|
switch v := line.contents.(type) {
|
||
|
case Transclusion:
|
||
|
html += Transclude(v, state)
|
||
|
case string:
|
||
|
html += v
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return html
|
||
|
}
|
||
|
|
||
|
func ToHtml(name, text string) string {
|
||
|
state := GemParserState{}
|
||
|
return Parse(lex(name, text), 0, 0, state)
|
||
|
}
|