Wiki List Support
This commit is contained in:
@@ -185,6 +185,8 @@ func (ctx *wikiContext) applyWikiTemplateFilter(value any, filter string, state
|
||||
return text, nil
|
||||
case "join":
|
||||
return joinWikiTemplateValue(value, firstArg(args)), nil
|
||||
case "list":
|
||||
return wikiTemplateHTML(renderWikiTemplateList(value, firstArg(args))), nil
|
||||
case "ordinal":
|
||||
return ordinalWikiTableValue(numericWikiTableValue(value)), nil
|
||||
case "default":
|
||||
@@ -361,6 +363,50 @@ func joinWikiTemplateValue(value any, sep string) string {
|
||||
}
|
||||
}
|
||||
|
||||
func renderWikiTemplateList(value any, class string) string {
|
||||
items := wikiTemplateListItems(value)
|
||||
if len(items) == 0 {
|
||||
return ""
|
||||
}
|
||||
var out strings.Builder
|
||||
out.WriteString("<ul")
|
||||
out.WriteString(attrClass(class))
|
||||
out.WriteString(">")
|
||||
for _, item := range items {
|
||||
out.WriteString("<li>")
|
||||
out.WriteString(renderWikiLinks(item))
|
||||
out.WriteString("</li>")
|
||||
}
|
||||
out.WriteString("</ul>")
|
||||
return out.String()
|
||||
}
|
||||
|
||||
func wikiTemplateListItems(value any) []string {
|
||||
switch typed := value.(type) {
|
||||
case []string:
|
||||
out := make([]string, 0, len(typed))
|
||||
for _, item := range typed {
|
||||
if text := strings.TrimSpace(item); text != "" {
|
||||
out = append(out, text)
|
||||
}
|
||||
}
|
||||
return out
|
||||
case []any:
|
||||
out := make([]string, 0, len(typed))
|
||||
for _, item := range typed {
|
||||
if text := strings.TrimSpace(stringifyWikiTemplatePlain(item)); text != "" {
|
||||
out = append(out, text)
|
||||
}
|
||||
}
|
||||
return out
|
||||
default:
|
||||
if text := strings.TrimSpace(stringifyWikiTemplatePlain(value)); text != "" {
|
||||
return []string{text}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (ctx *wikiContext) renderTemplateReference(value any, dataset string) string {
|
||||
return ctx.renderReference(value, ctx.wikiIDMapForDataset(dataset), ctx.wikiNameResolverForDataset(dataset))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user