Closed Hocdoc closed 4 years ago
I think this would be useful for this project, but how would be it be useful for hast-util-to-html
?
Use Cases:
hast-util-to-html
to silently ignore all unknown nodes instead of throwing an error. (We store meta-nodes in the Remark-AST, which get converted into HAST, then we transform the HAST depending on these meta-nodes, and then we print HTML ignoring the unknown meta-nodes).But I see your point, we could also just remove all non-HAST-nodes before running hast-util-to-html
.
I will write a PR for mdast-util-to-hast
next monday.
I get the metadata in mdast indeed, but I don’t really see what kind of metadata is still useful in a hast AST (or: maybe useful at first, but then you’d transform them away to make valid hast from your custom hast).
An idea that may be of interest: you could use hast to represent HTML custom elements (<mycompany-icon>
) too, which are have more meaning to you?
You can also add metadata to nodes at the node.data
object.
Custom log messages for unknown nodes
I’d suggest using vfile.messages
for that, if possible?
Appreciate the PR, thanks!
Closed by GH-37.
For our project it would be really useful to define a custom handler for unknown nodes.
We mix many custom nodes with remark nodes. We need our custom nodes unchanged in the HAST tree after we run
mdast-util-to-hast
. Writing a custom handler for every custom type wouldn't work for our use case.At the moment all unknown nodes get converted to text or a div (as defined in one.js ).
I wish to add to a new property like
options.unknownHandler = (h, node, parent): Node
(or as alternative a special handler "unknown" in the existingoptions.handlers
object).A handler for unknown nodes would be also useful in the
hast-util-to-html
project. There all unknown nodes result in anError
.It could be also used f.ex. to show wrong node types in the HTML output.
If I can convince you about this feature, I can write PRs for
mdast-util-to-hast
andhast-util-to-html
to support a custom unknown-node-handler.