How to configure void and open-close node configuration
wooorm opened this issue · 3 comments
I was just working on hast-include (similar to posthtml-include), to show the difference between PostHTML and hast, and ran into the problem of configuring void nodes (used to control whether or not an ending tag is expected) and open-close nodes (used to determine which opening tags implicitly imply the closing of other elements).
Now, plug-ins might want to configure these mappings, e.g., the include plug-in defines a custom include element which is a void element. It should be parsed and compiled (and maybe treated by other plug-ins?) as void.
To ensure this, I propose exposing the void and open-close dictionaries on either file or processor.
E.g., file.namespace('hast').void or processor.void.
The disadvantage of this is that, when patching file, users have to keep track of that (e.g., when running parse, run, and compile with different parsers). The disadvantage of patching processor is that currently, Parser and Compiler have no access to it (but that’s fixable of course)!
I would say that file is an obscure place for this, and parser/stringifier configuration should got to Parser or Stringifier (or processor)?
I doubt that having multiple sources of such configuration is a good idea (what happens if they conflict? what should plugins do — add configuration to both or pick one? which one?). file.namespace('hast').void would probably represent “file-wise” configuration and take precedence over processor.void, but I think file has nothing to do with parsing or stringifying at all, unless I'm missing something.
processor it is; I think I’ll add support for a data dictionary on it, similar to VFile’s and Unist nodes!