2020-10-30 13:25:48 +00:00
|
|
|
package markup
|
2020-08-05 15:08:59 +00:00
|
|
|
|
|
|
|
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 {
|
2020-08-05 15:08:59 +00:00
|
|
|
return "Transclusion depth limit"
|
|
|
|
}
|
|
|
|
for _, line := range ast {
|
2020-11-03 12:27:26 +00:00
|
|
|
if line.id >= from && (line.id <= to || to == 0) || line.id == -1 {
|
2020-08-05 15:08:59 +00:00
|
|
|
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()
|
2020-08-05 15:08:59 +00:00
|
|
|
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>"
|
2020-08-05 15:08:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return html
|
|
|
|
}
|