Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

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
Open

id & class shortcuts expect exact order #83

rachel-carvalho opened this issue Oct 4, 2011 · 4 comments
Labels

Comments

@rachel-carvalho
Copy link
Contributor

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>
@ewollesen
Copy link

An additional case that might prove illuminating:

div ".foo#bar.baz"

Yields

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

@treeform
Copy link

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
Copy link

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
Copy link

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
Labels
Projects
None yet
Development

No branches or pull requests

4 participants