Skip to content

Instantly share code, notes, and snippets.

@cojahmetov
Created February 5, 2015 19:52
Show Gist options
  • Select an option

  • Save cojahmetov/a5646164e6212ebd3b67 to your computer and use it in GitHub Desktop.

Select an option

Save cojahmetov/a5646164e6212ebd3b67 to your computer and use it in GitHub Desktop.
#js# content to html entities
function htmlEntities (str) {
return String(str)
.replace(/&/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
}
function toHtml(content) {
var text = htmlEntities(content);
var text = text.replace(/(?:\r\n|\r|\n)/g, '<br />');
return text;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment