@md-plugins/md-plugin-table 0.1.0-alpha.28 → 0.1.0-alpha.29

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.
Files changed (2) hide show
  1. package/dist/index.mjs +35 -17
  2. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -1,28 +1,46 @@
1
- const tablePlugin = (md, {
2
- tableClass = "markdown-table",
3
- tableHeaderClass = "text-left",
4
- tableRowClass = "",
5
- tableCellClass = "",
6
- tableToken = "q-markup-table",
7
- tableAttributes = []
8
- } = {}) => {
1
+ function resolvePluginOptions(options, key, defaults) {
2
+ if (options && typeof options === "object" && key in options) {
3
+ return { ...defaults, ...options[key] };
4
+ }
5
+ return { ...defaults, ...options };
6
+ }
7
+
8
+ const DEFAULT_TABLE_PLUGIN_OPTIONS = {
9
+ tableClass: "markdown-table",
10
+ tableHeaderClass: "text-left",
11
+ tableRowClass: "",
12
+ tableCellClass: "",
13
+ tableToken: "q-markup-table",
14
+ tableAttributes: []
15
+ };
16
+ const tablePlugin = (md, options) => {
17
+ const {
18
+ tableClass = DEFAULT_TABLE_PLUGIN_OPTIONS.tableClass,
19
+ tableHeaderClass = DEFAULT_TABLE_PLUGIN_OPTIONS.tableHeaderClass,
20
+ tableRowClass = DEFAULT_TABLE_PLUGIN_OPTIONS.tableRowClass,
21
+ tableCellClass = DEFAULT_TABLE_PLUGIN_OPTIONS.tableCellClass,
22
+ tableToken = DEFAULT_TABLE_PLUGIN_OPTIONS.tableToken,
23
+ tableAttributes = DEFAULT_TABLE_PLUGIN_OPTIONS.tableAttributes
24
+ } = resolvePluginOptions(
25
+ options,
26
+ "tablePlugin",
27
+ DEFAULT_TABLE_PLUGIN_OPTIONS
28
+ );
9
29
  const render = md.renderer.render.bind(md.renderer);
10
- md.renderer.render = (tokens, options, env) => {
30
+ md.renderer.render = (tokens, options2, env) => {
11
31
  for (let i = 0; i < tokens.length; i++) {
12
32
  const token = tokens[i];
13
- if (!token) {
14
- continue;
15
- }
33
+ if (!token) continue;
16
34
  switch (token.type) {
17
35
  case "table_open":
18
- token.tag = tableToken;
19
- token.attrSet("class", tableClass);
20
- for (const [attrName, attrValue] of tableAttributes) {
36
+ token.tag = tableToken ?? DEFAULT_TABLE_PLUGIN_OPTIONS.tableToken;
37
+ token.attrSet("class", tableClass ?? DEFAULT_TABLE_PLUGIN_OPTIONS.tableClass);
38
+ for (const [attrName, attrValue] of tableAttributes ?? []) {
21
39
  token.attrSet(attrName, String(attrValue));
22
40
  }
23
41
  break;
24
42
  case "table_close":
25
- token.tag = tableToken;
43
+ token.tag = tableToken ?? DEFAULT_TABLE_PLUGIN_OPTIONS.tableToken;
26
44
  break;
27
45
  case "th_open":
28
46
  if (tableHeaderClass) {
@@ -41,7 +59,7 @@ const tablePlugin = (md, {
41
59
  break;
42
60
  }
43
61
  }
44
- return render(tokens, options, env);
62
+ return render(tokens, options2, env);
45
63
  };
46
64
  };
47
65
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@md-plugins/md-plugin-table",
3
- "version": "0.1.0-alpha.28",
3
+ "version": "0.1.0-alpha.29",
4
4
  "description": "A markdown-it plugin for handling tables with custom tag and styles.",
5
5
  "keywords": [
6
6
  "markdown-it",
@@ -35,7 +35,7 @@
35
35
  "devDependencies": {
36
36
  "markdown-it": "^14.1.0",
37
37
  "@types/markdown-it": "^14.1.2",
38
- "@md-plugins/shared": "0.1.0-alpha.28"
38
+ "@md-plugins/shared": "0.1.0-alpha.29"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "markdown-it": "^14.1.0"