@mdit/plugin-tasklist 0.1.0-alpha.0
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 +23 -0
- package/README.md +16 -0
- package/lib/index.cjs +2 -0
- package/lib/index.cjs.map +1 -0
- package/lib/index.d.cts +32 -0
- package/lib/index.d.mts +32 -0
- package/lib/index.d.ts +32 -0
- package/lib/index.mjs +2 -0
- package/lib/index.mjs.map +1 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016, Revin Guillen
|
|
4
|
+
Modified code Copyright (c) 2016, linsir, MIT License
|
|
5
|
+
Copyright (C) 2022 - PRESENT by MrHope
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in
|
|
15
|
+
all copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# @mdit/plugin-tasklist
|
|
2
|
+
|
|
3
|
+
[  ](https://www.npmjs.com/package/@mdit/plugin-tasklist)
|
|
4
|
+
|
|
5
|
+
tasklist plugin for MarkdownIt.
|
|
6
|
+
|
|
7
|
+
## Install / 安装
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# pnpm
|
|
11
|
+
pnpm add -D @mdit/plugin-tasklist
|
|
12
|
+
# npm
|
|
13
|
+
npm i -D @mdit/plugin-tasklist
|
|
14
|
+
# yarn
|
|
15
|
+
yarn add -D @mdit/plugin-tasklist
|
|
16
|
+
```
|
package/lib/index.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var a=require("markdown-it/lib/token.js");const r=(t,s,n)=>{const e=t.attrIndex(s),l=[s,n];e<0?t.attrPush(l):t.attrs[e]=l},c=(t,s)=>{const n=t[s].level-1;for(let e=s-1;e>=0;e--)if(t[e].level===n)return e;return-1},o=t=>(t==null?void 0:t.type)==="inline",d=t=>(t==null?void 0:t.type)==="paragraph_open",u=t=>(t==null?void 0:t.type)==="list_item_open",h=t=>/^\[[xX \u00A0]\][ \u00A0]/.test(t.content),k=(t,s)=>o(t[s])&&d(t[s-1])&&u(t[s-2])&&h(t[s]),b=(t,s,n=!0)=>{const e=new a("checkbox_input","input",0);return e.attrs=[["type","checkbox"],["class","task-list-item-checkbox"],["id",s]],/^\[[xX]\][ \u00A0]/.test(t.content)&&e.attrs.push(["checked","checked"]),n&&e.attrs.push(["disabled","disabled"]),e},p=t=>{const s=new a("label_open","label",1);return s.attrs=[["class","task-list-item-label"],["for",t]],s},v=()=>new a("label_close","label",-1),f=(t,s,n)=>{const e=`task-item-${s.env.tasklists++}`;t.children=t.children||[],t.children[0].content=t.children[0].content.slice(3),n.label&&(t.children.unshift(p(e)),t.children.push(v())),t.children.unshift(b(t,e,n.disabled))},m=(t,{disabled:s=!0,label:n=!0}={})=>{t.core.ruler.after("inline","github-task-lists",e=>{const l=e.tokens;e.env.tasklists||(e.env.tasklists=0);for(let i=2;i<l.length;i++)k(l,i)&&(f(l[i],e,{disabled:s,label:n}),r(l[i-2],"class","task-list-item"),r(l[c(l,i-2)],"class","task-list-container"));return!0})};exports.tasklist=m;
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/utils.ts","../src/plugin.ts"],"sourcesContent":["import type Token from \"markdown-it/lib/token.js\";\n\nexport const setTokenAttr = (\n token: Token,\n name: string,\n value: string\n): void => {\n const index = token.attrIndex(name);\n const attr: [string, string] = [name, value];\n\n if (index < 0) token.attrPush(attr);\n else token.attrs![index] = attr;\n};\n\nexport const getParentTokenIndex = (tokens: Token[], index: number): number => {\n const targetLevel = tokens[index].level - 1;\n\n for (let i = index - 1; i >= 0; i--)\n if (tokens[i].level === targetLevel) return i;\n\n return -1;\n};\n\nexport const isInlineToken = (token?: Token): boolean =>\n token?.type === \"inline\";\n\nexport const isParagraphToken = (token?: Token): boolean =>\n token?.type === \"paragraph_open\";\n\nexport const isListItemToken = (token?: Token): boolean =>\n token?.type === \"list_item_open\";\n","/**\n * Forked from https://github.com/linsir/markdown-it-task-checkbox/blob/master/index.js\n */\n\nimport Token from \"markdown-it/lib/token.js\";\nimport {\n getParentTokenIndex,\n isInlineToken,\n isParagraphToken,\n isListItemToken,\n setTokenAttr,\n} from \"./utils.js\";\n\nimport type { PluginWithOptions } from \"markdown-it\";\nimport type StateCore from \"markdown-it/lib/rules_core/state_core.js\";\nimport type { MarkdownItTaskListOptions } from \"./options.js\";\nimport type { TaskListEnv } from \"./types.js\";\n\ninterface TaskListStateCore extends StateCore {\n env: TaskListEnv;\n}\n// The leading whitespace in a list item (token.content) is already trimmed off by markdown-it.\n// The regex below checks for '[ ] ' or '[x] ' or '[X] ' at the start of the string token.content,\n// where the space is either a normal space or a non-breaking space (character 160 = \\u00A0).\nconst startsWithTodoMarkdown = (token: Token): boolean =>\n /^\\[[xX \\u00A0]\\][ \\u00A0]/.test(token.content);\n\nconst isTaskListItem = (tokens: Token[], index: number): boolean =>\n isInlineToken(tokens[index]) &&\n isParagraphToken(tokens[index - 1]) &&\n isListItemToken(tokens[index - 2]) &&\n startsWithTodoMarkdown(tokens[index]);\n\nconst generateCheckbox = (token: Token, id: string, disabled = true): Token => {\n const checkbox = new Token(\"checkbox_input\", \"input\", 0);\n\n checkbox.attrs = [\n [\"type\", \"checkbox\"],\n [\"class\", \"task-list-item-checkbox\"],\n [\"id\", id],\n ];\n\n // if token.content starts with '[x] ' or '[X] '\n if (/^\\[[xX]\\][ \\u00A0]/.test(token.content))\n checkbox.attrs.push([\"checked\", \"checked\"]);\n\n if (disabled) checkbox.attrs.push([\"disabled\", \"disabled\"]);\n\n return checkbox;\n};\n\nconst beginLabel = (id: string): Token => {\n const label = new Token(\"label_open\", \"label\", 1);\n\n label.attrs = [\n [\"class\", \"task-list-item-label\"],\n [\"for\", id],\n ];\n\n return label;\n};\n\nconst endLabel = (): Token => new Token(\"label_close\", \"label\", -1);\n\nconst addCheckBox = (\n token: Token,\n state: TaskListStateCore,\n options: Required<MarkdownItTaskListOptions>\n): void => {\n const id = `task-item-${state.env.tasklists++}`;\n\n token.children = token.children || [];\n\n // remove the checkbox syntax letter\n token.children[0].content = token.children[0].content.slice(3);\n\n if (options.label) {\n // add label\n token.children.unshift(beginLabel(id));\n token.children.push(endLabel());\n }\n // checkbox\n token.children.unshift(generateCheckbox(token, id, options.disabled));\n};\n\nexport const tasklist: PluginWithOptions<MarkdownItTaskListOptions> = (\n md,\n { disabled = true, label = true } = {}\n) => {\n md.core.ruler.after(\n \"inline\",\n \"github-task-lists\",\n (state: TaskListStateCore) => {\n const tokens = state.tokens;\n\n if (!state.env.tasklists) state.env.tasklists = 0;\n\n for (let i = 2; i < tokens.length; i++) {\n if (isTaskListItem(tokens, i)) {\n addCheckBox(tokens[i], state, { disabled, label });\n setTokenAttr(tokens[i - 2], \"class\", \"task-list-item\");\n setTokenAttr(\n tokens[getParentTokenIndex(tokens, i - 2)],\n \"class\",\n \"task-list-container\"\n );\n }\n }\n\n return true;\n }\n );\n};\n"],"names":["setTokenAttr","token","name","value","index","attr","getParentTokenIndex","tokens","targetLevel","i","isInlineToken","isParagraphToken","isListItemToken","startsWithTodoMarkdown","isTaskListItem","generateCheckbox","id","disabled","checkbox","Token","beginLabel","label","endLabel","addCheckBox","state","options","tasklist","md"],"mappings":"uDAEO,MAAMA,EAAe,CAC1BC,EACAC,EACAC,IACS,CACT,MAAMC,EAAQH,EAAM,UAAUC,CAAI,EAC5BG,EAAyB,CAACH,EAAMC,CAAK,EAEvCC,EAAQ,EAAGH,EAAM,SAASI,CAAI,EAC7BJ,EAAM,MAAOG,GAASC,CAC7B,EAEaC,EAAsB,CAACC,EAAiBH,IAA0B,CAC7E,MAAMI,EAAcD,EAAOH,GAAO,MAAQ,EAE1C,QAASK,EAAIL,EAAQ,EAAGK,GAAK,EAAGA,IAC9B,GAAIF,EAAOE,GAAG,QAAUD,EAAa,OAAOC,EAE9C,MAAO,EACT,EAEaC,EAAiBT,IAC5BA,GAAA,YAAAA,EAAO,QAAS,SAELU,EAAoBV,IAC/BA,GAAA,KAAA,OAAAA,EAAO,QAAS,iBAELW,EAAmBX,IAC9BA,GAAA,KAAA,OAAAA,EAAO,QAAS,iBCNZY,EAA0BZ,GAC9B,4BAA4B,KAAKA,EAAM,OAAO,EAE1Ca,EAAiB,CAACP,EAAiBH,IACvCM,EAAcH,EAAOH,EAAM,GAC3BO,EAAiBJ,EAAOH,EAAQ,EAAE,GAClCQ,EAAgBL,EAAOH,EAAQ,EAAE,GACjCS,EAAuBN,EAAOH,EAAM,EAEhCW,EAAmB,CAACd,EAAce,EAAYC,EAAW,KAAgB,CAC7E,MAAMC,EAAW,IAAIC,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MAAAI,CAAM,CAAC,EACjDrB,EAAaO,EAAOE,EAAI,GAAI,QAAS,gBAAgB,EACrDT,EACEO,EAAOD,EAAoBC,EAAQE,EAAI,CAAC,GACxC,QACA,qBACF,GAIJ,MAAO,EACT,CACF,CACF"}
|
package/lib/index.d.cts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { PluginWithOptions } from 'markdown-it';
|
|
2
|
+
|
|
3
|
+
interface MarkdownItTaskListOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Whether disable checkbox
|
|
6
|
+
*
|
|
7
|
+
* 是否禁用 checkbox
|
|
8
|
+
*
|
|
9
|
+
* @default true
|
|
10
|
+
*/
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Whether use `<label>` to wrap text
|
|
14
|
+
*
|
|
15
|
+
* 是否使用 `<label>` 来包裹文字
|
|
16
|
+
*
|
|
17
|
+
* @default true
|
|
18
|
+
*/
|
|
19
|
+
label?: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Forked from https://github.com/linsir/markdown-it-task-checkbox/blob/master/index.js
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
declare const tasklist: PluginWithOptions<MarkdownItTaskListOptions>;
|
|
27
|
+
|
|
28
|
+
interface TaskListEnv {
|
|
29
|
+
tasklists: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { MarkdownItTaskListOptions, TaskListEnv, tasklist };
|
package/lib/index.d.mts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { PluginWithOptions } from 'markdown-it';
|
|
2
|
+
|
|
3
|
+
interface MarkdownItTaskListOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Whether disable checkbox
|
|
6
|
+
*
|
|
7
|
+
* 是否禁用 checkbox
|
|
8
|
+
*
|
|
9
|
+
* @default true
|
|
10
|
+
*/
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Whether use `<label>` to wrap text
|
|
14
|
+
*
|
|
15
|
+
* 是否使用 `<label>` 来包裹文字
|
|
16
|
+
*
|
|
17
|
+
* @default true
|
|
18
|
+
*/
|
|
19
|
+
label?: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Forked from https://github.com/linsir/markdown-it-task-checkbox/blob/master/index.js
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
declare const tasklist: PluginWithOptions<MarkdownItTaskListOptions>;
|
|
27
|
+
|
|
28
|
+
interface TaskListEnv {
|
|
29
|
+
tasklists: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { MarkdownItTaskListOptions, TaskListEnv, tasklist };
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { PluginWithOptions } from 'markdown-it';
|
|
2
|
+
|
|
3
|
+
interface MarkdownItTaskListOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Whether disable checkbox
|
|
6
|
+
*
|
|
7
|
+
* 是否禁用 checkbox
|
|
8
|
+
*
|
|
9
|
+
* @default true
|
|
10
|
+
*/
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Whether use `<label>` to wrap text
|
|
14
|
+
*
|
|
15
|
+
* 是否使用 `<label>` 来包裹文字
|
|
16
|
+
*
|
|
17
|
+
* @default true
|
|
18
|
+
*/
|
|
19
|
+
label?: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Forked from https://github.com/linsir/markdown-it-task-checkbox/blob/master/index.js
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
declare const tasklist: PluginWithOptions<MarkdownItTaskListOptions>;
|
|
27
|
+
|
|
28
|
+
interface TaskListEnv {
|
|
29
|
+
tasklists: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { MarkdownItTaskListOptions, TaskListEnv, tasklist };
|
package/lib/index.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import a from"markdown-it/lib/token.js";const r=(t,s,n)=>{const e=t.attrIndex(s),l=[s,n];e<0?t.attrPush(l):t.attrs[e]=l},o=(t,s)=>{const n=t[s].level-1;for(let e=s-1;e>=0;e--)if(t[e].level===n)return e;return-1},c=t=>(t==null?void 0:t.type)==="inline",d=t=>(t==null?void 0:t.type)==="paragraph_open",h=t=>(t==null?void 0:t.type)==="list_item_open",u=t=>/^\[[xX \u00A0]\][ \u00A0]/.test(t.content),k=(t,s)=>c(t[s])&&d(t[s-1])&&h(t[s-2])&&u(t[s]),b=(t,s,n=!0)=>{const e=new a("checkbox_input","input",0);return e.attrs=[["type","checkbox"],["class","task-list-item-checkbox"],["id",s]],/^\[[xX]\][ \u00A0]/.test(t.content)&&e.attrs.push(["checked","checked"]),n&&e.attrs.push(["disabled","disabled"]),e},p=t=>{const s=new a("label_open","label",1);return s.attrs=[["class","task-list-item-label"],["for",t]],s},m=()=>new a("label_close","label",-1),f=(t,s,n)=>{const e=`task-item-${s.env.tasklists++}`;t.children=t.children||[],t.children[0].content=t.children[0].content.slice(3),n.label&&(t.children.unshift(p(e)),t.children.push(m())),t.children.unshift(b(t,e,n.disabled))},v=(t,{disabled:s=!0,label:n=!0}={})=>{t.core.ruler.after("inline","github-task-lists",e=>{const l=e.tokens;e.env.tasklists||(e.env.tasklists=0);for(let i=2;i<l.length;i++)k(l,i)&&(f(l[i],e,{disabled:s,label:n}),r(l[i-2],"class","task-list-item"),r(l[o(l,i-2)],"class","task-list-container"));return!0})};export{v as tasklist};
|
|
2
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/utils.ts","../src/plugin.ts"],"sourcesContent":["import type Token from \"markdown-it/lib/token.js\";\n\nexport const setTokenAttr = (\n token: Token,\n name: string,\n value: string\n): void => {\n const index = token.attrIndex(name);\n const attr: [string, string] = [name, value];\n\n if (index < 0) token.attrPush(attr);\n else token.attrs![index] = attr;\n};\n\nexport const getParentTokenIndex = (tokens: Token[], index: number): number => {\n const targetLevel = tokens[index].level - 1;\n\n for (let i = index - 1; i >= 0; i--)\n if (tokens[i].level === targetLevel) return i;\n\n return -1;\n};\n\nexport const isInlineToken = (token?: Token): boolean =>\n token?.type === \"inline\";\n\nexport const isParagraphToken = (token?: Token): boolean =>\n token?.type === \"paragraph_open\";\n\nexport const isListItemToken = (token?: Token): boolean =>\n token?.type === \"list_item_open\";\n","/**\n * Forked from https://github.com/linsir/markdown-it-task-checkbox/blob/master/index.js\n */\n\nimport Token from \"markdown-it/lib/token.js\";\nimport {\n getParentTokenIndex,\n isInlineToken,\n isParagraphToken,\n isListItemToken,\n setTokenAttr,\n} from \"./utils.js\";\n\nimport type { PluginWithOptions } from \"markdown-it\";\nimport type StateCore from \"markdown-it/lib/rules_core/state_core.js\";\nimport type { MarkdownItTaskListOptions } from \"./options.js\";\nimport type { TaskListEnv } from \"./types.js\";\n\ninterface TaskListStateCore extends StateCore {\n env: TaskListEnv;\n}\n// The leading whitespace in a list item (token.content) is already trimmed off by markdown-it.\n// The regex below checks for '[ ] ' or '[x] ' or '[X] ' at the start of the string token.content,\n// where the space is either a normal space or a non-breaking space (character 160 = \\u00A0).\nconst startsWithTodoMarkdown = (token: Token): boolean =>\n /^\\[[xX \\u00A0]\\][ \\u00A0]/.test(token.content);\n\nconst isTaskListItem = (tokens: Token[], index: number): boolean =>\n isInlineToken(tokens[index]) &&\n isParagraphToken(tokens[index - 1]) &&\n isListItemToken(tokens[index - 2]) &&\n startsWithTodoMarkdown(tokens[index]);\n\nconst generateCheckbox = (token: Token, id: string, disabled = true): Token => {\n const checkbox = new Token(\"checkbox_input\", \"input\", 0);\n\n checkbox.attrs = [\n [\"type\", \"checkbox\"],\n [\"class\", \"task-list-item-checkbox\"],\n [\"id\", id],\n ];\n\n // if token.content starts with '[x] ' or '[X] '\n if (/^\\[[xX]\\][ \\u00A0]/.test(token.content))\n checkbox.attrs.push([\"checked\", \"checked\"]);\n\n if (disabled) checkbox.attrs.push([\"disabled\", \"disabled\"]);\n\n return checkbox;\n};\n\nconst beginLabel = (id: string): Token => {\n const label = new Token(\"label_open\", \"label\", 1);\n\n label.attrs = [\n [\"class\", \"task-list-item-label\"],\n [\"for\", id],\n ];\n\n return label;\n};\n\nconst endLabel = (): Token => new Token(\"label_close\", \"label\", -1);\n\nconst addCheckBox = (\n token: Token,\n state: TaskListStateCore,\n options: Required<MarkdownItTaskListOptions>\n): void => {\n const id = `task-item-${state.env.tasklists++}`;\n\n token.children = token.children || [];\n\n // remove the checkbox syntax letter\n token.children[0].content = token.children[0].content.slice(3);\n\n if (options.label) {\n // add label\n token.children.unshift(beginLabel(id));\n token.children.push(endLabel());\n }\n // checkbox\n token.children.unshift(generateCheckbox(token, id, options.disabled));\n};\n\nexport const tasklist: PluginWithOptions<MarkdownItTaskListOptions> = (\n md,\n { disabled = true, label = true } = {}\n) => {\n md.core.ruler.after(\n \"inline\",\n \"github-task-lists\",\n (state: TaskListStateCore) => {\n const tokens = state.tokens;\n\n if (!state.env.tasklists) state.env.tasklists = 0;\n\n for (let i = 2; i < tokens.length; i++) {\n if (isTaskListItem(tokens, i)) {\n addCheckBox(tokens[i], state, { disabled, label });\n setTokenAttr(tokens[i - 2], \"class\", \"task-list-item\");\n setTokenAttr(\n tokens[getParentTokenIndex(tokens, i - 2)],\n \"class\",\n \"task-list-container\"\n );\n }\n }\n\n return true;\n }\n );\n};\n"],"names":["setTokenAttr","token","name","value","index","attr","getParentTokenIndex","tokens","targetLevel","i","isInlineToken","isParagraphToken","isListItemToken","startsWithTodoMarkdown","isTaskListItem","generateCheckbox","id","disabled","checkbox","Token","beginLabel","label","endLabel","addCheckBox","state","options","tasklist","md"],"mappings":"wCAEO,MAAMA,EAAe,CAC1BC,EACAC,EACAC,IACS,CACT,MAAMC,EAAQH,EAAM,UAAUC,CAAI,EAC5BG,EAAyB,CAACH,EAAMC,CA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E,EAE5DI,EAAc,CAClBtB,EACAuB,EACAC,IACS,CACT,MAAMT,EAAK,aAAaQ,EAAM,IAAI,cAElCvB,EAAM,SAAWA,EAAM,UAAY,CAAA,EAGnCA,EAAM,SAAS,GAAG,QAAUA,EAAM,SAAS,GAAG,QAAQ,MAAM,CAAC,EAEzDwB,EAAQ,QAEVxB,EAAM,SAAS,QAAQmB,EAAWJ,CAAE,CAAC,EACrCf,EAAM,SAAS,KAAKqB,EAAU,CAAA,GAGhCrB,EAAM,SAAS,QAAQc,EAAiBd,EAAOe,EAAIS,EAAQ,QAAQ,CAAC,CACtE,EAEaC,EAAyD,CACpEC,EACA,CAAE,SAAAV,EAAW,GAAM,MAAAI,EAAQ,EAAK,EAAI,CAAA,IACjC,CACHM,EAAG,KAAK,MAAM,MACZ,SACA,oBACCH,GAA6B,CAC5B,MAAMjB,EAASiB,EAAM,OAEhBA,EAAM,IAAI,YAAWA,EAAM,IAAI,UAAY,GAEhD,QAASf,EAAI,EAAGA,EAAIF,EAAO,OAAQE,IAC7BK,EAAeP,EAAQE,CAAC,IAC1Bc,EAAYhB,EAAOE,GAAIe,EAAO,CAAE,SAAAP,EAAU,MAAAI,CAAM,CAAC,EACjDrB,EAAaO,EAAOE,EAAI,GAAI,QAAS,gBAAgB,EACrDT,EACEO,EAAOD,EAAoBC,EAAQE,EAAI,CAAC,GACxC,QACA,qBACF,GAIJ,MAAO,EACT,CACF,CACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mdit/plugin-tasklist",
|
|
3
|
+
"version": "0.1.0-alpha.0",
|
|
4
|
+
"description": "tasklist plugin for MarkdownIt",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"markdownit",
|
|
7
|
+
"markdown-it",
|
|
8
|
+
"markdown-it-plugin",
|
|
9
|
+
"tasklist"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://github.com/Mister-Hope//mdit-plugins/packages/tasklist#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/Mister-Hope//mdit-plugins/issues"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/Mister-Hope//mdit-plugins.git",
|
|
18
|
+
"directory": "packages/tasklist"
|
|
19
|
+
},
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"author": {
|
|
22
|
+
"name": "Mr.Hope",
|
|
23
|
+
"email": "mister-hope@outlook.com",
|
|
24
|
+
"url": "https://mrhope.site"
|
|
25
|
+
},
|
|
26
|
+
"main": "lib/index.cjs",
|
|
27
|
+
"types": "lib/index.d.ts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": "./lib/index.mjs",
|
|
30
|
+
"./package.json": "./package.json"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"lib"
|
|
34
|
+
],
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@types/markdown-it": "^12.2.3",
|
|
37
|
+
"markdown-it": "^13.0.1"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "rollup -c rollup.config.ts --configPlugin esbuild",
|
|
44
|
+
"clean": "rimraf ./lib"
|
|
45
|
+
}
|
|
46
|
+
}
|