1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-10-31 04:06:16 +00:00
mycorrhiza/markup/parser.go
2021-01-01 09:07:56 +05:00

27 lines
593 B
Go

package markup
const maxRecursionLevel = 3
func Parse(ast []Line, from, to int, recursionLevel int) (html string) {
if recursionLevel > maxRecursionLevel {
return "Transclusion depth limit"
}
for _, line := range ast {
if line.id >= from && (line.id <= to || to == 0) || line.id == -1 {
switch v := line.contents.(type) {
case Transclusion:
html += Transclude(v, recursionLevel)
case Img:
html += v.ToHtml()
case Table:
html += v.asHtml()
case string:
html += v
default:
html += "<b class='error'>Unknown element.</b>"
}
}
}
return html
}