Monday, June 3, 2013

Re: How to fix <h1> id strings?

On Monday, June 3, 2013 11:07:48 PM UTC+2, stevelitt wrote:
> This is actually two different problems:
>
>
>
> 1) Spaces can't appear in an id string
>
> 2) <h?> text isn't guaranteed unique


1) You are absolutely right, whitespaces are not allowed in id and name tokens.
2) Text node doesn't have to be unique, id token does. For example,

<h1 id="heading-1">Heading</h1>
<h1 id="heading-2">Heading</h1>

is fine, while

<h1 id="heading">First heading</h1>
<h1 id="heading">Second heading</h1>

is not.

And finally... let's take a look at the snippet in question:

snippet h1
<h1 id="${1:heading}">${2:$1}</h1>

You type h1<TAB> and you'll get <h1 id="heading">heading</h1>. Cursor at the first tabstop and id value is highlighted and ready to be replaced. Now you type a new value (it should not, actually must not, contain spaces; but no one is forcing you to type spaces here), this value is also used as a placeholder for next and final tabstop. You hit <TAB>, cursor moves to the second tabstop (element's text node), text is again highlighted and ready to be replaced. You type a new heading.

Personally, I see no value in using the first variable as a placeholder for the second (for header tags anyway). I much more prefer the way it's done in this snippet file (it also has a final tabstop outside the closing tag):

https://gist.github.com/smt/1112952

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: