Skip to content

Commit

Permalink
Added example code blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
meggles711 committed Jul 27, 2020
1 parent 393ee95 commit ad5d177
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/trusted_types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ based on the sink context. Each policy should be given a distinct name.
Here is an example policy that sanitizes HTML by escaping the ``<`` character.

.. code-block:: javascript
if (window.trustedTypes && trustedTypes.createPolicy) {
const escapeHTMLPolicy = trustedTypes.createPolicy('myEscapePolicy', {
createHTML: string => string.replace(/\</g, '&lt;')
Expand All @@ -93,6 +94,7 @@ Here is an example policy that sanitizes HTML by escaping the ``<`` character.
Here is an example of how that policy can be used.

.. code-block:: javascript
const escaped = escapeHTMLPolicy.createHTML('<img src=x onerror=alert(1)>');
console.log(escaped instanceof TrustedHTML);
el.innerHTML = escaped;
Expand Down

0 comments on commit ad5d177

Please sign in to comment.