@md-plugins/md-plugin-link 0.1.0-alpha.27 → 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 +27 -10
  2. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -1,16 +1,33 @@
1
- const linkPlugin = (md, {
2
- linkTag = "MarkdownLink",
3
- linkToKeyword = "to",
4
- pageScript = 'import MarkdownLink from "src/.q-press/components/MarkdownLink.vue"'
5
- } = {}) => {
6
- md.renderer.rules.link_open = (tokens, idx, options, env, self) => {
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_LINK_PLUGIN_OPTIONS = {
9
+ linkTag: "MarkdownLink",
10
+ linkToKeyword: "to",
11
+ pageScript: 'import MarkdownLink from "src/.q-press/components/MarkdownLink.vue"'
12
+ };
13
+ const linkPlugin = (md, options) => {
14
+ const {
15
+ linkTag = "MarkdownLink",
16
+ linkToKeyword = "to",
17
+ pageScript
18
+ } = resolvePluginOptions(
19
+ options,
20
+ "linkPlugin",
21
+ DEFAULT_LINK_PLUGIN_OPTIONS
22
+ );
23
+ md.renderer.rules.link_open = (tokens, idx, options2, env, self) => {
7
24
  const token = tokens[idx];
8
25
  if (!token) {
9
26
  return "";
10
27
  }
11
28
  const hrefIndex = token.attrIndex("href");
12
29
  if (hrefIndex < 0 || !token.attrs) {
13
- return self.renderToken(tokens, idx, options);
30
+ return self.renderToken(tokens, idx, options2);
14
31
  }
15
32
  const link = token.attrs[hrefIndex];
16
33
  const url = link[1];
@@ -21,9 +38,9 @@ const linkPlugin = (md, {
21
38
  env.pageScripts = env.pageScripts || /* @__PURE__ */ new Set();
22
39
  env.pageScripts.add(pageScript);
23
40
  }
24
- return self.renderToken(tokens, idx, options);
41
+ return self.renderToken(tokens, idx, options2);
25
42
  };
26
- md.renderer.rules.link_close = (tokens, idx, options, env, self) => {
43
+ md.renderer.rules.link_close = (tokens, idx, options2, env, self) => {
27
44
  const token = tokens[idx];
28
45
  if (!token) {
29
46
  return "";
@@ -36,7 +53,7 @@ const linkPlugin = (md, {
36
53
  if (openingToken && openingToken.tag) {
37
54
  token.tag = openingToken.tag;
38
55
  }
39
- return self.renderToken(tokens, idx, options);
56
+ return self.renderToken(tokens, idx, options2);
40
57
  };
41
58
  };
42
59
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@md-plugins/md-plugin-link",
3
- "version": "0.1.0-alpha.27",
3
+ "version": "0.1.0-alpha.29",
4
4
  "description": "A markdown-it plugin for handling links.",
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.27"
38
+ "@md-plugins/shared": "0.1.0-alpha.29"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "markdown-it": "^14.1.0"