Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/scss/_common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
}
}

table {
.yfm-table {
color: var(--yfm-color-table);

display: inline-block;
Expand Down
16 changes: 16 additions & 0 deletions src/transform/plugins/table/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {MarkdownItPluginCb} from '../typings';
import {AttrsParser} from './attrs';

const pluginName = 'yfm_table';
const tableTokenTypes = ['table_open', 'yfm_table_open'];
const pipeChar = 0x7c; // |
const apostropheChar = 0x60; // `
const hashChar = 0x23; // #
Expand Down Expand Up @@ -500,6 +501,21 @@ const yfmTable: MarkdownItPluginCb = (md) => {
return true;
},
);

function applyTableClassRule(tokenType: string) {
const existingRenderer =
md.renderer.rules[tokenType] || md.renderer.renderToken.bind(md.renderer);

md.renderer.rules[tokenType] = (tokens, idx, options, env, renderer) => {
const token = tokens[idx];

token.attrSet('class', [token.attrGet('class'), 'yfm-table'].filter(Boolean).join(' '));

return existingRenderer(tokens, idx, options, env, renderer);
};
}

tableTokenTypes.forEach(applyTableClassRule);
};

export = yfmTable;