Sha256: f9f90d972e46e8e1eeb55b0d60e79ec576573609774d826fd71dfe0364a43854

Contents?: true

Size: 1.11 KB

Versions: 193

Compression:

Stored size: 1.11 KB

Contents

// Replace all occurences of "--" (double-hyphens,) within the page's text-nodes, with em-dashes.
// Use a replacer function to omit any occurences of triple-hyphens which appear in our documentation.
// For example, YAML Front - matter's opening and closing triple-hyphens
// Without the replacer funciton, triple-hyphens get replaced with an em-dash and a hyphen.
const emDashOrTripleHyphensRegex = /---?/g;
const tripleHyphenRegex = /---/;
const emDashReplacement = '—' // This is an em-dash, however, it looks like a hyphen in monospace text editor font!

function replacerFunction(match) {
  return match.search(tripleHyphenRegex) === -1 ? emDashReplacement : match;
}
function walkText(node) {
  if (node.nodeType == 3) {
    node.data = node.data.replace(emDashOrTripleHyphensRegex, replacerFunction);
  }
  if (node.nodeType == 1 && node.nodeName != 'SCRIPT') {
    for (var i = 0; i < node.childNodes.length; i++) {
      walkText(node.childNodes[i]);
    }
  }
}
//  Note on usage: You don't need to necessarily traverse the entire document.body. 
//  Usage:
//
//    walkText(document.body);
//
export default walkText;

Version data entries

193 entries across 193 versions & 2 rubygems

Version Path
kcc-gem-theme-3.12.5 assets/js/src/walkText.js
kcc-gem-theme-3.12.4 assets/js/src/walkText.js
kcc-gem-theme-3.12.3 assets/js/src/walkText.js
kcc-gem-theme-3.12.2 assets/js/src/walkText.js
kcc-gem-theme-3.12.1 assets/js/src/walkText.js
kcc-gem-theme-3.12.0 assets/js/src/walkText.js
kcc-gem-theme-3.11.5 assets/js/src/walkText.js
kcc-gem-theme-3.11.4 assets/js/src/walkText.js
kcc-gem-theme-3.11.3 assets/js/src/walkText.js
kcc-gem-theme-3.11.1 assets/js/src/walkText.js
kcc-gem-theme-3.11.0 assets/js/src/walkText.js
kcc-gem-theme-3.10.7 assets/js/src/walkText.js
kcc-gem-theme-3.10.6 assets/js/src/walkText.js
kcc-gem-theme-3.10.5 assets/js/src/walkText.js
kcc-gem-theme-3.10.4 assets/js/src/walkText.js
kcc-gem-theme-3.10.3 assets/js/src/walkText.js
kcc-gem-theme-3.10.2 assets/js/src/walkText.js
kcc-gem-theme-3.10.1 assets/js/src/walkText.js
kcc-gem-theme-3.10.0 assets/js/src/walkText.js
kcc-gem-theme-3.9.4 assets/js/src/walkText.js