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

Wrong attribute parsing #62

Open
YerkoPalma opened this issue Jan 13, 2017 · 9 comments
Open

Wrong attribute parsing #62

YerkoPalma opened this issue Jan 13, 2017 · 9 comments

Comments

@YerkoPalma
Copy link
Member

I'm having problems with bel. I try to use bel to render some markdown content with the help of marked library. With this code

const html = require('yo-yo')
const marked = require('marked')

const post = require('./posts/post.md')
console.log(marked(post))
document.body.appendChild(html(marked(post)))

And this markdown content

# hello world

I'm using stringify to require the .md file content. When I console log the marked(post) call, I get

<h1 id="hello-world">hello world</h1>

That's pretty valid html to me, but bel complains with this error.

Uncaught DOMException: Failed to execute 'setAttribute' on 'Element': 'hello-world"' is not a valid attribute name.
at belCreateElement (http://playground-yerkopalma.c9users.io:8080/bundle.js:1447:14)
at http://playground-yerkopalma.c9users.io:8080/bundle.js:1807:12
at http://playground-yerkopalma.c9users.io:8080/bundle.js:1569:45
at Object.1../posts/post.md (http://playground-yerkopalma.c9users.io:8080/bundle.js:7:27)
at s (http://playground-yerkopalma.c9users.io:8080/bundle.js:1:254)
at e (http://playground-yerkopalma.c9users.io:8080/bundle.js:1:425)
at http://playground-yerkopalma.c9users.io:8080/bundle.js:1:443

And the problem is that when the belCreateElement function is called, it is called with wrong attributes

error

Now why is that happening? I thought about an hyperx error, but tried it with hyperscript and it render correctly. Not sure what could it be, also looked at the hyperscript-attribute-to-property library inside hyperx, but again why would it work with hyperscript, but not with bel?

Any help would be appreciated.

@roobie
Copy link

roobie commented Jan 31, 2017

I've experienced the same issue. Funny thing is:

This does not work, as @YerkoPalma states above:

html(htmlAsText)

However, this works:

eval('html`' + htmlAsText + '`');

Which leads me to the suspicion that there is some conditional somewhere in the library that makes the parsing go differently depending on whether it is used as a template string or as an ordinary function.

(Tested in Chromium Version 55.0.2883.75 built on Debian stretch/sid, running on Debian 9.0 (64-bit))

@yoshuawuyts
Copy link
Member

yoshuawuyts commented Jan 31, 2017 via email

@roobie
Copy link

roobie commented Jan 31, 2017

Personally, I used 'choo/html' but the Error is thrown in bel, which is why I chimed in here, but I may be a bit off =)

@yoshuawuyts
Copy link
Member

yoshuawuyts commented Jan 31, 2017 via email

@blahah
Copy link
Contributor

blahah commented Feb 26, 2017

@yoshuawuyts I use html(foo) quite a lot in choo. It's useful whenever you want to use some externally supplied HTML. Can you elaborate on why it's a bad idea? Apart from this issue of course, which seems like a bug.

@yoshuawuyts
Copy link
Member

yoshuawuyts commented Feb 27, 2017 via email

@roobie
Copy link

roobie commented Feb 28, 2017

@blahah you've never had the DOMException thrown from bel when doing that?

@blahah
Copy link
Contributor

blahah commented Feb 28, 2017

@roobie I have, only with certain elements. It always happens with <img src="..." />, but quite often I don't get the error.

I was suggesting that the usage pattern of passing HTML to html() is useful, and questioning why it would be a bad idea. I'd love to see this solved.

@YerkoPalma
Copy link
Member Author

YerkoPalma commented Feb 28, 2017

I guess that the problem might be related with yo-yoify. As it is a browserify transform, it can make a difference if it is called like

bel(str)

or like

bel`${str}`

Because of the parsing made by yo-yoify. Also, it is only my thoughts as I havent checked the code yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants