FANDOM


EntityConvert is a tool that allows you to quickly encode/decode HTML entities, and change some encoding and decoding settings.

Installation

Installation

Add this JavaScript on your wiki:

Global Personal Site-wide
w:Special:Mypage/global.js Special:Mypage/common.js MediaWiki:Common.js
importArticles({
	type: "script",
	articles: [
		"u:dev:EntityConvert/code.js"
	]
});
importArticles — Best Practices for installing JavaScript on Fandom
The importArticles statement is designed to combine multiple HTTP requests into a single data transfer, allowing multiple scripts to load and execute faster. If you've been installing several different scripts, your JavaScript file has probably accumulated unnecessary import statements. Click "Expand" to learn how to efficiently batch import scripts to speed up performance and make your code look cleaner. One other approach is by using the MediaWiki:ImportJS.
If your JavaScript file has several lines of code that say importScript, importScriptPage, or importArticles, you may be able to combine them! By batch importing a collection of scripts with a single import, your JavaScript code will load faster and look cleaner. Consider the example below. On the left is an example of what your JavaScript file might currently look like. On the right is how you could improve that code.
Multiple imports — messy and slow One import — clean and efficient
importScriptPage('AjaxRC/code.js','dev');
 
importScript('MediaWiki:localScript.js');
 
importArticle({
  type: 'script',
  article: 'u:dev:FloatingToc/code.js'
});
 
importScriptPage('page1.js', 'wikiname');
 
importScriptPage('page2.js', 'wikiname');
importArticles({
    type: 'script',
    articles: [
        'u:dev:AjaxRC/code.js',
        'MediaWiki:localScript.js',
        'u:dev:FloatingToc/code.js',
        'u:wikiname:page1.js',
        'u:wikiname:page2.js'
    ]
});
Note: In this example, pay close attention to the placement of commas and other punctuation. For people who aren't familiar with programming (and even those who are!), a common mistake when writing code is to accidentally delete, forget, or misplace critical symbols like commas or quotation marks. This can cause a syntax error that breaks the code. Carefully follow the convention shown here when using importArticles.
But there's much more to importArticles than just this! For more examples and advanced usage, see the help page at Help:Including additional JavaScript and CSS.


Settings

EntityConvert has an options menu with several encoding and decoding settings:

Encoding options
  • Convert text to decimal or hexadecimal (e.g. the lower case letter "z" as a decimal entity would be z, and z in hexadecimal).
  • Encode default XML entities only (&, ", ', <, >) and not other characters.
Decoding options
  • Choose whether or not to decode number entities (decimal and/or hexadecimal), ampersad (&amp;) and other default XML entities.

Input size

In case that the input is larger than 100,000 bytes, on which case the convertion may take a few seconds, a notice would pop up, asking you whether or not you wish to continue. It can be disabled via the settings as well, however, choosing to only convert "vital characters" (XML default entities) should speed up the convertion.

Entities decode

The decode tool can only decode number entities (decimal and hexadecimal) and the default XML entities. For instance, if you were to try and decode &nbsp; or &euro;, they would not be converted, however, you can also specify a list of additional entities to replace these entities as well.

Outputs

Note that EntityConvert only encodes characters in either decimal (like &#122;) or hexadecimal entities (like &#x7a;).

Custom entities

As EntityConvert only allows decoding the default XML entities and decimal/hexadecimal entities, for decoding entities like &nbsp;, &bull;, &euro; or &trade;, you'd need to use further customization for these entities. In order to do that, above the script import function in your JS page, place the following code to declare further entities that you'd like to code. On the example below, the entities are placed in the following object. Each property represents the entitie's name (e.g. bull for &bull;, which produces •), and its property is the character that this entity represents. The values in this example are unicode-encoded, but you can use instead the actual characters:

EntityConvert = {
	"entities": {
		"custom": {
			"nbsp": "\u00a0", // non-breaking space
			"bull": "\u2022", // bullet sign •
			"trade": "\u2022", // trademark sign ™
			"copy": "\u00a9", // copyright sign ©
			"pound": "\u00a3" // pound sign £
		}
	}
}

This feature also allows you to decode "pseudo entities"- in case you used custom entities that are not supported by web browsers.

Skin Support

The feature works both in the Oasis and Monobook skins. It's accessible in the following ways:

  • In monobook it's accessible through the "wikia" section in the left wiki rail.
  • In wiki:
    • It appears in the "My Tools" menu in the bottom wiki navigation.
    • In case that the MyTools already has 10 or more list items, it would be appended to the bottom wiki navigation list itself.

Versions

  • December 14, 2014- Updating selectors for Oasis.
  • March 4, 2014- minimizing decoding function and adding optional custom entities.
  • February 10, 2014- Updating selectors for Oasis.
  • December 3, 2013- EntityConvert is released.

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.