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

Encoded HTML ssr/browser rendering #84

Closed
jondashkyle opened this issue Jul 12, 2017 · 7 comments
Closed

Encoded HTML ssr/browser rendering #84

jondashkyle opened this issue Jul 12, 2017 · 7 comments

Comments

@jondashkyle
Copy link
Contributor

jondashkyle commented Jul 12, 2017

Really enjoying the new SSR capabilities with bel! I wanted to render some Markdown output on the server recently, and with @yoshuawuyts’s help was able to get this working in both the browser and SSR by doing something like this:

var example = format('<p>some example</p><h2>markdown output</h2>')

function format (str) {
  if (typeof window !== 'undefined') {
    var wrapper = html`<div></div>`
    wrapper.innerHTML = str
    return wrapper
  } else {
    var wrapper = new String(str)
    wrapper.__encoded = true
    return wrapper
  }
}

And a little interactive example using Glitch. Super awesome, but a little verbose. Maybe there is a way to do this using a single unified method? #42

@louiscenter
Copy link
Member

this is a really useful snippet! thanks for sharing ✨

just incase anyone takes this for a spin with choo, make sure you're using v6, as it won't be compatible with choo v5 (found this out the hard way 😅)

@axelav
Copy link

axelav commented Aug 4, 2017

brilliant! spent a while digging into this issue tonight until I got down to pelo & saw what was happening. this works perfectly, should def go on the working with html section of the wiki :)

@bcomnes
Copy link
Collaborator

bcomnes commented Aug 4, 2017

Would this be worth exporting as a bundled-but-separate utility function?

@yoshuawuyts
Copy link
Member

yoshuawuyts commented Aug 7, 2017 via email

@jondashkyle
Copy link
Contributor Author

jondashkyle commented Aug 7, 2017

@yoshuawuyts Yeah, echoing that thought—was discussing this with @louiscenter as I’m using this method within several projects right now. Keeping it within the bel package but separate from the core would be a great move. I could make a PR for it?

Also, a fan of bel/raw. 3/3.

@yoshuawuyts
Copy link
Member

yoshuawuyts commented Aug 7, 2017 via email

@goto-bus-stop
Copy link
Member

https://github.com/choojs/nanohtml/blob/master/raw.js !

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

6 participants