Closed elquimista closed 8 years ago
Yep, this is a known problem of Jade interpolation since it only uses a simple greedy regex and making it non-greedy would break simple variable access more easily (#[a(href=$someVar['someValue'])]
).
I will think about a better way to resolve this.
Is it a native problem of original Jade language interpreter?
Nope, the native implementation can handle both cases just fine.
I'm already working on a solution.
FYI, here's my suggestion
/#(\[(?:[^\[\]]+|(?1))*+\])/
Just use my suggestion for reference. I want to see your solution as well. And pls release the new version covering this issue asap. thanks.
And can you do me a favor? This is not about your talejade repo ;).
Please check https://github.com/clthck/cakephp-jade-tmbundle/blob/master/Syntaxes/Jade.tmLanguage
I tried to customize Jade sublime text syntax so that it displays php syntax instead of javascript (e.g. = $this->variable
), but it doesn't work well.
Honestly, I've never taken a look at Sublime text syntax highlighting definition, but I'll look if I can find the problem.
What exactly is the problem?
p= strtolower($s)
In the above code, strtolower($s)
should be highlighted as PHP language, but currently I think it's considered plain text.
Btw, what do you think of my regex suggestion?
Your regex suggestion would fix this problem indeed.
It would make something like
p Some string #[a(href=$params['url']) #[i.fa.fa-fw.fa-person] My #{$lang['link']}, welcome #{$user->{$nameProperty}}]
impossible, though.
That's why I took a different approach which doesn't use a single reg-ex (I could put that into the lexer but it would be a mess to lex and interpolation works inside text- and attribute values only)
https://github.com/Talesoft/tale-jade/blob/dev-interpolation-fix/Compiler.php#L664
I now simply count brackets.
This will allow probably any kind of syntax you might need inside interpolation, once and for all.
Your case is nested interpolation. I think using nested interpolation is not good for the sake of code legibility and it's also rarely used. I'd rather use line break and multiple lines in that case.
I guess nested interpolation might make sense for stuff like
article
p.
Some random article content #[a #{$lang['more']}] #[a #{$lang['comments']} (#{$commentCount})]
and also stuff like
article
p.
Some wiki article #[a Some external ref #[i.fa.fa-whatever]]
In any case, bracket counting fixes both cases, I've written the tests already, the fix will be online soon :)
New release is out (1.3.7), can you update and test it?
Great :+1: Works perfect !! Thank you so much for releasing v1.3.7. Btw, what is tale-config used for?
tale-config is just a small configuration utility library that I will use in some further tale-* projects and components. Some of them are already online, just take a look at the Talesoft GitHub page. Every one except for tale-jade and tale-config is really experimental
Here's an example:
This should be interpreted as:
But it's misinterpreted like this:
I confirmed it on talejade sandbox.
I think this is caused by wrong lookup of matching brackets during interpolation processing.