Skip to content

Instantly share code, notes, and snippets.

@carlosvega20
Last active March 12, 2022 20:47
Show Gist options
  • Save carlosvega20/79b78e50bcc83b3bd23b52452880c7e0 to your computer and use it in GitHub Desktop.
Save carlosvega20/79b78e50bcc83b3bd23b52452880c7e0 to your computer and use it in GitHub Desktop.
Excel markdown table | Notable.app Plugin
const require = (url) => {
const head = document.getElementsByTagName('head')[0];
const script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
head.appendChild(script);
}
require("https://cdn.jsdelivr.net/npm/hyperformula/dist/hyperformula.full.min.js");
$(document).on ( 'preview:render', ()=>{
const tables = document.querySelectorAll('table');
if (!tables.length) return
const sheets = [...tables].reduce((prevtable, table, TI) => ({
...prevtable,
['table'+TI]: [...table.rows].map((row, ri) => [...row.cells].map((cell, ci) => {
if (cell.innerHTML.match(/^=/g)) cell.setAttribute('data-table', JSON.stringify({row: ri, col: ci, sheet: TI}))
return cell.innerHTML;
}))
}), {});
const hfInstance = HyperFormula.buildFromSheets(sheets, {licenseKey: 'gpl-v3'});
const cellsToCalculate = document.querySelectorAll('[data-table]');
cellsToCalculate.forEach(el => el.innerHTML = hfInstance.getCellValue({ ...JSON.parse(el.getAttribute('data-table')) }))
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment