Hi, I am trying to replicate Github's alert banners:
The parser would need to decide at the block-quote level, whether the first Text child is some pre-defined string. If so, the parser would then need to remove the first child and assign an enum category to the alert banner.
Ideally I would create a MarkupRewriter and return a new type in
func visitBlockQuote(_ blockQuote: BlockQuote)
But I dont see any way to extend the existing markup types. I could implement a struct AlertBlock: BlockMarkup but the protocol requires a MarkupVisitor which cannot be a subclass protocol.
My only workaround is to introduce a complicated state-machine into my HTML formatter to ignore the first Text child element, if a parent blockquote is alert banner style.
(side question:
this does not work. Is the MarkupWalker not allowed to change text?
var alertTag = blockQuote.child(at: 0)?.child(at: 0) as? Text
alertTag?.string = ""
)
Hi, I am trying to replicate Github's alert banners:
Note
like this
The parser would need to decide at the block-quote level, whether the first
Textchild is some pre-defined string. If so, the parser would then need to remove the first child and assign an enum category to the alert banner.Ideally I would create a
MarkupRewriterand return a new type inBut I dont see any way to extend the existing markup types. I could implement a
struct AlertBlock: BlockMarkupbut the protocol requires aMarkupVisitorwhich cannot be a subclass protocol.My only workaround is to introduce a complicated state-machine into my HTML formatter to ignore the first
Textchild element, if a parent blockquote is alert banner style.(side question:
this does not work. Is the
MarkupWalkernot allowed to change text?)