Skip to content

Instantly share code, notes, and snippets.

@styfle
styfle / html-table-to-markdown-table.js
Created September 19, 2016 20:44
Convert an HTML Table in the DOM to a Markdown Table as a string
function toMarkdown(doc) {
let s = '| ';
let thead = doc.querySelector('thead');
let headcells = thead.querySelectorAll('td');
for (let i = 0; i < headcells.length; i++) {
let cell = headcells[i];
s += cell.textContent.trim() + ' | ';
}