@8btc/mditor 0.0.15 → 0.0.16

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.
@@ -1,4 +1,6 @@
1
- document.body.insertAdjacentHTML('afterbegin', `<svg style="position: absolute; width: 0; height: 0; overflow: hidden;" version="1.1" xmlns="http://www.w3.org/2000/svg">
1
+ document.body.insertAdjacentHTML(
2
+ "afterbegin",
3
+ `<svg style="position: absolute; width: 0; height: 0; overflow: hidden;" version="1.1" xmlns="http://www.w3.org/2000/svg">
2
4
  <defs>
3
5
  <symbol id="vditor-icon-comment" viewBox="0 0 32 32">
4
6
  <path d="M18.177 12.965c-0.825 0-1.464 0.639-1.464 1.428s0.639 1.428 1.464 1.428c0.754 0 1.393-0.639 1.393-1.428s-0.639-1.428-1.393-1.428zM8.178 12.965c-0.825 0-1.464 0.639-1.464 1.428s0.639 1.428 1.464 1.428c0.754 0 1.393-0.639 1.393-1.428s-0.639-1.428-1.393-1.428z"></path>
@@ -170,5 +172,10 @@ document.body.insertAdjacentHTML('afterbegin', `<svg style="position: absolute;
170
172
  <symbol id="vditor-icon-zhihu" viewBox="0 0 32 32">
171
173
  <path d="M18.245 3.993v24.401h2.555l1.073 3.041 4.532-3.041h5.601v-24.401h-13.761zM28.795 25.162h-2.551l-3.199 2.147-0.758-2.147h-0.767v-17.837h7.27v17.837zM16.601 14.931h-5.656c0.089-1.912 0.183-4.442 0.281-7.364h5.575l-0.004-0.345c0-0.026-0.009-0.626-0.098-1.239-0.089-0.639-0.281-1.486-0.894-1.486h-9.353c0.187-0.877 0.669-2.969 1.252-3.995l0.273-0.477-0.549-0.030c-0.034 0-0.835-0.038-1.763 0.451-1.521 0.809-2.202 2.402-2.5 3.595-0.784 3.113-1.9 5.277-2.372 6.201-0.141 0.273-0.226 0.434-0.264 0.545-0.077 0.209-0.034 0.417 0.119 0.554 0.447 0.405 1.627-0.124 1.64-0.128 0.026-0.013 0.055-0.026 0.094-0.043 0.592-0.268 2.347-1.065 2.973-3.599h2.415c0.030 1.371 0.132 5.895 0.124 7.364h-6.005l-0.089 0.064c-0.984 0.72-1.299 2.692-1.312 2.777l-0.060 0.392h7.113c-0.524 3.335-1.129 4.83-1.448 5.426-0.158 0.298-0.311 0.596-0.456 0.886-0.907 1.797-1.849 3.654-5.379 6.542-0.153 0.119-0.298 0.341-0.204 0.584 0.102 0.268 0.396 0.388 1.048 0.388 0.23 0 0.503-0.013 0.826-0.043 2.125-0.187 4.293-0.767 5.754-3.731 0.724-1.495 1.35-3.054 1.87-4.638l5.814 6.815 0.213-0.511c0.034-0.081 0.809-1.972 0.217-4.085l-0.021-0.077-4.604-5.239-0.937 0.707c0.273-1.112 0.451-2.125 0.532-3.028h6.759v-0.341c0-1.708-0.788-2.722-0.818-2.764l-0.102-0.128z"></path>
172
174
  </symbol>
175
+ <symbol id="vditor-icon-run" viewBox="0 0 32 32">
176
+ <path d="M12 12.004a1.333 1.333 0 0 1 2.023-1.145l6.663 3.996a1.333 1.333 0 0 1 0 2.291l-6.663 3.996A1.333 1.333 0 0 1 12 19.995z" fill="none" stroke="currentColor" stroke-width="2.667" stroke-linecap="round" stroke-linejoin="round"></path>
177
+ <circle cx="16" cy="16" r="13.333" fill="none" stroke="currentColor" stroke-width="2.667" stroke-linecap="round" stroke-linejoin="round"></circle>
178
+ </symbol>
173
179
  </defs>
174
- </svg>`)
180
+ </svg>`
181
+ );
@@ -143,9 +143,13 @@ document.body.insertAdjacentHTML(
143
143
  <symbol id="vditor-icon-pause" viewBox="0 0 32 32">
144
144
  <path d="M20.617 0h9.128v32h-9.128v-32zM2.255 32v-32h9.128v32h-9.128z"></path>
145
145
  </symbol>
146
- <symbol id="vditor-icon-run" viewBox="0 0 24 24">
147
- <path d="M9 9.003a1 1 0 0 1 1.517-.859l4.997 2.997a1 1 0 0 1 0 1.718l-4.997 2.997A1 1 0 0 1 9 14.996z" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path>
148
- <circle cx="12" cy="12" r="10" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></circle>
146
+ <symbol id="vditor-icon-run" viewBox="0 0 32 32">
147
+ <path d="M12 12.004a1.333 1.333 0 0 1 2.023-1.145l6.663 3.996a1.333 1.333 0 0 1 0 2.291l-6.663 3.996A1.333 1.333 0 0 1 12 19.995z" fill="none" stroke="currentColor" stroke-width="2.667" stroke-linecap="round" stroke-linejoin="round"></path>
148
+ <circle cx="16" cy="16" r="13.333" fill="none" stroke="currentColor" stroke-width="2.667" stroke-linecap="round" stroke-linejoin="round"></circle>
149
+ </symbol>
150
+ <symbol id="vditor-icon-play" viewBox="0 0 32 32">
151
+ <path d="M12 12.004a1.333 1.333 0 0 1 2.023-1.145l6.663 3.996a1.333 1.333 0 0 1 0 2.291l-6.663 3.996A1.333 1.333 0 0 1 12 19.995z" fill="none" stroke="currentColor" stroke-width="2.667" stroke-linecap="round" stroke-linejoin="round"></path>
152
+ <circle cx="16" cy="16" r="13.333" fill="none" stroke="currentColor" stroke-width="2.667" stroke-linecap="round" stroke-linejoin="round"></circle>
149
153
  </symbol>
150
154
  <symbol id="vditor-icon-emoji" viewBox="0 0 32 32">
151
155
  <path d="M16 24.789q-2.779 0-4.995-1.54t-3.192-4.019h2.629q1.878 3.155 5.559 3.155t5.559-3.155h2.629q-0.977 2.479-3.192 4.019t-4.995 1.54zM16 28.845q5.258 0 9.052-3.793t3.793-9.052-3.793-9.052-9.052-3.793-9.052 3.793-3.793 9.052 3.793 9.052 9.052 3.793zM16 0q6.61 0 11.305 4.695t4.695 11.305-4.695 11.305-11.305 4.695-11.305-4.695-4.695-11.305 4.695-11.305 11.305-4.695zM10.366 14.423q-0.977 0-1.69-0.714t-0.714-1.69 0.714-1.69 1.69-0.714 1.69 0.714 0.714 1.69-0.714 1.69-1.69 0.714zM21.634 14.423q-0.977 0-1.69-0.714t-0.714-1.69 0.714-1.69 1.69-0.714 1.69 0.714 0.714 1.69-0.714 1.69-1.69 0.714z"></path>
package/dist/method.d.ts CHANGED
@@ -5,9 +5,13 @@ declare class Vditor {
5
5
  /** 点击图片放大 */
6
6
  static previewImage: (oldImgElement: HTMLImageElement, lang?: keyof II18n, theme?: string) => void;
7
7
  /** 为 element 中的代码块添加复制按钮 */
8
- static codeRender: (element: HTMLElement, option?: IHljs, runHtml?: {
8
+ static codeRender: (element: HTMLElement, option?: IHljs, runCode?: {
9
9
  enable?: boolean;
10
- callback?(html: string): void;
10
+ items?: string[];
11
+ callback?(payload: {
12
+ code: string;
13
+ lang: string;
14
+ }): void;
11
15
  }) => void;
12
16
  /** 对 graphviz 进行渲染 */
13
17
  static graphvizRender: (element: HTMLElement, cdn?: string) => void;
package/dist/method.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Vditor v0.0.15 - A markdown editor written in TypeScript.
2
+ * Vditor v0.0.16 - A markdown editor written in TypeScript.
3
3
  *
4
4
  * MIT License
5
5
  *
@@ -45,7 +45,7 @@ return /******/ (() => { // webpackBootstrap
45
45
  /* harmony export */ "g": () => (/* binding */ Constants)
46
46
  /* harmony export */ });
47
47
  /* unused harmony export VDITOR_VERSION */
48
- var _VDITOR_VERSION = (/* unused pure expression or super */ null && ("0.0.15"));
48
+ var _VDITOR_VERSION = (/* unused pure expression or super */ null && ("0.0.16"));
49
49
 
50
50
  var Constants = /** @class */ (function () {
51
51
  function Constants() {
@@ -347,7 +347,7 @@ var Constants = /** @class */ (function () {
347
347
  "c#",
348
348
  "bat",
349
349
  ];
350
- Constants.CDN = "https://webcdn.wujieai.com/vditor@".concat("0.0.15");
350
+ Constants.CDN = "https://webcdn.wujieai.com/vditor@".concat("0.0.16");
351
351
  Constants.MARKDOWN_OPTIONS = {
352
352
  autoSpace: false,
353
353
  gfmAutoLink: true,
@@ -1703,9 +1703,9 @@ var attachEchartsContextMenu = function (el, option, chart, cdn) {
1703
1703
  /**
1704
1704
  * 为预览区域中的代码块添加辅助操作:
1705
1705
  * - 复制按钮:一键复制代码文本
1706
- * - 运行按钮:当启用 runHtml 时,向外部回调当前代码块的 HTML 字符串
1706
+ * - 运行按钮:当启用 runCode 时,向外部回调当前代码块的 HTML 字符串
1707
1707
  */
1708
- var codeRender = function (element, option, runHtml) {
1708
+ var codeRender = function (element, option, runCode) {
1709
1709
  Array.from(element.querySelectorAll("pre > code"))
1710
1710
  .filter(function (e, index) {
1711
1711
  if (e.parentElement.classList.contains("vditor-wysiwyg__pre") ||
@@ -1754,14 +1754,18 @@ var codeRender = function (element, option, runHtml) {
1754
1754
  '<svg viewBox="0 0 32 32"><path d="M22.545-0h-17.455c-1.6 0-2.909 1.309-2.909 2.909v20.364h2.909v-20.364h17.455v-2.909zM26.909 5.818h-16c-1.6 0-2.909 1.309-2.909 2.909v20.364c0 1.6 1.309 2.909 2.909 2.909h16c1.6 0 2.909-1.309 2.909-2.909v-20.364c0-1.6-1.309-2.909-2.909-2.909zM26.909 29.091h-16v-20.364h16v20.364z"></path></svg>';
1755
1755
  }
1756
1756
  var playIconHTML = document.getElementById("vditorIconScript")
1757
- ? '<svg><use xlink:href="#vditor-icon-play"></use></svg>'
1757
+ ? '<svg><use xlink:href="#vditor-icon-run"></use></svg>'
1758
1758
  : '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-circle-play-icon lucide-circle-play"><path d="M9 9.003a1 1 0 0 1 1.517-.859l4.997 2.997a1 1 0 0 1 0 1.718l-4.997 2.997A1 1 0 0 1 9 14.996z"/><circle cx="12" cy="12" r="10"/></svg>';
1759
1759
  var divElement = document.createElement("div");
1760
1760
  divElement.className = "vditor-copy";
1761
1761
  var textarea = document.createElement("textarea");
1762
1762
  textarea.value = (0,_util_code160to32__WEBPACK_IMPORTED_MODULE_1__/* .code160to32 */ .X)(codeText);
1763
1763
  divElement.appendChild(textarea);
1764
- if (runHtml === null || runHtml === void 0 ? void 0 : runHtml.enable) {
1764
+ var langMatch = e.className.match(/language-([^\s]+)/);
1765
+ var lang = langMatch ? langMatch[1] : "";
1766
+ var allowRun = !!(runCode === null || runCode === void 0 ? void 0 : runCode.enable) &&
1767
+ (!runCode.items || (lang && runCode.items.includes(lang)));
1768
+ if (allowRun) {
1765
1769
  var runSpan = document.createElement("span");
1766
1770
  runSpan.setAttribute("aria-label", ((_a = window.VditorI18n) === null || _a === void 0 ? void 0 : _a.run) || "运行");
1767
1771
  runSpan.setAttribute("onmouseover", "this.setAttribute('aria-label', '".concat(((_b = window.VditorI18n) === null || _b === void 0 ? void 0 : _b.run) || "运行", "')"));
@@ -1769,10 +1773,12 @@ var codeRender = function (element, option, runHtml) {
1769
1773
  "vditor-copy__item vditor-tooltipped vditor-tooltipped__w";
1770
1774
  runSpan.innerHTML = playIconHTML;
1771
1775
  runSpan.addEventListener("click", function (evt) {
1776
+ var _a;
1772
1777
  evt.stopPropagation();
1773
- if (typeof runHtml.callback === "function") {
1774
- runHtml.callback((0,_util_code160to32__WEBPACK_IMPORTED_MODULE_1__/* .code160to32 */ .X)(codeText));
1775
- }
1778
+ (_a = runCode === null || runCode === void 0 ? void 0 : runCode.callback) === null || _a === void 0 ? void 0 : _a.call(runCode, {
1779
+ code: (0,_util_code160to32__WEBPACK_IMPORTED_MODULE_1__/* .code160to32 */ .X)(codeText),
1780
+ lang: lang,
1781
+ });
1776
1782
  });
1777
1783
  divElement.appendChild(runSpan);
1778
1784
  }
@@ -5143,13 +5149,13 @@ var mergeOptions = function (options) {
5143
5149
  speech: {
5144
5150
  enable: false,
5145
5151
  },
5146
- runHtml: {
5152
+ runCode: {
5147
5153
  enable: false,
5148
5154
  },
5149
5155
  render: {
5150
5156
  media: {
5151
5157
  enable: true,
5152
- }
5158
+ },
5153
5159
  },
5154
5160
  theme: constants/* Constants.THEME_OPTIONS */.g.THEME_OPTIONS,
5155
5161
  };
@@ -5214,12 +5220,27 @@ var previewRender = function (previewElement, markdown, options) { return __awai
5214
5220
  previewElement.innerHTML = html;
5215
5221
  previewElement.classList.add("vditor-reset");
5216
5222
  if (!!mergedOptions.i18n) return [3 /*break*/, 5];
5217
- if (!!["de_DE", "en_US", "es_ES", "fr_FR", "ja_JP", "ko_KR", "pt_BR", "ru_RU", "sv_SE", "vi_VN", "zh_CN", "zh_TW"].includes(mergedOptions.lang)) return [3 /*break*/, 2];
5223
+ if (!![
5224
+ "de_DE",
5225
+ "en_US",
5226
+ "es_ES",
5227
+ "fr_FR",
5228
+ "ja_JP",
5229
+ "ko_KR",
5230
+ "pt_BR",
5231
+ "ru_RU",
5232
+ "sv_SE",
5233
+ "vi_VN",
5234
+ "zh_CN",
5235
+ "zh_TW",
5236
+ ].includes(mergedOptions.lang)) return [3 /*break*/, 2];
5218
5237
  throw new Error("options.lang error, see https://ld246.com/article/1549638745630#options");
5219
5238
  case 2:
5220
5239
  i18nScriptPrefix = "vditorI18nScript";
5221
5240
  i18nScriptID_1 = i18nScriptPrefix + mergedOptions.lang;
5222
- document.querySelectorAll("head script[id^=\"".concat(i18nScriptPrefix, "\"]")).forEach(function (el) {
5241
+ document
5242
+ .querySelectorAll("head script[id^=\"".concat(i18nScriptPrefix, "\"]"))
5243
+ .forEach(function (el) {
5223
5244
  if (el.id !== i18nScriptID_1) {
5224
5245
  document.head.removeChild(el);
5225
5246
  }
@@ -5243,7 +5264,7 @@ var previewRender = function (previewElement, markdown, options) { return __awai
5243
5264
  if (mergedOptions.anchor === 1) {
5244
5265
  previewElement.classList.add("vditor-reset--anchor");
5245
5266
  }
5246
- (0,codeRender/* codeRender */.O)(previewElement, mergedOptions.hljs, mergedOptions.runHtml);
5267
+ (0,codeRender/* codeRender */.O)(previewElement, mergedOptions.hljs, mergedOptions.runCode);
5247
5268
  (0,highlightRender/* highlightRender */.s)(mergedOptions.hljs, previewElement, mergedOptions.cdn);
5248
5269
  (0,mathRender/* mathRender */.H)(previewElement, {
5249
5270
  cdn: mergedOptions.cdn,
@@ -5276,7 +5297,8 @@ var previewRender = function (previewElement, markdown, options) { return __awai
5276
5297
  }
5277
5298
  previewElement.addEventListener("click", function (event) {
5278
5299
  var spanElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(event.target, "SPAN");
5279
- if (spanElement && (0,hasClosest/* hasClosestByClassName */.fb)(spanElement, "vditor-toc")) {
5300
+ if (spanElement &&
5301
+ (0,hasClosest/* hasClosestByClassName */.fb)(spanElement, "vditor-toc")) {
5280
5302
  var headingElement = previewElement.querySelector("#" + spanElement.getAttribute("data-target-id"));
5281
5303
  if (headingElement) {
5282
5304
  window.scrollTo(window.scrollX, headingElement.offsetTop);