Skip to content

Instantly share code, notes, and snippets.

@clausd
Created March 10, 2009 18:33
Show Gist options
  • Select an option

  • Save clausd/77051 to your computer and use it in GitHub Desktop.

Select an option

Save clausd/77051 to your computer and use it in GitHub Desktop.
/* Convert selection to HTML entitites - danish chars only */
CmdUtils.CreateCommand({
name: "entitize",
icon: "http://www.classy.dk/favicon.ico",
homepage: "http://www.classy.dk/",
author: { name: "Claus Dahl", email: "dee@classy.dk"},
license: "GPL",
description: "Translates danish characters to html entities",
help: "select text and apply to replace with entitized text",
takes: {"input": noun_arb_text},
_entitize: function (input) {
var text = input;
text = text.replace(/&/g, "&");
text = text.replace(/>/g, ">");
text = text.replace(/</g, "&lt;");
text = text.replace(/ø/g,'&amp;oslash;');
text = text.replace(/Ø/g,'&amp;Oslash;');
text = text.replace(/å/g,'&amp;aring;');
text = text.replace(/Å/g,'&amp;Aring;');
text = text.replace(/æ/g,'&amp;aelig;');
text = text.replace(/Æ/g,'&amp;AElig;');
text = text.replace(/ä/g,'&amp;auml;');
text = text.replace(/Ä/g,'&amp;Auml;');
text = text.replace(/ö/g,'&amp;ouml;');
text = text.replace(/Ö/g,'&amp;Ouml;');
return text;
},
preview: function( pblock, input ) {
pblock.innerHTML = this._entitize(input.html);
},
execute: function(input) {
CmdUtils.setSelection(this._entitize(input.html));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment