@md-plugins/md-plugin-table 0.1.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +21 -0
- package/README.md +158 -0
- package/dist/index.d.mts +44 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.mjs +48 -0
- package/package.json +48 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-present, Jeff Galbraith
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# @md-plugins/md-plugin-table
|
|
2
|
+
|
|
3
|
+
A **Markdown-It** plugin that customizes the rendering of tables in Markdown. This plugin allows developers to style and structure tables with additional attributes, making them more visually appealing and compatible with design systems.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Adds customizable CSS classes to `<table>`, `<thead>`, `<tbody>`, `<tr>`, `<th>`, and `<td>` elements.
|
|
8
|
+
- Supports custom attributes for `<table>` elements.
|
|
9
|
+
- Replaces the default `<table>` tag with a configurable custom tag (e.g., `q-markup-table`).
|
|
10
|
+
- Flexible configuration for adapting to different frameworks or design systems like Quasar.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
Install the plugin via your preferred package manager:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
# With npm:
|
|
18
|
+
npm install @md-plugins/md-plugin-table
|
|
19
|
+
# Or with Yarn:
|
|
20
|
+
yarn add @md-plugins/md-plugin-table
|
|
21
|
+
# Or with pnpm:
|
|
22
|
+
pnpm add @md-plugins/md-plugin-table
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
### Basic Setup
|
|
28
|
+
|
|
29
|
+
```js
|
|
30
|
+
import MarkdownIt from 'markdown-it';
|
|
31
|
+
import { tablePlugin } from '@md-plugins/md-plugin-table';
|
|
32
|
+
|
|
33
|
+
const md = new MarkdownIt();
|
|
34
|
+
md.use(tablePlugin, {
|
|
35
|
+
tableClass: 'custom-table-class',
|
|
36
|
+
tableToken: 'custom-table-tag',
|
|
37
|
+
tableAttributes: [
|
|
38
|
+
[':wrap-cells', 'true'],
|
|
39
|
+
[':flat', 'true'],
|
|
40
|
+
],
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const markdownContent = `
|
|
44
|
+
| Header 1 | Header 2 |
|
|
45
|
+
|----------|----------|
|
|
46
|
+
| Cell 1 | Cell 2 |
|
|
47
|
+
| Cell 3 | Cell 4 |
|
|
48
|
+
`;
|
|
49
|
+
|
|
50
|
+
const renderedOutput = md.render(markdownContent);
|
|
51
|
+
|
|
52
|
+
console.log('Rendered Output:', renderedOutput);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Example Output
|
|
56
|
+
|
|
57
|
+
For the example above, the plugin produces the following output:
|
|
58
|
+
|
|
59
|
+
```html
|
|
60
|
+
<custom-table-tag class="custom-table-class" :wrap-cells="true" :flat="true">
|
|
61
|
+
<thead>
|
|
62
|
+
<tr>
|
|
63
|
+
<th>Header 1</th>
|
|
64
|
+
<th>Header 2</th>
|
|
65
|
+
</tr>
|
|
66
|
+
</thead>
|
|
67
|
+
<tbody>
|
|
68
|
+
<tr>
|
|
69
|
+
<td>Cell 1</td>
|
|
70
|
+
<td>Cell 2</td>
|
|
71
|
+
</tr>
|
|
72
|
+
<tr>
|
|
73
|
+
<td>Cell 3</td>
|
|
74
|
+
<td>Cell 4</td>
|
|
75
|
+
</tr>
|
|
76
|
+
</tbody>
|
|
77
|
+
</custom-table-tag>
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Options
|
|
81
|
+
|
|
82
|
+
The `md-plugin-table` plugin supports the following options:
|
|
83
|
+
|
|
84
|
+
| Option | Type | Default | Description |
|
|
85
|
+
| ---------------- | ------ | --------------------- | -------------------------------------------------- |
|
|
86
|
+
| tableClass | string | 'markdown-page-table' | CSS class for the `<table>` or custom tag. |
|
|
87
|
+
| tableToken | string | 'q-markup-table' | Tag name to replace the default `<table>` tag. |
|
|
88
|
+
| tableAttributes | Array | [] | Array of attribute name-value pairs for the table. |
|
|
89
|
+
| tableHeaderClass | string | 'text-left' | CSS class for `<th>` elements. |
|
|
90
|
+
| tableRowClass | string | '' | CSS class for `<tr>` elements. |
|
|
91
|
+
| tableCellClass | string | '' | CSS class for `<td>` elements. |
|
|
92
|
+
|
|
93
|
+
## Advanced Usage
|
|
94
|
+
|
|
95
|
+
### Custom Styling
|
|
96
|
+
|
|
97
|
+
Apply custom styling to tables by defining your own classes:
|
|
98
|
+
|
|
99
|
+
```js
|
|
100
|
+
md.use(tablePlugin, {
|
|
101
|
+
tableClass: 'custom-table',
|
|
102
|
+
tableHeaderClass: 'custom-header',
|
|
103
|
+
tableRowClass: 'custom-row',
|
|
104
|
+
tableCellClass: 'custom-cell',
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Renered output:
|
|
109
|
+
|
|
110
|
+
```html
|
|
111
|
+
<q-markup-table class="custom-table">
|
|
112
|
+
<thead>
|
|
113
|
+
<tr class="custom-row">
|
|
114
|
+
<th class="custom-header">Header 1</th>
|
|
115
|
+
<th class="custom-header">Header 2</th>
|
|
116
|
+
</tr>
|
|
117
|
+
</thead>
|
|
118
|
+
<tbody>
|
|
119
|
+
<tr class="custom-row">
|
|
120
|
+
<td class="custom-cell">Cell 1</td>
|
|
121
|
+
<td class="custom-cell">Cell 2</td>
|
|
122
|
+
</tr>
|
|
123
|
+
</tbody>
|
|
124
|
+
</q-markup-table>
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Custom Attributes
|
|
128
|
+
|
|
129
|
+
Add attributes for frameworks like Quasar:
|
|
130
|
+
|
|
131
|
+
```js
|
|
132
|
+
md.use(tablePlugin, {
|
|
133
|
+
tableAttributes: [
|
|
134
|
+
[':bordered', 'true'],
|
|
135
|
+
[':flat', 'true'],
|
|
136
|
+
],
|
|
137
|
+
});
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Rendered output:
|
|
141
|
+
|
|
142
|
+
```html
|
|
143
|
+
<q-markup-table class="markdown-page-table" :bordered="true" :flat="true">
|
|
144
|
+
...
|
|
145
|
+
</q-markup-table>
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Testing
|
|
149
|
+
|
|
150
|
+
Run the unit tests to ensure the plugin behaves as expected:
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
pnpm test
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## License
|
|
157
|
+
|
|
158
|
+
This project is licensed under the MIT License. See the [LICENSE](LICENSE.md) file for details.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { PluginWithOptions } from 'markdown-it';
|
|
2
|
+
|
|
3
|
+
interface TablePluginOptions {
|
|
4
|
+
/**
|
|
5
|
+
* The class for the table
|
|
6
|
+
*
|
|
7
|
+
* @default 'markdown-page-table'
|
|
8
|
+
*/
|
|
9
|
+
tableClass?: string;
|
|
10
|
+
/**
|
|
11
|
+
* The class for the table header
|
|
12
|
+
*
|
|
13
|
+
* @default 'text-left'
|
|
14
|
+
*/
|
|
15
|
+
tableHeaderClass?: string;
|
|
16
|
+
/**
|
|
17
|
+
* The class for the table row
|
|
18
|
+
*
|
|
19
|
+
* @default ''
|
|
20
|
+
*/
|
|
21
|
+
tableRowClass?: string;
|
|
22
|
+
/**
|
|
23
|
+
* The class for the table cell
|
|
24
|
+
*
|
|
25
|
+
* @default ''
|
|
26
|
+
*/
|
|
27
|
+
tableCellClass?: string;
|
|
28
|
+
/**
|
|
29
|
+
* The token for the table
|
|
30
|
+
*
|
|
31
|
+
* @default 'q-markup-table' (replaces 'table')
|
|
32
|
+
*/
|
|
33
|
+
tableToken?: string;
|
|
34
|
+
/**
|
|
35
|
+
* The attributes for the table
|
|
36
|
+
*
|
|
37
|
+
* @default [ [':wrap-cells', 'true'],[':flat', 'true'],[':bordered', 'true'] ]
|
|
38
|
+
*/
|
|
39
|
+
tableAttributes?: [string, any][];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
declare const tablePlugin: PluginWithOptions<TablePluginOptions>;
|
|
43
|
+
|
|
44
|
+
export { type TablePluginOptions, tablePlugin };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { PluginWithOptions } from 'markdown-it';
|
|
2
|
+
|
|
3
|
+
interface TablePluginOptions {
|
|
4
|
+
/**
|
|
5
|
+
* The class for the table
|
|
6
|
+
*
|
|
7
|
+
* @default 'markdown-page-table'
|
|
8
|
+
*/
|
|
9
|
+
tableClass?: string;
|
|
10
|
+
/**
|
|
11
|
+
* The class for the table header
|
|
12
|
+
*
|
|
13
|
+
* @default 'text-left'
|
|
14
|
+
*/
|
|
15
|
+
tableHeaderClass?: string;
|
|
16
|
+
/**
|
|
17
|
+
* The class for the table row
|
|
18
|
+
*
|
|
19
|
+
* @default ''
|
|
20
|
+
*/
|
|
21
|
+
tableRowClass?: string;
|
|
22
|
+
/**
|
|
23
|
+
* The class for the table cell
|
|
24
|
+
*
|
|
25
|
+
* @default ''
|
|
26
|
+
*/
|
|
27
|
+
tableCellClass?: string;
|
|
28
|
+
/**
|
|
29
|
+
* The token for the table
|
|
30
|
+
*
|
|
31
|
+
* @default 'q-markup-table' (replaces 'table')
|
|
32
|
+
*/
|
|
33
|
+
tableToken?: string;
|
|
34
|
+
/**
|
|
35
|
+
* The attributes for the table
|
|
36
|
+
*
|
|
37
|
+
* @default [ [':wrap-cells', 'true'],[':flat', 'true'],[':bordered', 'true'] ]
|
|
38
|
+
*/
|
|
39
|
+
tableAttributes?: [string, any][];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
declare const tablePlugin: PluginWithOptions<TablePluginOptions>;
|
|
43
|
+
|
|
44
|
+
export { type TablePluginOptions, tablePlugin };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const tablePlugin = (md, {
|
|
2
|
+
tableClass = "markdown-page-table",
|
|
3
|
+
tableHeaderClass = "text-left",
|
|
4
|
+
tableRowClass = "",
|
|
5
|
+
tableCellClass = "",
|
|
6
|
+
tableToken = "q-markup-table",
|
|
7
|
+
tableAttributes = []
|
|
8
|
+
} = {}) => {
|
|
9
|
+
const render = md.renderer.render.bind(md.renderer);
|
|
10
|
+
md.renderer.render = (tokens, options, env) => {
|
|
11
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
12
|
+
const token = tokens[i];
|
|
13
|
+
if (!token) {
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
switch (token.type) {
|
|
17
|
+
case "table_open":
|
|
18
|
+
token.tag = tableToken;
|
|
19
|
+
token.attrSet("class", tableClass);
|
|
20
|
+
for (const [attrName, attrValue] of tableAttributes) {
|
|
21
|
+
token.attrSet(attrName, String(attrValue));
|
|
22
|
+
}
|
|
23
|
+
break;
|
|
24
|
+
case "table_close":
|
|
25
|
+
token.tag = tableToken;
|
|
26
|
+
break;
|
|
27
|
+
case "th_open":
|
|
28
|
+
if (tableHeaderClass) {
|
|
29
|
+
token.attrSet("class", tableHeaderClass);
|
|
30
|
+
}
|
|
31
|
+
break;
|
|
32
|
+
case "tr_open":
|
|
33
|
+
if (tableRowClass) {
|
|
34
|
+
token.attrSet("class", tableRowClass);
|
|
35
|
+
}
|
|
36
|
+
break;
|
|
37
|
+
case "td_open":
|
|
38
|
+
if (tableCellClass) {
|
|
39
|
+
token.attrSet("class", tableCellClass);
|
|
40
|
+
}
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return render(tokens, options, env);
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export { tablePlugin };
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@md-plugins/md-plugin-table",
|
|
3
|
+
"version": "0.1.0-alpha.1",
|
|
4
|
+
"description": "A markdown-it plugin for handling tables with custom tag and styles.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"markdown-it",
|
|
7
|
+
"quasarframework",
|
|
8
|
+
"vue",
|
|
9
|
+
"types"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://github.com/md-plugins",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/md-plugins/md-plugins/issues"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/md-plugins/md-plugins.git"
|
|
18
|
+
},
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"author": "hawkeye64 <galbraith64@gmail.com>",
|
|
21
|
+
"type": "module",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"import": {
|
|
25
|
+
"types": "./dist/index.d.mts",
|
|
26
|
+
"default": "./dist/index.mjs"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"module": "./dist/index.mjs",
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"files": [
|
|
33
|
+
"./dist"
|
|
34
|
+
],
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@types/markdown-it": "^14.1.2",
|
|
37
|
+
"markdown-it": "^14.1.0",
|
|
38
|
+
"@md-plugins/shared": "0.1.0-alpha.1"
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "unbuild",
|
|
45
|
+
"clean": "rm -rf dist",
|
|
46
|
+
"test": "vitest"
|
|
47
|
+
}
|
|
48
|
+
}
|