Last active
October 24, 2016 08:07
TIO modified snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function encodeInput(encoding) { | |
var input = document.getElementById("input"); | |
return input ? "&input=" + encoding(input.value) : ""; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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