From ca9703fb81eba4efd7e94caa717a3afdf2299416 Mon Sep 17 00:00:00 2001 From: Tim-Siu Date: Sat, 9 Mar 2024 12:13:20 +0800 Subject: [PATCH] Add SortableTable plugin --- packages/core/src/plugins/SortableTable.ts | 81 ++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 packages/core/src/plugins/SortableTable.ts diff --git a/packages/core/src/plugins/SortableTable.ts b/packages/core/src/plugins/SortableTable.ts new file mode 100644 index 0000000000..1c1259c885 --- /dev/null +++ b/packages/core/src/plugins/SortableTable.ts @@ -0,0 +1,81 @@ +import { PluginContext } from './Plugin'; +import { MbNode } from '../utils/node'; + +const cheerio = require('cheerio'); +const constant = require('lodash/constant'); + +const md = require('../lib/markdown-it'); + +// fix table style +md.renderer.rules.table_open = constant( + '
' + + ''); +md.renderer.rules.table_close = constant('
'); + +const sortableTableCss = ` + .sortable-table th { + cursor: pointer; + } + + .sortable-table th::after { + content: " \\2195"; /* Up/Down arrow */ + } + + .sortable-table th.th-sort-asc::after { + content: " \\2191"; /* Ascending arrow */ + } + .sortable-table th.th-sort-desc::after { + content: " \\2193"; /* Descending arrow */ + } +`; + +const sortableTableJs = ` +`; + +export = { + getScripts: () => [sortableTableJs], + processNode: (pluginContext: PluginContext, node: MbNode) => { + // Check if the node needs to be processed + if (node.name !== 'sortable') { + return; + } + const $ = cheerio(node); + $.replaceWith(md.render($.text())); + $.append(``); + }, +};