-# The list of named character references is _huge_ so ask the browser to decode
-# for us instead of wasting bandwidth/space on including the table here.
-#
-# Pass without the "&" but with the ";" examples:
-# for "&" pass "amp;"
-# for "′" pass "x2032;"
-g_dncr = {
- cache: {}
- textarea: document.createElement('textarea')
-}
-# TODO test this in IE8
+# The list of named character references is _huge_ so if we're running in a
+# browser, we get the browser to decode them, rather than increasing the code
+# size to include the table.
+if context is 'module'
+ _decode_named_char_ref = require './html5-named-entities.coffee'
+else
+ # TODO test this in IE8
+ decode_named_char_ref_el = document.createElement('textarea')
+ _decode_named_char_ref = (txt) ->
+ txt = "&#{txt};"
+ decode_named_char_ref_el.innerHTML = txt
+ decoded = decode_named_char_ref_el.value
+ return null if decoded is txt
+ return decoded
+# Pass the name of a named entity _that has a terminating semicolon_
+# Entities without terminating semicolons should use legacy_char_refs[]
+# Do not include the "&" or ";" in your argument, eg pass "alpha"
+decode_named_char_ref_cache = {}