Conversation
| -- > | Just NodeRawBlock{} <- getNodeType node = True | ||
| -- > | otherwise = False | ||
| -- > in Nodes . filter (not . isRawHTML) . unNodes | ||
| newtype Nodes a = Nodes { unNodes :: [Node a] } |
There was a problem hiding this comment.
These types have an annoying type parameter because in order to implement fromNodes :: Nodes -> a, you would need to tell the compiler that a can render any NodeTypes that might be in the Nodes. But since NodeType is extensible, it might be possible Nodes to parse some new FancyNode and Html () not know how to render it (for example).
A clearer type would be to say
data Nodes nodeTypes = ...where nodeTypes is a type-level set of node types that are represented in a Nodes value, and fromNodes could have a constraint that says "a can render every one of these node types". But this isn't very feasible right now.
The current implementation effectively bundles the Dict for IsBlock (Html ()) (Html ()) when parsing SomeNodeType, so each Node carries around how to "finish" rendering
|
I did a similar thing here and released it as a small adjunct library on Hackage. I functorized the sum types representing inlines and blocks and then used |
Adds a new completely optional (not even exported in
import Commonmark) code path for people who want to inspect or transform the markdown content before rendering asHtml (). Not sure if it's worth merging, but it was at least an interesting exercise. I'm putting up this PR mostly for demonstration purposesTested in GHCi: