Skip to content

Conversation

inkstak
Copy link

@inkstak inkstak commented Feb 28, 2023

We use lookbook which relies on htmlbeautifier to output pretty HTML and we have some custom block elements (such as <turbo-frame>) which are not rendered indented.

This PR replace the constants from HtmlBeautifier::HtmlParser by methods which allows to specify additional elements:

HtmlBeautifier::HtmlParser.block_elements << "main"
HtmlBeautifier::HtmlParser.block_elements << "turbo-frame"
HtmlBeautifier::HtmlParser.block_elements << "whatever"

The downside is that mappings is compiled each time HtmlParser is initialized.
If this is an issue, I guess I can add a method to compile and cache the mappings only once.

I've add tests in a second commit but:

  • I'm not sure it's relevant to add tests because it's mostly a refactor which doesn't change current behaviors.
  • It modify the block_elements globally

@threedaymonk
Copy link
Owner

Sorry for neglecting this for so long! I think this is a good feature, but I'm not keen on the class attributes. I think I'd prefer to have these as attributes of the particular instance of HtmlParser.

Perhaps the best implementation would be to expose the list of elements, and let you inject a parser, so that you could then subclass the parser with whatever elements you like. I'll think about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants