Add labels block

This commit is contained in:
Christoph Hagen
2025-01-06 17:40:35 +01:00
parent cc19ff4a6f
commit 8e19adda70
5 changed files with 40 additions and 3 deletions

View File

@ -0,0 +1,31 @@
struct LabelsBlock: OrderedKeyBlockProcessor {
typealias Key = PageIcon
static let blockId: ContentBlock = .labels
let content: Content
let results: PageGenerationResults
let language: ContentLanguage
init(content: Content, results: PageGenerationResults, language: ContentLanguage) {
self.content = content
self.results = results
self.language = language
}
func process(_ arguments: [(key: PageIcon, value: String)], markdown: Substring) -> String {
let labels: [ContentLabel] = arguments.compactMap { (icon, value) in
guard value != "" else {
invalid(markdown)
return nil
}
results.require(icon: icon)
return .init(icon: icon, value: value)
}
return ContentLabels(labels: labels).content
}
}