main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
867 bytes
|
Rev | Line | |
---|
[d24f17c] | 1 | 'use strict'
|
---|
| 2 |
|
---|
| 3 | /* eslint-env browser */
|
---|
| 4 |
|
---|
| 5 | var el
|
---|
| 6 |
|
---|
| 7 | var semicolon = 59 // ';'
|
---|
| 8 |
|
---|
| 9 | module.exports = decodeEntity
|
---|
| 10 |
|
---|
| 11 | function decodeEntity(characters) {
|
---|
| 12 | var entity = '&' + characters + ';'
|
---|
| 13 | var char
|
---|
| 14 |
|
---|
| 15 | el = el || document.createElement('i')
|
---|
| 16 | el.innerHTML = entity
|
---|
| 17 | char = el.textContent
|
---|
| 18 |
|
---|
| 19 | // Some entities do not require the closing semicolon (`¬` - for instance),
|
---|
| 20 | // which leads to situations where parsing the assumed entity of ¬it; will
|
---|
| 21 | // result in the string `¬it;`. When we encounter a trailing semicolon after
|
---|
| 22 | // parsing and the entity to decode was not a semicolon (`;`), we can
|
---|
| 23 | // assume that the matching was incomplete
|
---|
| 24 | if (char.charCodeAt(char.length - 1) === semicolon && characters !== 'semi') {
|
---|
| 25 | return false
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | // If the decoded string is equal to the input, the entity was not valid
|
---|
| 29 | return char === entity ? false : char
|
---|
| 30 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.