md-editor-v3 4.18.0-0 → 4.18.0-2

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.
@@ -8,7 +8,6 @@ const mediumZoom = require("medium-zoom");
8
8
  const copy = require("copy-to-clipboard");
9
9
  const mdit = require("markdown-it");
10
10
  const ImageFiguresPlugin = require("markdown-it-image-figures");
11
- const TaskListPlugin = require("markdown-it-task-lists");
12
11
  const index$1 = require("./index4.cjs");
13
12
  const lruCache = require("lru-cache");
14
13
  function _mergeNamespaces(n, m) {
@@ -2036,6 +2035,100 @@ const XSSPlugin = (md, options) => {
2036
2035
  });
2037
2036
  };
2038
2037
  const XSSPlugin$1 = XSSPlugin;
2038
+ const attrSet = (token, name, value) => {
2039
+ const index2 = token.attrIndex(name);
2040
+ const attr = [name, value];
2041
+ if (index2 < 0) {
2042
+ token.attrPush(attr);
2043
+ } else {
2044
+ token.attrs = token.attrs || [];
2045
+ token.attrs[index2] = attr;
2046
+ }
2047
+ };
2048
+ const isInline = (token) => {
2049
+ return token.type === "inline";
2050
+ };
2051
+ const isParagraph = (token) => {
2052
+ return token.type === "paragraph_open";
2053
+ };
2054
+ const isListItem = (token) => {
2055
+ return token.type === "list_item_open";
2056
+ };
2057
+ const startsWithTodoMarkdown = (token) => {
2058
+ return token.content.indexOf("[ ] ") === 0 || token.content.indexOf("[x] ") === 0 || token.content.indexOf("[X] ") === 0;
2059
+ };
2060
+ const isTodoItem = (tokens, index2) => {
2061
+ return isInline(tokens[index2]) && isParagraph(tokens[index2 - 1]) && isListItem(tokens[index2 - 2]) && startsWithTodoMarkdown(tokens[index2]);
2062
+ };
2063
+ const parentToken = (tokens, index2) => {
2064
+ const targetLevel = tokens[index2].level - 1;
2065
+ for (let i = index2 - 1; i >= 0; i--) {
2066
+ if (tokens[i].level === targetLevel) {
2067
+ return i;
2068
+ }
2069
+ }
2070
+ return -1;
2071
+ };
2072
+ const beginLabel = (TokenConstructor) => {
2073
+ const token = new TokenConstructor("html_inline", "", 0);
2074
+ token.content = "<label>";
2075
+ return token;
2076
+ };
2077
+ const endLabel = (TokenConstructor) => {
2078
+ const token = new TokenConstructor("html_inline", "", 0);
2079
+ token.content = "</label>";
2080
+ return token;
2081
+ };
2082
+ const afterLabel = (content, id, TokenConstructor) => {
2083
+ const token = new TokenConstructor("html_inline", "", 0);
2084
+ token.content = '<label class="task-list-item-label" for="' + id + '">' + content + "</label>";
2085
+ token.attrs = [{ for: id }];
2086
+ return token;
2087
+ };
2088
+ const makeCheckbox = (token, TokenConstructor, options) => {
2089
+ const checkbox = new TokenConstructor("html_inline", "", 0);
2090
+ const disabledAttr = !options.enabled ? ' disabled="" ' : " ";
2091
+ if (token.content.indexOf("[ ] ") === 0) {
2092
+ checkbox.content = '<input class="task-list-item-checkbox"' + disabledAttr + 'type="checkbox">';
2093
+ } else if (token.content.indexOf("[x] ") === 0 || token.content.indexOf("[X] ") === 0) {
2094
+ checkbox.content = '<input class="task-list-item-checkbox" checked=""' + disabledAttr + 'type="checkbox">';
2095
+ }
2096
+ return checkbox;
2097
+ };
2098
+ const todoify = (token, TokenConstructor, options) => {
2099
+ token.children = token.children || [];
2100
+ token.children.unshift(makeCheckbox(token, TokenConstructor, options));
2101
+ token.children[1].content = token.children[1].content.slice(3);
2102
+ token.content = token.content.slice(3);
2103
+ if (options.label) {
2104
+ if (options.labelAfter) {
2105
+ token.children.pop();
2106
+ const id = "task-item-" + Math.ceil(Math.random() * (1e4 * 1e3) - 1e3);
2107
+ token.children[0].content = token.children[0].content.slice(0, -1) + ' id="' + id + '">';
2108
+ token.children.push(afterLabel(token.content, id, TokenConstructor));
2109
+ } else {
2110
+ token.children.unshift(beginLabel(TokenConstructor));
2111
+ token.children.push(endLabel(TokenConstructor));
2112
+ }
2113
+ }
2114
+ };
2115
+ const githubTaskLists = (md, options = {}) => {
2116
+ md.core.ruler.after("inline", "github-task-lists", (state) => {
2117
+ const tokens = state.tokens;
2118
+ for (let i = 2; i < tokens.length; i++) {
2119
+ if (isTodoItem(tokens, i)) {
2120
+ todoify(tokens[i], state.Token, options);
2121
+ attrSet(
2122
+ tokens[i - 2],
2123
+ "class",
2124
+ "task-list-item" + (options.enabled ? " enabled" : " ")
2125
+ );
2126
+ attrSet(tokens[parentToken(tokens, i - 2)], "class", "contains-task-list");
2127
+ }
2128
+ }
2129
+ });
2130
+ };
2131
+ const TaskListPlugin = githubTaskLists;
2039
2132
  const initLineNumber = (md) => {
2040
2133
  md.core.ruler.push("init-line-number", (state) => {
2041
2134
  state.tokens.forEach((token) => {
@@ -3387,7 +3480,12 @@ const MdPreview = /* @__PURE__ */ vue.defineComponent({
3387
3480
  "style": props.style
3388
3481
  }, [vue.createVNode(ContentPreview, {
3389
3482
  "modelValue": props.modelValue,
3390
- "onChange": props.onChange,
3483
+ "onChange": (value) => {
3484
+ if (props.onChange) {
3485
+ props.onChange(value);
3486
+ }
3487
+ ctx.emit("onChange", value);
3488
+ },
3391
3489
  "onHtmlChanged": (html) => {
3392
3490
  if (props.onHtmlChanged) {
3393
3491
  props.onHtmlChanged(html);
@@ -7,7 +7,6 @@ import mediumZoom from "medium-zoom";
7
7
  import copy from "copy-to-clipboard";
8
8
  import mdit from "markdown-it";
9
9
  import ImageFiguresPlugin from "markdown-it-image-figures";
10
- import TaskListPlugin from "markdown-it-task-lists";
11
10
  import { c as generateCodeRowNumber, d as getNextId } from "./index4.mjs";
12
11
  import { LRUCache } from "lru-cache";
13
12
  function _mergeNamespaces(n, m) {
@@ -2035,6 +2034,100 @@ const XSSPlugin = (md, options) => {
2035
2034
  });
2036
2035
  };
2037
2036
  const XSSPlugin$1 = XSSPlugin;
2037
+ const attrSet = (token, name, value) => {
2038
+ const index2 = token.attrIndex(name);
2039
+ const attr = [name, value];
2040
+ if (index2 < 0) {
2041
+ token.attrPush(attr);
2042
+ } else {
2043
+ token.attrs = token.attrs || [];
2044
+ token.attrs[index2] = attr;
2045
+ }
2046
+ };
2047
+ const isInline = (token) => {
2048
+ return token.type === "inline";
2049
+ };
2050
+ const isParagraph = (token) => {
2051
+ return token.type === "paragraph_open";
2052
+ };
2053
+ const isListItem = (token) => {
2054
+ return token.type === "list_item_open";
2055
+ };
2056
+ const startsWithTodoMarkdown = (token) => {
2057
+ return token.content.indexOf("[ ] ") === 0 || token.content.indexOf("[x] ") === 0 || token.content.indexOf("[X] ") === 0;
2058
+ };
2059
+ const isTodoItem = (tokens, index2) => {
2060
+ return isInline(tokens[index2]) && isParagraph(tokens[index2 - 1]) && isListItem(tokens[index2 - 2]) && startsWithTodoMarkdown(tokens[index2]);
2061
+ };
2062
+ const parentToken = (tokens, index2) => {
2063
+ const targetLevel = tokens[index2].level - 1;
2064
+ for (let i = index2 - 1; i >= 0; i--) {
2065
+ if (tokens[i].level === targetLevel) {
2066
+ return i;
2067
+ }
2068
+ }
2069
+ return -1;
2070
+ };
2071
+ const beginLabel = (TokenConstructor) => {
2072
+ const token = new TokenConstructor("html_inline", "", 0);
2073
+ token.content = "<label>";
2074
+ return token;
2075
+ };
2076
+ const endLabel = (TokenConstructor) => {
2077
+ const token = new TokenConstructor("html_inline", "", 0);
2078
+ token.content = "</label>";
2079
+ return token;
2080
+ };
2081
+ const afterLabel = (content, id, TokenConstructor) => {
2082
+ const token = new TokenConstructor("html_inline", "", 0);
2083
+ token.content = '<label class="task-list-item-label" for="' + id + '">' + content + "</label>";
2084
+ token.attrs = [{ for: id }];
2085
+ return token;
2086
+ };
2087
+ const makeCheckbox = (token, TokenConstructor, options) => {
2088
+ const checkbox = new TokenConstructor("html_inline", "", 0);
2089
+ const disabledAttr = !options.enabled ? ' disabled="" ' : " ";
2090
+ if (token.content.indexOf("[ ] ") === 0) {
2091
+ checkbox.content = '<input class="task-list-item-checkbox"' + disabledAttr + 'type="checkbox">';
2092
+ } else if (token.content.indexOf("[x] ") === 0 || token.content.indexOf("[X] ") === 0) {
2093
+ checkbox.content = '<input class="task-list-item-checkbox" checked=""' + disabledAttr + 'type="checkbox">';
2094
+ }
2095
+ return checkbox;
2096
+ };
2097
+ const todoify = (token, TokenConstructor, options) => {
2098
+ token.children = token.children || [];
2099
+ token.children.unshift(makeCheckbox(token, TokenConstructor, options));
2100
+ token.children[1].content = token.children[1].content.slice(3);
2101
+ token.content = token.content.slice(3);
2102
+ if (options.label) {
2103
+ if (options.labelAfter) {
2104
+ token.children.pop();
2105
+ const id = "task-item-" + Math.ceil(Math.random() * (1e4 * 1e3) - 1e3);
2106
+ token.children[0].content = token.children[0].content.slice(0, -1) + ' id="' + id + '">';
2107
+ token.children.push(afterLabel(token.content, id, TokenConstructor));
2108
+ } else {
2109
+ token.children.unshift(beginLabel(TokenConstructor));
2110
+ token.children.push(endLabel(TokenConstructor));
2111
+ }
2112
+ }
2113
+ };
2114
+ const githubTaskLists = (md, options = {}) => {
2115
+ md.core.ruler.after("inline", "github-task-lists", (state) => {
2116
+ const tokens = state.tokens;
2117
+ for (let i = 2; i < tokens.length; i++) {
2118
+ if (isTodoItem(tokens, i)) {
2119
+ todoify(tokens[i], state.Token, options);
2120
+ attrSet(
2121
+ tokens[i - 2],
2122
+ "class",
2123
+ "task-list-item" + (options.enabled ? " enabled" : " ")
2124
+ );
2125
+ attrSet(tokens[parentToken(tokens, i - 2)], "class", "contains-task-list");
2126
+ }
2127
+ }
2128
+ });
2129
+ };
2130
+ const TaskListPlugin = githubTaskLists;
2038
2131
  const initLineNumber = (md) => {
2039
2132
  md.core.ruler.push("init-line-number", (state) => {
2040
2133
  state.tokens.forEach((token) => {
@@ -3386,7 +3479,12 @@ const MdPreview = /* @__PURE__ */ defineComponent({
3386
3479
  "style": props.style
3387
3480
  }, [createVNode(ContentPreview, {
3388
3481
  "modelValue": props.modelValue,
3389
- "onChange": props.onChange,
3482
+ "onChange": (value) => {
3483
+ if (props.onChange) {
3484
+ props.onChange(value);
3485
+ }
3486
+ ctx.emit("onChange", value);
3487
+ },
3390
3488
  "onHtmlChanged": (html) => {
3391
3489
  if (props.onHtmlChanged) {
3392
3490
  props.onHtmlChanged(html);
@@ -0,0 +1,15 @@
1
+ /**
2
+ * 源码来自https://github.com/revin/markdown-it-task-lists
3
+ *
4
+ * 进行了部分重构
5
+ * 1. 使用ts和箭头函数重构
6
+ * 2. 将option作为局部变量,支持了多个实例的使用
7
+ */
8
+ import markdownit from 'markdown-it';
9
+ interface Options {
10
+ enabled?: boolean;
11
+ label?: boolean;
12
+ labelAfter?: boolean;
13
+ }
14
+ declare const githubTaskLists: (md: markdownit, options?: Options) => void;
15
+ export default githubTaskLists;