import cheerio from 'cheerio'; import { FrontMatter, PluginContext } from './Plugin.js'; import { markdownIt as md } from '../lib/markdown-it/index.js'; const CSS_FILE_NAME = 'dataTableAssets/datatables.min.css'; const CSS_ADDITIONAL = 'dataTableAssets/datatables-additional.css'; const JS_FILE_NAME = 'dataTableAssets/datatables.min.js'; const initScript = ` `; const getLinks = () => [ ``, ``, ]; const getScripts = () => [``, initScript]; const postRender = (pluginContext: PluginContext, frontmatter: FrontMatter, content: string) => { const $ = cheerio.load(content); $('d-table').each((index: number, node: cheerio.Element) => { const $node = $(node); const html = $node.html(); if (html == null) { return; } const isSortable = $node.attr('sortable') !== undefined; const isSearchable = $node.attr('searchable') !== undefined; let tableClass: string = ''; if (isSortable && isSearchable) { tableClass = 'sortable-searchable-table'; } else if (isSortable) { tableClass = 'sortable-table'; } else if (isSearchable) { tableClass = 'searchable-table'; } const renderedTable = md.render(html); const $renderedTable = $(renderedTable); $renderedTable.find('table') .addClass(tableClass) .attr('id', `datatable-${index}`); $node.replaceWith($renderedTable); }); return $.html(); }; export { postRender, getScripts, getLinks, };