31 lines
940 B
Swift
31 lines
940 B
Swift
|
|
struct LabelsCommandProcessor: CommandProcessor {
|
|
|
|
let commandType: ShorthandMarkdownKey = .labels
|
|
|
|
let content: Content
|
|
|
|
let results: PageGenerationResults
|
|
|
|
init(content: Content, results: PageGenerationResults) {
|
|
self.content = content
|
|
self.results = results
|
|
}
|
|
|
|
func process(_ arguments: [String], markdown: Substring) -> String {
|
|
let labels: [ContentLabel] = arguments.compactMap { arg in
|
|
let parts = arg.components(separatedBy: "=")
|
|
guard parts.count == 2 else {
|
|
results.invalid(command: .labels, markdown)
|
|
return nil
|
|
}
|
|
guard let icon = PageIcon(rawValue: parts[0].trimmed) else {
|
|
results.invalid(command: .labels, markdown)
|
|
return nil
|
|
}
|
|
return .init(icon: icon, value: parts[1])
|
|
}
|
|
return ContentLabels(labels: labels).content
|
|
}
|
|
}
|