Skip to content

Instantly share code, notes, and snippets.

@somebody1234
Last active October 24, 2016 08:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save somebody1234/8255fbaf9d1b76af7eae76a4b5accc4e to your computer and use it in GitHub Desktop.
Save somebody1234/8255fbaf9d1b76af7eae76a4b5accc4e to your computer and use it in GitHub Desktop.
TIO modified snippet
function encodeInput(encoding) {
var input = document.getElementById("input");
return input ? "&input=" + encoding(input.value) : "";
}
var snippet = (function () {
var custom = {"05AB1E":1,"2sable":1,"Actually":1,"Convex":1,"GS2":1,"Jelly":1,"M":1,"pl":1,"Retina":1,"Seriously":1,"V":1},
newlineCharCode = "\n".charCodeAt(0),
alphaCharCode = "α".charCodeAt(0),
omegaCharCode = "ω".charCodeAt(0),
omicronCharCode = "ο".charCodeAt(0),
fullwidthACharCode = "A".charCodeAt(0),
fullwidthZCharCode = "Z".charCodeAt(0),
otherCharcoalCharacters = "⁰¹²³⁴⁵⁶⁷⁸⁹\
⟦⟧⦃⦄«»⁺⁻×÷﹪∧∨¬⁼‹›\
←↑→↓↖↗↘↙\
↶↷⟲¿‽‖´·¤¦“”⎚¶…§⎇";
function inCharcoalCodepage (character) {
var charcode = character.charCodeAt(0);
return (
(charcode <= 128 && character != newlineCharCode) ||
(charcode >= alphaCharCode && charcode <= omegaCharCode && charcode != omicronCharCode) ||
(charcode >= fullwidthACharCode && charcode <= fullwidthZCharCode) ||
otherCharcoalCharacters.includes(character)
);
}
function charcoalLength (string) {
var length = 0
for (var i = 0; i < string.length; i++) {
var character = string[i];
if (inCharcoalCodepage(character))
length++;
else
length += unescape(encodeURIComponent(character)).length;
}
return length;
}
return function () {
permalink();
var language = document.getElementById("lang").innerText,
languageLink = document.getElementById("lang").href,
code = document.getElementById("code").value,
codeLength = language === "Charcoal" ?
charcoalLength(code) :
(
custom[language] ?
code :
unescape(encodeURIComponent(code))
).length;
return "# [" + language + "](" + languageLink + "), " +
codeLength + " byte" + (codeLength == 1 ? "" : "s") +
"\n\n" + code.replace(/^/gm, ' ') + "\n\n[Try it online!](" + window.location.href + ")";
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment