INNER CODE UNIT · TypeScript
getExt
philschmid/clipper.js · src/clipper.ts:18
const getExt = (node: any) => {
// Simple match where the <pre> has the `highlight-source-js` tags
const getFirstTag = (node: Element) =>
node.outerHTML.split('>').shift()! + '>';
const match = node.outerHTML.match(
/(highlight-source-|language-)[a-z]+/
);
if (match) return match[0].split('-').pop();
// Check the parent just in case
const parent = getFirstTag(node.parentNode!).match(
/(highlight-source-|language-)[a-z]+/
);
if (parent) return parent[0].split('-').pop();