Last active
March 20, 2017 01:44
-
-
Save r-k-b/dd02d4e641826a721dec112d40b90630 to your computer and use it in GitHub Desktop.
Allow Ligatures in more places in Sanctuary.js's docs. Intended for use alongside a custom CSS theme that applies a font like Fira Code.
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
// ==UserScript== | |
// @name Ligatures for Sanctuary.js Docs | |
// @namespace https://gist.github.com/r-k-b/ | |
// @version 0.1 | |
// @description Allow Ligatures in more places in Sanctuary.js's docs. Intended for use alongside a custom CSS theme that applies a font like Fira Code. | |
// @author Robert K. Bell | |
// @homepage https://gist.github.com/r-k-b/dd02d4e641826a721dec112d40b90630 | |
// @downloadURL https://gist.github.com/r-k-b/dd02d4e641826a721dec112d40b90630/raw/ligatures-for-sanctuary.user.js | |
// @match https://sanctuary.js.org/* | |
// @grant none | |
// @run-at document-idle | |
// ==/UserScript== | |
/* jshint esnext: true */ | |
(function(){ | |
const gap = /\u2060/g; | |
function stripSpan(el) { | |
const parent = el.parentNode; | |
while (el.childNodes.length > 0) { | |
nextChild = el.childNodes[0]; | |
parent.insertBefore(nextChild, el); | |
} | |
parent.removeChild(el); | |
parent.normalize(); | |
// strip invisible whitespace | |
for (i=parent.childNodes.length; i>0; i--) { | |
let e = parent.childNodes[i-1]; | |
if (e.nodeType == Node.TEXT_NODE) { | |
e.nodeValue = gap[Symbol.replace](e.nodeValue, ''); | |
} | |
} | |
} | |
const hyphens = Array.prototype.slice.call( | |
document.querySelectorAll('.arrow-hyphen') | |
); | |
hyphens.forEach(stripSpan); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment