Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

id & class shortcuts expect exact order #83

Open
rachel-carvalho opened this Issue Oct 4, 2011 · 4 comments

Comments

Projects
None yet
4 participants
Contributor

rachel-carvalho commented Oct 4, 2011

If I use

div '#id.class', ''

it renders as expected:

<div id="id" class="class"></div>

but if I switch class and id (which is the case when using htmlkup converter)

div '.class#id', ''

it's interpreted as one big id

<div id="classid"></div>

An additional case that might prove illuminating:

div ".foo#bar.baz"

Yields

<div id="foobar" class="baz"/>

The code uses "." as a split, so #id.class becomes "#id" "class", and then things with "#" in them become ids

I bet '.class.#id' would work as expected

kgrz commented Oct 29, 2012

--Edited--
@treeform I guess not. Yes. @treeform is right. The relevant code is here: https://github.com/mauricemach/coffeekup/blob/master/src/coffeekup.coffee#L128

Once the string is split with ., the list is traversed and every instance of # is removed. There is one logic as to why the author wanted to split against . and not # -- the tags may have multiple classes but only one id (proper markup, anyway).

kgrz commented Oct 29, 2012

One alternative would be to have another split, this time on # if it is present in the string:

for i in str.split '.'
  if '#' in i
    [klass, id] = i.split '#'
    id = id.replace '#', ''
    classes.push klass unless klass is ''
  else
    classes.push i unless i is ''

Since the i.split '#' returns only a two element array, it would be safe to avoid using the ... operand on klass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment