Skip to main content

Parser

Index

Constructors

constructor

Properties

allowed

allowed: Set<string>

banned

banned: Set<string>

blocked

blocked: Set<string>

optionalcontainer

container?: HTMLElement

content

content: Node[] = []

filters

filters: FilterInterface[]

keyIndex

keyIndex: number

matchers

matchers: MatcherInterface<any>[]

props

Methods

applyAttributeFilters

  • Loop through and apply all registered attribute filters.


    Type parameters

applyMatchers

  • Loop through and apply all registered matchers to the string. If a match is found, create a React element, and build a new array. This array allows React to interpolate and render accordingly.

applyNodeFilters

  • applyNodeFilters(name: string, node: null | HTMLElement): null | HTMLElement
  • Loop through and apply all registered node filters.

canRenderChild

  • Determine whether the child can be rendered within the parent.

convertLineBreaks

  • convertLineBreaks(markup: string): string
  • Convert line breaks in a string to HTML <br/> tags. If the string contains HTML, we should not convert anything, as line breaks should be handled by <br/>s in the markup itself.

createContainer

  • createContainer(markup: string): undefined | HTMLElement
  • Create a detached HTML document that allows for easy HTML parsing while not triggering scripts or loading external resources.

extractAttributes

  • extractAttributes(node: HTMLElement): null | Attributes
  • Convert an elements attribute map to an object map. Returns null if no attributes are defined.

extractStyleAttribute

  • extractStyleAttribute(node: HTMLElement): object
  • Extract the style attribute as an object and remove values that allow for attack vectors.

getTagConfig

  • Return configuration for a specific tag.

isSafe

  • isSafe(node: HTMLElement): boolean
  • Verify that a node is safe from XSS and injection attacks.

isTagAllowed

  • isTagAllowed(tagName: string): boolean
  • Verify that an HTML tag is allowed to render.

parse

  • Parse the markup by injecting it into a detached document, while looping over all child nodes and generating an array to interpolate into JSX.

parseNode

  • Loop over the nodes children and generate a list of text nodes and React elements.

replaceTokens

  • Deconstruct the string into an array, by replacing custom tokens with React elements, so that React can render it correctly.