htmlbeautifier icon indicating copy to clipboard operation
htmlbeautifier copied to clipboard

WIP: Fix handling of right angle bracket (`>`) in attributes

Open andyw8 opened this issue 1 year ago • 3 comments

This is the fix suggested by @jon-sully in https://github.com/threedaymonk/htmlbeautifier/issues/78#issuecomment-2369219951

It may need further work and verification, so I'm only opening it as a draft for now to allow for discussion.

Also, it breaks one of the current tests: HtmlBeautifier indents general self-closing tags

andyw8 avatar Oct 14 '24 17:10 andyw8

i couldnt really come up with a more clever regex but testing in regex101 the following still matched,

%r{ (?:<%.*?%>|(?:[^"]*?->[^"]*?)|[^>])* }mx

its a bit dumber but just allows > within quotes

Hmm actually it lead me to adjust it once more to the following

%r{ (?:[^"]?[-%]>[^"]?|[^>])* }mx

moved the erb tag or - check together [-%]

im not sure if this is correct but, ill fork sometime next week and see for myself

phyzical avatar Nov 01 '24 08:11 phyzical

So i gave it a try, neither of my queries were perfect %r{ (?:[^"]?[-%]>[^"]?|[^>])* }mx is close.. but it breaks it "stays indented within <details> with Boolean attribute handled by ERB" do

@andyw8 i did notice if your revert image all tests will pass, was this change intentional?

phyzical avatar Nov 07 '24 05:11 phyzical

It was copied from https://github.com/threedaymonk/htmlbeautifier/issues/78#issuecomment-2369219951 but I haven't yet looked into it.

andyw8 avatar Nov 07 '24 23:11 andyw8