Campus Novel

Dispatches from the Higher Ed Front

let regex = new RegExp(/\[\[([0-9]+)\]\](?!:)/, 'g') ; document.querySelectorAll('article p, article li, article figcaption, article .kg-callout-text').forEach(element => { var textchunk = ""; for (var i = 0; i < element.childNodes.length; i++) { var curNode = element.childNodes[i]; if (curNode.nodeName === "#text") { textchunk=curNode.nodeValue const matches = curNode.nodeValue.matchAll(regex); for (const match of matches) { let firstpiece = textchunk.slice(0,match.index) let lastpiece = textchunk.slice(match.index + match[0].length) let linkpiece = ` ${match[1]} ` let newpiece = firstpiece + linkpiece + lastpiece let tmp = document.createRange().createContextualFragment(newpiece) curNode.replaceWith(tmp) } } } } ) let regex2 = new RegExp(/\[\[([0-9]+)\]\]:/, 'g') for (let node of document.querySelectorAll('article p')) { textchunk=node.innerHTML const matches = textchunk.matchAll(regex2); for (const match of matches) { let newpiece = `
  1. ${textchunk.slice(match[1].length + 5)}

` let tmp = document.createRange().createContextualFragment(newpiece) node.replaceWith(tmp) } }