Last active
December 9, 2015 08:26
-
-
Save think49/1032896 to your computer and use it in GitHub Desktop.
encodeHtmlEntity.js : <>&"' をHTMLエンティティ化する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* encode-html-entity.js | |
* encode Character entity reference & Numeric character reference. | |
* | |
* @version 1.0.3 | |
* @author think49 | |
* @url https://gist.github.com/1032896 | |
* @license http://www.opensource.org/licenses/mit-license.php (The MIT License) | |
* @see <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/named-character-references.html">11.5 Named character references - HTML Standard</a> | |
* @see <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/apis-in-html-documents.html#innerhtml">3.3 APIs in HTML documents - HTML Standard</a> | |
*/ | |
var encodeHtmlEntity = (function (String) { | |
function encodeHtmlEntity (string) { | |
return String(string).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/\x22/g, '"').replace(/\x27/g, ''') | |
} | |
return encodeHtmlEntity; | |
}(String)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ver 1.0.3
'
に未対応だったのでシングルクォートは'
に書き換えるように修正しました。