Skip to content

Instantly share code, notes, and snippets.

@radusuciu
Created January 25, 2018 02:38
Show Gist options
  • Save radusuciu/d07ca374bb168973fbc6632e89101ffc to your computer and use it in GitHub Desktop.
Save radusuciu/d07ca374bb168973fbc6632e89101ffc to your computer and use it in GitHub Desktop.
Generate a list of Cravatt alumni in markdown format from an html source
var els = Array.from(document.getElementsByTagName('tr'));
els.shift();
var processed = []
for (let el of els) {
if (!el.hasChildNodes()) {
continue;
}
[, nameEl, positionEl, currentPositionEl, ] = el.getElementsByTagName('td');
var currentPosition = currentPositionEl.textContent.trim().split('\n\n').shift().split('\n');
var emailEl = currentPositionEl.getElementsByTagName('img')[0];
var labEl = currentPositionEl.getElementsByTagName('a')[0];
var names = nameEl.textContent.toLowerCase().replace(/\,/g, '').replace(/\./g, '').trim().replace(/ph\s*d/, '').replace('md', '').trim().split(' ');
processed.push(
`
echo "---
name: ${nameEl.textContent.trim()}
position: ${positionEl.textContent.trim()}
currentPosition:
${currentPosition.map(x => ` - ${x}
`).join('')}
${!emailEl ? '' :
`email: ${emailEl.src.split('text=')[1].split('&')[0].replace('(at)', '@')}`
}
${!labEl ? '' :
`lab:
- url: ${labEl.href}
- text: ${labEl.textContent.slice(1, -1)}`
}---" > ${names[names.length - 1]}.${names[0]}.md`
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment