emmet-mode icon indicating copy to clipboard operation
emmet-mode copied to clipboard

How do you escape special characters? Pipe operator, curly braces, etc

Open mhavard999 opened this issue 9 years ago • 13 comments

If I want

<p> | </p>

(where | is the literal pipe operator, not the cursor position)

I cannot use p{|} because the pipe operator is part of emmet's syntax. Is there currently a way to escape special characters? I also cannot get <p>{</p>. Asterisk and square brackets seem fine.

mhavard999 avatar Apr 01 '15 14:04 mhavard999

p{{} actually works on my system, but p{}}| fails with an unbalanced parens error, so still a problem.

| is the char used for filters - it definitely makes things fail if present in brackets. I think it might be difficult to support it, but we 100% should.

I think any characters except | and } should work. | definitely SHOULD work, and ideally we should have an escape mechanism for }.

Thanks for bringing this to our attention!

pobocks avatar Apr 01 '15 19:04 pobocks

No problem. This is an awesome mode. And it looks like the opening curly bracket works fine for me too. I must have tried only the closing one and assumed it wouldn't work for the opening bracket.

mhavard999 avatar Apr 01 '15 19:04 mhavard999

I'm gonna take a stab at this on the train tomorrow. It may take a bit - the parsing for that stuff is regex based, and emacs doesn't support lookbehind (or even lookahead).

On Wed, Apr 1, 2015 at 3:46 PM, mhavard999 [email protected] wrote:

No problem. This is an awesome mode. And it looks like the opening curly bracket works fine for me too. I must have tried only the closing one and assumed it wouldn't work for the opening bracket.

— Reply to this email directly or view it on GitHub https://github.com/smihica/emmet-mode/issues/61#issuecomment-88609145.

pobocks avatar Apr 02 '15 04:04 pobocks

I think I have a fix for brackets - the regex has gotten orders of magnitude slower, but it's on-demand by user so it doesn't matter. It's breaking the climb-up and sibling contructions right now, but I think the basic premise is sound, and I'm going to try and have a working version by today or tomorrow.

Pipe is going to be substantially harder and messier, I fear.

pobocks avatar Apr 02 '15 13:04 pobocks

A related issue - if your template engine uses curly braces, you may want to do something like this: (Using the syntax of the web framework Pyramid's template engine)

script[type=text/javascript src=${request.static_url('static/main.js')}]

Which expands to:

<script type="text/javascript" src="$"></script>

where the {request.static_url('static/main.js')} part is missing.

This is a pretty significant bug since it's pretty common to use rendered template values as attributes of html elements, and a lot of template engines use curly braces (Jinja, Django, Buncha JS engines, etc). Another use case off the top of my head is generating csrf tokens:

input[type=hidden value=${generate_csrf_token()}]
<input type="hidden" value="$" /> <!-- :( -->

Also, if you replace the braces in these examples with pipe, it just fails to render at all. I think some ruby-related template engines may use the pipe operator.

Sorry to pile it on :)

mhavard999 avatar Apr 03 '15 18:04 mhavard999

No need to apologize - I'm super-glad you've caught this stuff!

I think this may need more serious re-working of the parser - no matter how much better I make the regular expressions, I don't think all cases will be handled gracefully by regex.

On Fri, Apr 3, 2015 at 2:02 PM, mhavard999 [email protected] wrote:

A related issue - if your template engine uses curly braces, you may want to do something like this:

script[type=text/javascript src=${request.static_url('static/main.js')}]

Which expands to:

where the {request.static_url('static/main.js')} part is missing.

This is a pretty significant bug since it's pretty common to use rendered template values as attributes of html elements, and a lot of template engines use curly braces. Another use case off the top of my head is generating csrf tokens:

input[type=hidden value=${generate_csrf_token()}]

Also, if you replace the braces in these examples with pipe, it just fails to render at all. I think some ruby-related template engines may use the pipe operator.

Sorry to pile it on :)

— Reply to this email directly or view it on GitHub https://github.com/smihica/emmet-mode/issues/61#issuecomment-89377114.

pobocks avatar Apr 03 '15 18:04 pobocks

That's fixed half of the problem. I'm going to merge this in now, since the bracket part seems like a real blocker for you (and other people using, say, Django's built-in templates).

pobocks avatar Apr 10 '15 15:04 pobocks

Nice! But now I don't get the preview before I optionally decide to expand.

mhavard999 avatar Apr 10 '15 15:04 mhavard999

Hmmm... This shouldn't affect that - are you updating from a version before the default got changed to "don't expand"?

On Fri, Apr 10, 2015 at 11:43 AM, mhavard999 [email protected] wrote:

Nice! But now I don't get the preview before I optionally decide to expand.

— Reply to this email directly or view it on GitHub https://github.com/smihica/emmet-mode/issues/61#issuecomment-91597178.

pobocks avatar Apr 10 '15 16:04 pobocks

When I first installed (just a couple weeks ago), I used the package manager, but I removed the directory the package manager created for emmet and cloned master from here to get the new changes. Escaping the close brace works, but the preview does not.

mhavard999 avatar Apr 10 '15 16:04 mhavard999

Hmmm... Try doing:

C-u C-j

And tell me if the preview triggers.

On Fri, Apr 10, 2015 at 12:13 PM, mhavard999 [email protected] wrote:

When I first installed (just a couple weeks ago), I used the package manager, but I removed the directory the package manager created for emmet and cloned master from here. Escaping the close brace works, but the preview does not.

— Reply to this email directly or view it on GitHub https://github.com/smihica/emmet-mode/issues/61#issuecomment-91604934.

pobocks avatar Apr 10 '15 17:04 pobocks

It does

mhavard999 avatar Apr 10 '15 18:04 mhavard999

There's a variable that controls whether or not the preview activates by default - it's called emmet-preview-default - I suspect you don't have it set, or have it set to nil.

On Fri, Apr 10, 2015 at 2:17 PM, mhavard999 [email protected] wrote:

It does

— Reply to this email directly or view it on GitHub https://github.com/smihica/emmet-mode/issues/61#issuecomment-91642572.

pobocks avatar Apr 10 '15 19:04 pobocks