vitepress-theme-element-plus 0.0.6 → 0.0.7

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/dist/index.d.mts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { mdExternalLinkIcon } from "./markdown/plugins/external-link-icon.mjs";
2
2
  import { mdTableWrapper } from "./markdown/plugins/table-wrapper.mjs";
3
3
  import { mdTag } from "./markdown/plugins/tag.mjs";
4
+ import { mdElementPlusTaskList } from "./markdown/plugins/task-list.mjs";
4
5
  import { mdTooltip } from "./markdown/plugins/tooltip.mjs";
5
- export { mdExternalLinkIcon, mdTableWrapper, mdTag, mdTooltip };
6
+ export { mdExternalLinkIcon, mdTableWrapper, mdTag, mdElementPlusTaskList as mdTaskList, mdTooltip };
package/dist/index.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import mdExternalLinkIcon from "./markdown/plugins/external-link-icon.mjs";
2
2
  import mdTableWrapper from "./markdown/plugins/table-wrapper.mjs";
3
3
  import mdTag from "./markdown/plugins/tag.mjs";
4
+ import { mdElementPlusTaskList } from "./markdown/plugins/task-list.mjs";
4
5
  import mdTooltip from "./markdown/plugins/tooltip.mjs";
5
6
 
6
- export { mdExternalLinkIcon, mdTableWrapper, mdTag, mdTooltip };
7
+ export { mdExternalLinkIcon, mdTableWrapper, mdTag, mdElementPlusTaskList as mdTaskList, mdTooltip };
@@ -0,0 +1,13 @@
1
+ import { PluginWithOptions } from "markdown-it";
2
+
3
+ //#region node/markdown/plugins/task-list.d.ts
4
+ interface ElementPlusTaskListOptions {
5
+ disabled?: boolean;
6
+ itemClass?: string;
7
+ listClass?: string;
8
+ checkboxClass?: string;
9
+ labelClass?: string;
10
+ }
11
+ declare const mdElementPlusTaskList: PluginWithOptions<ElementPlusTaskListOptions>;
12
+ //#endregion
13
+ export { mdElementPlusTaskList };
@@ -0,0 +1,51 @@
1
+ //#region node/markdown/plugins/task-list.ts
2
+ function startsWithTask(token) {
3
+ return token.type === "inline" && /^\[[x \u00A0]\][ \u00A0]/i.test(token.content);
4
+ }
5
+ function isTaskListItem(tokens, index) {
6
+ return startsWithTask(tokens[index]) && tokens[index - 1]?.type === "paragraph_open" && tokens[index - 2]?.type === "list_item_open";
7
+ }
8
+ function html(state, content) {
9
+ const token = new state.Token("html_inline", "", 0);
10
+ token.content = content;
11
+ return token;
12
+ }
13
+ function addClass(token, className) {
14
+ if (!token) return;
15
+ const current = token.attrGet("class");
16
+ if (!current) {
17
+ token.attrSet("class", className);
18
+ return;
19
+ }
20
+ if (current.split(/\s+/).includes(className)) return;
21
+ token.attrSet("class", `${current} ${className}`);
22
+ }
23
+ const mdElementPlusTaskList = (md, { disabled = true, itemClass = "ep-task-list__item", listClass = "ep-task-list", checkboxClass = "ep-task-list__checkbox", labelClass = "ep-task-list__label" } = {}) => {
24
+ md.core.ruler.after("inline", "ep-task-list", (state) => {
25
+ const { tokens, env } = state;
26
+ env.epTaskId ||= 0;
27
+ for (let i = 2; i < tokens.length; i++) {
28
+ if (!isTaskListItem(tokens, i)) continue;
29
+ const inlineToken = tokens[i];
30
+ const listItemToken = tokens[i - 2];
31
+ const parentListToken = tokens.findLast((token, idx) => idx < i - 2 && token.level === listItemToken.level - 1 && token.type.endsWith("list_open"));
32
+ addClass(listItemToken, itemClass);
33
+ addClass(parentListToken, listClass);
34
+ const textToken = inlineToken.children?.find((child) => child.type === "text");
35
+ if (!textToken) continue;
36
+ const checked = /^\[x\]/i.test(textToken.content);
37
+ textToken.content = textToken.content.replace(/^\[[x \u00A0]\][ \u00A0]?/i, "");
38
+ const id = `ep-task-${env.epTaskId++}`;
39
+ const input = `<span class="el-checkbox__input${checked ? " is-checked" : ""}${disabled ? " is-disabled" : ""}">
40
+ <span class="el-checkbox__inner"></span>
41
+ <input id="${id}" class="el-checkbox__original" type="checkbox" ${checked ? "checked" : ""} ${disabled ? "disabled" : ""} aria-checked="${checked ? "true" : "false"}" role="presentation">
42
+ </span>`;
43
+ inlineToken.children.unshift(html(state, `<label class="el-checkbox ${checkboxClass}" for="${id}" role="checkbox" aria-checked="${checked ? "true" : "false"}">`), html(state, `${input}<span class="el-checkbox__label ${labelClass}">`));
44
+ inlineToken.children.push(html(state, "</span></label>"));
45
+ }
46
+ return true;
47
+ });
48
+ };
49
+
50
+ //#endregion
51
+ export { mdElementPlusTaskList };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vitepress-theme-element-plus",
3
3
  "type": "module",
4
- "version": "0.0.6",
4
+ "version": "0.0.7",
5
5
  "description": "A VitePress theme for Element Plus",
6
6
  "author": "Hezhengxu",
7
7
  "license": "MIT",
@@ -213,6 +213,14 @@
213
213
  list-style: auto
214
214
  }
215
215
 
216
+ .ep-task-list {
217
+ padding-left: 0;
218
+
219
+ &>li {
220
+ list-style: none;
221
+ }
222
+ }
223
+
216
224
  hr {
217
225
  margin-top: 20px;
218
226
  margin-bottom: 20px;