Permalink
Browse files

Improve `he.encode` documentation

Make it clear that enabling the `strict` option causes `he.encode` to either throw (for input containing invalid code points) or return a string of valid HTML.

Closes #49.
  • Loading branch information...
mirabilos authored and mathiasbynens committed Aug 30, 2016
1 parent a836f82 commit 6467b1f4e14b2bc09d8e1210baecc38078281c72
Showing with 3 additions and 1 deletion.
  1. +3 −1 README.md
@@ -71,13 +71,15 @@ he.encode('foo © bar ≠ baz 𝌆 qux');
// → 'foo © bar ≠ baz 𝌆 qux'
```

As long as the input string contains [allowed code points](https://html.spec.whatwg.org/multipage/parsing.html#preprocessing-the-input-stream) only, the return value of this function is always valid HTML. Any [(invalid) code points that cannot be represented using a character reference](https://html.spec.whatwg.org/multipage/syntax.html#table-charref-overrides) in the input are not encoded.
As long as the input string contains [allowed code points](https://html.spec.whatwg.org/multipage/parsing.html#preprocessing-the-input-stream) only, the return value of this function is always valid HTML. Any [(invalid) code points that cannot be represented using a character reference](https://html.spec.whatwg.org/multipage/syntax.html#table-charref-overrides) in the input are not encoded:

```js
he.encode('foo \0 bar');
// → 'foo \0 bar'
```

However, enabling [the `strict` option](https://github.com/mathiasbynens/he#strict) causes invalid code points to throw an exception. With `strict` enabled, `he.encode` either throws (if the input contains invalid code points) or returns a string of valid HTML.

The `options` object is optional. It recognizes the following properties:

#### `useNamedReferences`

0 comments on commit 6467b1f

Please sign in to comment.