Port of Python's html.escape and html.unescape to Nim
Find a file
2021-11-28 15:53:42 -03:00
.github/workflows Add build workflow 2021-11-24 17:24:05 -03:00
external Minor refactoring 2021-11-28 12:41:56 -03:00
src Make unescape() GC-safe 2021-11-28 15:52:54 -03:00
tests Add build workflow 2021-11-24 17:24:05 -03:00
.gitignore Initial commit 2021-11-24 17:08:59 -03:00
htmlunescape.nimble Bump version 2021-11-28 15:53:42 -03:00
README.md Add README 2021-11-24 17:48:49 -03:00

HTML (Un)escape is a port of Python's html.escape and html.unescape to Nim.

Installation

Install using nimble:

nimble install --accept 'htmlunescape'

Usage:

Escaping sequences:

import htmlunescape

assert escape(s = "'<script>\"&foo;\"</script>'") == "&#x27;&lt;script&gt;&quot;&amp;foo;&quot;&lt;/script&gt;&#x27;"
assert escape(s = "'<script>\"&foo;\"</script>'", quote = false) == "'&lt;script&gt;\"&amp;foo;\"&lt;/script&gt;'"

Unescaping sequences:

import htmlunescape

assert unescape(s = "&quot;&quot;&quot;") == "\"\"\""
assert unescape(s = "&amp;&amp;&amp;") == "&&&"

Contributing

If you have discovered a bug in this library and know how to fix it, fork this repository and open a Pull Request.