Skip to content

Allow HTML in content #3

Description

@vinyll

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)
    ])
  }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions