Encode and decode HTML entities

These are not sufficient to escape strings embedded in comments.

Character | Entity | escape_text | escape_attribute | escape_all_quotes ----------|----------|---------------|--------------------|-------------------- & | &amp; | ✔ | ✔ | ✔ < | &lt; | ✔ | ✔ | ✔ > | &gt; | ✔ | ✔ | ✔ " | &quot; | | ✔ | ✔ ' | &apos; | | | ✔

escape_text(string) -> String

Escape a string so that it can be embedded in the main text. This does not escape quotes at all.

API docs.

escape_attribute(string) -> String

Escape a string so that it can be embedded in an attribute. Always use double quotes around attributes.

API docs.

escape_all_quotes(string) -> String

Escape a string including both single and double quotes. In general you should not need to use this.

API docs.

unescape(string) -> String

This follows the [official WHATWG algorithm] for expanding entities. The only exception should be that entities are supposed to be expanded slightly differently when they are in the main body of the text as opposed to within an attribute.

API docs.

License

This project dual-licensed under the Apache 2 and MIT licenses. You may choose to use either.

Contributions

Unless you explicitly state otherwise, any contribution you submit as defined in the Apache 2.0 license shall be dual licensed as above, without any additional terms or conditions.