2024-05-30 09:34:52 +02:00
|
|
|
import type * as MarkdownIt from 'markdown-it';
|
|
|
|
import type * as Renderer from 'markdown-it/lib/renderer';
|
|
|
|
import defaultRule from './utils/defaultRule';
|
2024-03-25 13:27:48 +02:00
|
|
|
|
|
|
|
export default {
|
|
|
|
// Make table horizontally scrollable by give table a div parent, so the width of the table is limited to the screen width.
|
|
|
|
// see https://github.com/laurent22/joplin/pull/10161
|
|
|
|
plugin: (markdownIt: MarkdownIt) => {
|
2024-05-30 09:34:52 +02:00
|
|
|
const defaultTableOpen = defaultRule(markdownIt, 'table_open');
|
|
|
|
markdownIt.renderer.rules.table_open = function(tokens: MarkdownIt.Token[], idx: number, options: MarkdownIt.Options, env: unknown, renderer: Renderer) {
|
|
|
|
const current = defaultTableOpen(tokens, idx, options, env, renderer);
|
2024-03-25 13:27:48 +02:00
|
|
|
// joplin-table-wrapper css is set in packages/renderer/noteStyle.ts
|
|
|
|
return `<div class="joplin-table-wrapper">\n${current}`;
|
|
|
|
};
|
2024-05-30 09:34:52 +02:00
|
|
|
|
|
|
|
const defaultTableClose = defaultRule(markdownIt, 'table_close');
|
|
|
|
markdownIt.renderer.rules.table_close = function(tokens: MarkdownIt.Token[], idx: number, options: MarkdownIt.Options, env: unknown, renderer: Renderer) {
|
|
|
|
const current = defaultTableClose(tokens, idx, options, env, renderer);
|
2024-03-25 13:27:48 +02:00
|
|
|
return `${current}</div>\n`;
|
|
|
|
};
|
|
|
|
},
|
|
|
|
};
|