
protocol OrderedKeyBlockProcessor: BlockLineProcessor {

    associatedtype Key: Hashable, RawRepresentable where Key.RawValue == String

    func process(_ arguments: [(key: Key, value: String)], markdown: Substring) -> String
}

extension OrderedKeyBlockProcessor {

    func process(_ lines: [String], markdown: Substring) -> String {
        let result: [(key: Key, value: String)] = lines.compactMap { line in
            guard line.trimmed != "" else {
                return nil
            }
            let (rawKey, rawValue) = line.splitAtFirst(":")
            guard let key = Key(rawValue: rawKey.trimmed) else {
                print("Invalid key \(rawKey)")
                invalid(markdown)
                return nil
            }
            return (key, rawValue.trimmed)
        }
        return process(result, markdown: markdown)
    }
}
