Module:encodings/documentation

From Wiktionary, the free dictionary
Jump to navigation Jump to search
Documentation for Module:encodings. [edit]
This page contains usage information, categories, interwiki links and other content describing the module.

The module defines a set "encoders" which are able to encode the text into a given encoding. More encoders can be added to the module as necessary.

encode

[edit]

Function encode(text, encoding)

Takes 'text' in UTF-8 encoding, encodes into 'encoding' and into %-encoding, returns the resulting string.

Explanation

[edit]
  • UTF-8: the wiki software and all its pages and output use UTF-8.
  • %-encoding: 1) encoded text is bound to contain invalid UTF-8 text and Scribunto does not allow modules to return invalid UTF-8 text (replaces any invalid bytes in the output with � [U+FFFD REPLACEMENT CHARACTER]), 2) primary use of this function is to encode text for use in URLs (external links), for certain sites that use older encodings.

Custom encoder methods

[edit]

Number difference

[edit]
  • Paste input and output hex-numbers to LibreOffice Calc and sort by input
  • Convert base-16 [hexadecimal] to base-10 [decimal] (e.g. with onlinenumbertools.com, toolslick.com, or see below custom converter)
  • Calculate difference (using references)
  • Sort by difference, color the background of repeating differences, sort by input
Custom converter
<!DOCTYPE html>
<html>
<head>
<script>
function baseconvert() {
	var base0 = parseInt( document.querySelector("#base0").innerText );
	var base1 = parseInt( document.querySelector("#base1").innerText );
	var dText0 = document.querySelector("#text0");
	var dText1 = document.querySelector("#text1");
	var ns = dText0.value.split("\n"); // numbers
	dText1.innerHTML = "";
	for (var i=0; i < ns.length; i++) {
		if (i)
			dText1.append( "\n" );
		if ( ns[i].search(/^[0-9A-Z]+$/gi) != -1 )
			dText1.append( parseInt(ns[i],base0).toString(base1) ); // XX > 10 > ZZ
	}
	dText0.style["height"] = "32px";  // variable .text height
	dText1.style["height"] = "32px";
	dText0.style["height"] = dText0.scrollHeight + "px";
	dText1.style["height"] = dText1.scrollHeight + "px";
}
document.addEventListener("DOMContentLoaded", function() {
	baseconvert();
	document.querySelector("#text0").addEventListener("input", baseconvert);
});
</script>
<style>
body {background: lightgray; display: grid; grid-template-columns: auto auto; gap: 8px;}
#desc {grid-column: 1 / -1;}
#desc, #base0, #base1 {justify-self: center; width: auto;}
#text0, #text1 {font-family: monospace, monospace; resize: none;}
</style>
</head>
<body>
	<div id="desc">Convert from left to right</div>
	<div id="base0" contenteditable>16</div>
	<div id="base1" contenteditable>10</div>
	<textarea id="text0">BADCAFE</textarea>
	<textarea id="text1" readonly></textarea>
</body>
</html>

{{R:IEC2}} (Catalan IEC dictionary) required input in ISO 8859-1 encoding:

  • {{#invoke:encodings|encode|abundància|ISO 8859-1}}
  • abund%E0ncia (< abundància)

See also

[edit]