Closed stuartpb closed 11 years ago
This regex comes sort of close to separating out inline content from attributes:
src = src.replace(/^([ \t]*)(style|script)((?:#\S*|\.\S*|\(.*\))*)(.*)(\n\1[ \t]+)/gm, dotImplicitTextOnlyBlock)
Really, though, this much cleverness to try to emulate proper parsing using regexes is a fool's errand: for this level of detail, it'd be more prudent to just parse the Jade script with the actual Jade parser, and then just rewrite it (re-output the input) with the appropriate changes.
In addition to my inline comment. What we need to check is actually just that the next line is indented more than the current line, that should be the only addition.
The replacement already only applies to blocks with a more indented line after: that's what /^([ \t]*)(style|script)(\S*)(\s*\n\1[ \t]+)/gm
is supposed to do.
Oh, crazy $1 back references, my regex knowledge is limited. I'm working on a fix that I think should work. Just testing it now.
The $1
backreference syntax was wrong, regex backreferences use backslashes like \1
(I'm not sure why I always think it's $). See 785c092.
My fix isn't working, turns out it's pretty complicated :p
There were a few little bugs but it was pretty easy to fix. Thanks for sorting this :smile:
Fix for some of the spurious fixes mentioned in visionmedia/jade#1036
I removed the initial test that ran before the replace operation, not sure if that did anything.
This is untested and I'm not positive it works (I'm a little fuzzy on how ^ and newlines interact in multiline mode, if regexes can still span multiple lines).