1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-16 06:50:26 +00:00
mycorrhiza/markup/parser.go

27 lines
593 B
Go
Raw Normal View History

2020-10-30 13:25:48 +00:00
package markup
const maxRecursionLevel = 3
2020-12-17 12:59:59 +00:00
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:
2020-12-17 12:59:59 +00:00
html += Transclude(v, recursionLevel)
2020-11-03 15:41:50 +00:00
case Img:
html += v.ToHtml()
2021-01-01 04:07:56 +00:00
case Table:
html += v.asHtml()
case string:
html += v
2020-11-26 18:41:26 +00:00
default:
2020-12-17 12:59:59 +00:00
html += "<b class='error'>Unknown element.</b>"
}
}
}
return html
}