ForbesLindesay-Unmaintained / fix-jade

Fix jade by removing reliance on deprecated features
MIT License
16 stars 3 forks source link

Change implicit textOnly fixes to only apply to indented block content #3

Closed stuartpb closed 11 years ago

stuartpb commented 11 years ago

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).

stuartpb commented 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.

ForbesLindesay commented 11 years ago

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.

stuartpb commented 11 years ago

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.

ForbesLindesay commented 11 years ago

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.

stuartpb commented 11 years ago

The $1 backreference syntax was wrong, regex backreferences use backslashes like \1 (I'm not sure why I always think it's $). See 785c092.

ForbesLindesay commented 11 years ago

My fix isn't working, turns out it's pretty complicated :p

ForbesLindesay commented 11 years ago

There were a few little bugs but it was pretty easy to fix. Thanks for sorting this :smile: