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

Allow HTML in content #3

Open
vinyll opened this issue Apr 10, 2020 · 0 comments
Open

Allow HTML in content #3

vinyll opened this issue Apr 10, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@vinyll
Copy link
Member

vinyll commented Apr 10, 2020

In some case a text contains HTML.
It would be unsafe when it comes from a user as it would permit XSS injection.
However when the text comes from a safe place, it would be handy to allow HTML content.

However I'm not aware of a way to declare text as safe html.

The solution I found is to create a component to include as child:

class SafeHTML extends Component {
  connected() {
    this.document.innerHTML = this.document.host.textContent
  }
}
customElement.define('safe-html', SafeHTML)

and then use it in my component:

class MyStuff extends Component {
  init() {
    this.state = { myText: "Hey <strong>Joe</strong>" }
  }
  vdom() {
    return ({ state }) => h('p', {}, [
      "reply: ",
      h('safe-html', {}, state.myText)
    ])
  }
}
@vinyll vinyll added the enhancement New feature or request label Apr 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant