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

What if tag contains text mixed with formatting nodes? #58

Open
jayarjo opened this issue Oct 4, 2016 · 2 comments
Open

What if tag contains text mixed with formatting nodes? #58

jayarjo opened this issue Oct 4, 2016 · 2 comments

Comments

@jayarjo
Copy link

jayarjo commented Oct 4, 2016

Consider html like this:

<p>
     Some text here with <strong>parts</strong> and some 
     <span style="color: purple;">inline styling</span>.
</p>

How do we convert this to HyperScript?

@dominictarr
Copy link
Collaborator

dominictarr commented Oct 6, 2016

those values would be escaped - they'd appear in the text as <strong> not as tags. If you trust the string, then you can do h('div', {innerHTML: string}) but if it's a user provided string, that will be a security hole.

in that case, you just need to find an html escaping module, than can allow certain tags and not others.

@fadookie
Copy link

innerHTML seems to work great for parsing an HTML string into a hyperscript object at runtime.

But for posterity I wanted to show an example of how to translate the above HTML snippet into hyperscript code, since you can supply a children array with a mix of strings and hyperscript tags like so:

h('p', [
    'Some text here with ',
     h('strong', 'parts'),
     ' and some',
     //etc.
])

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

3 participants