@md-plugins/md-plugin-codeblocks 0.1.0-alpha.25 → 0.1.0-alpha.27

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/README.md CHANGED
@@ -16,12 +16,12 @@ A **Markdown-It** plugin that enhances code block rendering by providing syntax
16
16
  Install the plugin via your preferred package manager:
17
17
 
18
18
  ```bash
19
- # With npm:
20
- npm install @md-plugins/md-plugin-codeblocks
21
- # Or with Yarn:
22
- yarn add @md-plugins/md-plugin-codeblocks
23
- # Or with pnpm:
19
+ # with pnpm:
24
20
  pnpm add @md-plugins/md-plugin-codeblocks
21
+ # with Yarn:
22
+ yarn add @md-plugins/md-plugin-codeblocks
23
+ # with npm:
24
+ npm install @md-plugins/md-plugin-codeblocks
25
25
  ```
26
26
 
27
27
  ## Usage
package/dist/index.mjs CHANGED
@@ -57,7 +57,7 @@ const codeblocksPlugin = (md, {
57
57
  },
58
58
  content: []
59
59
  };
60
- } else if (currentTabName !== null) {
60
+ } else if (currentTabName) {
61
61
  tabMap[currentTabName].content.push(line);
62
62
  }
63
63
  }
@@ -102,8 +102,10 @@ const codeblocksPlugin = (md, {
102
102
  const hasRemOrAdd = props.rem.length !== 0 || props.add.length !== 0;
103
103
  for (const type of magicCommentList) {
104
104
  const target = props[type];
105
+ if (target === undefined || target.length === 0) continue;
105
106
  for (const value of target) {
106
107
  let [from, to] = value.split("-").map((i) => parseInt(i, 10));
108
+ if (from === undefined) continue;
107
109
  if (to === undefined) to = from;
108
110
  for (let i = from; i <= to; i++) {
109
111
  acc[i - 1].classList.push(`line-${type}`);
@@ -118,6 +120,7 @@ const codeblocksPlugin = (md, {
118
120
  }
119
121
  hasRemOrAdd === true && lines.forEach((_, lineIndex) => {
120
122
  const target = acc[lineIndex];
123
+ if (target === undefined) return;
121
124
  target.prefix.push(
122
125
  target.classList.includes(`line-add`) === true ? "+" : target.classList.includes(`line-rem`) === true ? "-" : " "
123
126
  );
@@ -136,6 +139,7 @@ const codeblocksPlugin = (md, {
136
139
  }
137
140
  const html = prism.highlight(content, prism.languages[lang], lang).split("\n").map((line, lineIndex) => {
138
141
  const target = lineList[lineIndex];
142
+ if (target === undefined) return line;
139
143
  let lineHtml = "";
140
144
  lineHtml += target.classList.length !== 0 ? `<span class="c-line ${target.classList.join(" ")}"></span>` : "";
141
145
  lineHtml += target.prefix.length !== 0 ? `<span class="c-lpref">${target.prefix.join(" ")}</span>` : "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@md-plugins/md-plugin-codeblocks",
3
- "version": "0.1.0-alpha.25",
3
+ "version": "0.1.0-alpha.27",
4
4
  "description": "A markdown-it plugin for code blocks.",
5
5
  "keywords": [
6
6
  "markdown-it",
@@ -40,7 +40,7 @@
40
40
  "prismjs": "^1.29.0",
41
41
  "@types/markdown-it": "^14.1.2",
42
42
  "@types/prismjs": "^1.26.5",
43
- "@md-plugins/shared": "0.1.0-alpha.25"
43
+ "@md-plugins/shared": "0.1.0-alpha.27"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "markdown-it": "^14.1.0",