@mryhryki/markdown-preview 0.7.2 → 0.8.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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mryhryki/markdown-preview",
3
3
  "description": "Markdown realtime preview on browser with your favorite editor",
4
- "version": "0.7.2",
4
+ "version": "0.8.2",
5
5
  "author": "mryhryki",
6
6
  "license": "MIT",
7
7
  "publishConfig": {
@@ -42,7 +42,7 @@
42
42
  "type:watch": "tsc --noEmit --watch"
43
43
  },
44
44
  "dependencies": {
45
- "express": "^4.19.2",
45
+ "express": "^5.0.0",
46
46
  "express-ws": "^5.0.2",
47
47
  "log4js": "^6.9.1",
48
48
  "opener": "^1.5.2",
package/src/index.js CHANGED
@@ -5,14 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const express_1 = __importDefault(require("express"));
7
7
  const express_ws_1 = __importDefault(require("express-ws"));
8
- const serve_index_1 = __importDefault(require("serve-index"));
9
8
  const opener_1 = __importDefault(require("opener"));
9
+ const serve_index_1 = __importDefault(require("serve-index"));
10
+ const directory_1 = require("./lib/directory");
10
11
  const logger_1 = require("./lib/logger");
12
+ const params_1 = require("./lib/params");
11
13
  const show_1 = require("./lib/show");
12
14
  const markdown_1 = require("./markdown");
13
15
  const websocket_1 = require("./websocket");
14
- const directory_1 = require("./lib/directory");
15
- const params_1 = require("./lib/params");
16
16
  try {
17
17
  const params = new params_1.Params(process.env, process.argv.slice(2));
18
18
  if (params.help)
@@ -33,9 +33,9 @@ try {
33
33
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
34
34
  // @ts-ignore
35
35
  app.ws("/ws", (0, websocket_1.WebSocketHandler)(logger));
36
- params.extensions.forEach((ext) => {
36
+ for (const ext of params.extensions) {
37
37
  app.get(new RegExp(`^/.+\.${ext}$`), (0, markdown_1.MarkdownHandler)(params.template));
38
- });
38
+ }
39
39
  app.use(express_1.default.static(directory_1.rootDir, { index: false }));
40
40
  app.use(express_1.default.static(directory_1.staticDir, { index: false }));
41
41
  app.use((0, serve_index_1.default)(directory_1.rootDir, { icons: true, view: "details" }));
package/src/markdown.js CHANGED
@@ -1,20 +1,31 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
13
  };
5
14
  Object.defineProperty(exports, "__esModule", { value: true });
6
15
  exports.MarkdownHandler = MarkdownHandler;
7
- const path_1 = __importDefault(require("path"));
16
+ const promises_1 = __importDefault(require("node:fs/promises"));
17
+ const node_path_1 = __importDefault(require("node:path"));
8
18
  const directory_1 = require("./lib/directory");
9
19
  const file_1 = require("./lib/file");
10
20
  function MarkdownHandler(template) {
11
- return (req, res, next) => {
12
- const filepath = path_1.default.resolve(directory_1.rootDir, decodeURIComponent(req.path.substr(1)));
21
+ return (req, res, next) => __awaiter(this, void 0, void 0, function* () {
22
+ const filepath = node_path_1.default.resolve(directory_1.rootDir, decodeURIComponent(req.path.substring(1)));
13
23
  if ((0, file_1.existsFile)(filepath)) {
14
- res.sendFile(template);
24
+ const templateContent = yield promises_1.default.readFile(template, "utf-8");
25
+ res.status(200).send(templateContent);
15
26
  }
16
27
  else {
17
28
  next();
18
29
  }
19
- };
30
+ });
20
31
  }
@@ -58386,7 +58386,7 @@ var require_purify = __commonJS({
58386
58386
  const mathMl$1 = freeze(["math", "menclose", "merror", "mfenced", "mfrac", "mglyph", "mi", "mlabeledtr", "mmultiscripts", "mn", "mo", "mover", "mpadded", "mphantom", "mroot", "mrow", "ms", "mspace", "msqrt", "mstyle", "msub", "msup", "msubsup", "mtable", "mtd", "mtext", "mtr", "munder", "munderover", "mprescripts"]);
58387
58387
  const mathMlDisallowed = freeze(["maction", "maligngroup", "malignmark", "mlongdiv", "mscarries", "mscarry", "msgroup", "mstack", "msline", "msrow", "semantics", "annotation", "annotation-xml", "mprescripts", "none"]);
58388
58388
  const text4 = freeze(["#text"]);
58389
- const html3 = freeze(["accept", "action", "align", "alt", "autocapitalize", "autocomplete", "autopictureinpicture", "autoplay", "background", "bgcolor", "border", "capture", "cellpadding", "cellspacing", "checked", "cite", "class", "clear", "color", "cols", "colspan", "controls", "controlslist", "coords", "crossorigin", "datetime", "decoding", "default", "dir", "disabled", "disablepictureinpicture", "disableremoteplayback", "download", "draggable", "enctype", "enterkeyhint", "face", "for", "headers", "height", "hidden", "high", "href", "hreflang", "id", "inputmode", "integrity", "ismap", "kind", "label", "lang", "list", "loading", "loop", "low", "max", "maxlength", "media", "method", "min", "minlength", "multiple", "muted", "name", "nonce", "noshade", "novalidate", "nowrap", "open", "optimum", "pattern", "placeholder", "playsinline", "poster", "preload", "pubdate", "radiogroup", "readonly", "rel", "required", "rev", "reversed", "role", "rows", "rowspan", "spellcheck", "scope", "selected", "shape", "size", "sizes", "span", "srclang", "start", "src", "srcset", "step", "style", "summary", "tabindex", "title", "translate", "type", "usemap", "valign", "value", "width", "wrap", "xmlns", "slot"]);
58389
+ const html3 = freeze(["accept", "action", "align", "alt", "autocapitalize", "autocomplete", "autopictureinpicture", "autoplay", "background", "bgcolor", "border", "capture", "cellpadding", "cellspacing", "checked", "cite", "class", "clear", "color", "cols", "colspan", "controls", "controlslist", "coords", "crossorigin", "datetime", "decoding", "default", "dir", "disabled", "disablepictureinpicture", "disableremoteplayback", "download", "draggable", "enctype", "enterkeyhint", "face", "for", "headers", "height", "hidden", "high", "href", "hreflang", "id", "inputmode", "integrity", "ismap", "kind", "label", "lang", "list", "loading", "loop", "low", "max", "maxlength", "media", "method", "min", "minlength", "multiple", "muted", "name", "nonce", "noshade", "novalidate", "nowrap", "open", "optimum", "pattern", "placeholder", "playsinline", "popover", "popovertarget", "popovertargetaction", "poster", "preload", "pubdate", "radiogroup", "readonly", "rel", "required", "rev", "reversed", "role", "rows", "rowspan", "spellcheck", "scope", "selected", "shape", "size", "sizes", "span", "srclang", "start", "src", "srcset", "step", "style", "summary", "tabindex", "title", "translate", "type", "usemap", "valign", "value", "width", "wrap", "xmlns", "slot"]);
58390
58390
  const svg2 = freeze(["accent-height", "accumulate", "additive", "alignment-baseline", "ascent", "attributename", "attributetype", "azimuth", "basefrequency", "baseline-shift", "begin", "bias", "by", "class", "clip", "clippathunits", "clip-path", "clip-rule", "color", "color-interpolation", "color-interpolation-filters", "color-profile", "color-rendering", "cx", "cy", "d", "dx", "dy", "diffuseconstant", "direction", "display", "divisor", "dur", "edgemode", "elevation", "end", "fill", "fill-opacity", "fill-rule", "filter", "filterunits", "flood-color", "flood-opacity", "font-family", "font-size", "font-size-adjust", "font-stretch", "font-style", "font-variant", "font-weight", "fx", "fy", "g1", "g2", "glyph-name", "glyphref", "gradientunits", "gradienttransform", "height", "href", "id", "image-rendering", "in", "in2", "k", "k1", "k2", "k3", "k4", "kerning", "keypoints", "keysplines", "keytimes", "lang", "lengthadjust", "letter-spacing", "kernelmatrix", "kernelunitlength", "lighting-color", "local", "marker-end", "marker-mid", "marker-start", "markerheight", "markerunits", "markerwidth", "maskcontentunits", "maskunits", "max", "mask", "media", "method", "mode", "min", "name", "numoctaves", "offset", "operator", "opacity", "order", "orient", "orientation", "origin", "overflow", "paint-order", "path", "pathlength", "patterncontentunits", "patterntransform", "patternunits", "points", "preservealpha", "preserveaspectratio", "primitiveunits", "r", "rx", "ry", "radius", "refx", "refy", "repeatcount", "repeatdur", "restart", "result", "rotate", "scale", "seed", "shape-rendering", "specularconstant", "specularexponent", "spreadmethod", "startoffset", "stddeviation", "stitchtiles", "stop-color", "stop-opacity", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke", "stroke-width", "style", "surfacescale", "systemlanguage", "tabindex", "targetx", "targety", "transform", "transform-origin", "text-anchor", "text-decoration", "text-rendering", "textlength", "type", "u1", "u2", "unicode", "values", "viewbox", "visibility", "version", "vert-adv-y", "vert-origin-x", "vert-origin-y", "width", "word-spacing", "wrap", "writing-mode", "xchannelselector", "ychannelselector", "x", "x1", "x2", "xmlns", "y", "y1", "y2", "z", "zoomandpan"]);
58391
58391
  const mathMl = freeze(["accent", "accentunder", "align", "bevelled", "close", "columnsalign", "columnlines", "columnspan", "denomalign", "depth", "dir", "display", "displaystyle", "encoding", "fence", "frame", "height", "href", "id", "largeop", "length", "linethickness", "lspace", "lquote", "mathbackground", "mathcolor", "mathsize", "mathvariant", "maxsize", "minsize", "movablelimits", "notation", "numalign", "open", "rowalign", "rowlines", "rowspacing", "rowspan", "rspace", "rquote", "scriptlevel", "scriptminsize", "scriptsizemultiplier", "selection", "separator", "separators", "stretchy", "subscriptshift", "supscriptshift", "symmetric", "voffset", "width", "xmlns"]);
58392
58392
  const xml = freeze(["xlink:href", "xml:id", "xlink:title", "xml:space", "xmlns:xlink"]);
@@ -58419,6 +58419,23 @@ var require_purify = __commonJS({
58419
58419
  DOCTYPE_NAME,
58420
58420
  CUSTOM_ELEMENT
58421
58421
  });
58422
+ const NODE_TYPE = {
58423
+ element: 1,
58424
+ attribute: 2,
58425
+ text: 3,
58426
+ cdataSection: 4,
58427
+ entityReference: 5,
58428
+ // Deprecated
58429
+ entityNode: 6,
58430
+ // Deprecated
58431
+ progressingInstruction: 7,
58432
+ comment: 8,
58433
+ document: 9,
58434
+ documentType: 10,
58435
+ documentFragment: 11,
58436
+ notation: 12
58437
+ // Deprecated
58438
+ };
58422
58439
  const getGlobal = function getGlobal2() {
58423
58440
  return typeof window === "undefined" ? null : window;
58424
58441
  };
@@ -58449,9 +58466,9 @@ var require_purify = __commonJS({
58449
58466
  function createDOMPurify() {
58450
58467
  let window3 = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : getGlobal();
58451
58468
  const DOMPurify2 = (root4) => createDOMPurify(root4);
58452
- DOMPurify2.version = "3.1.2";
58469
+ DOMPurify2.version = "3.1.6";
58453
58470
  DOMPurify2.removed = [];
58454
- if (!window3 || !window3.document || window3.document.nodeType !== 9) {
58471
+ if (!window3 || !window3.document || window3.document.nodeType !== NODE_TYPE.document) {
58455
58472
  DOMPurify2.isSupported = false;
58456
58473
  return DOMPurify2;
58457
58474
  }
@@ -58473,6 +58490,7 @@ var require_purify = __commonJS({
58473
58490
  } = window3;
58474
58491
  const ElementPrototype = Element3.prototype;
58475
58492
  const cloneNode = lookupGetter(ElementPrototype, "cloneNode");
58493
+ const remove3 = lookupGetter(ElementPrototype, "remove");
58476
58494
  const getNextSibling = lookupGetter(ElementPrototype, "nextSibling");
58477
58495
  const getChildNodes = lookupGetter(ElementPrototype, "childNodes");
58478
58496
  const getParentNode = lookupGetter(ElementPrototype, "parentNode");
@@ -58570,7 +58588,6 @@ var require_purify = __commonJS({
58570
58588
  const DEFAULT_PARSER_MEDIA_TYPE = "text/html";
58571
58589
  let transformCaseFunc = null;
58572
58590
  let CONFIG = null;
58573
- const MAX_NESTING_DEPTH = 255;
58574
58591
  const formElement = document4.createElement("form");
58575
58592
  const isRegexOrFunction = function isRegexOrFunction2(testValue) {
58576
58593
  return testValue instanceof RegExp || testValue instanceof Function;
@@ -58774,9 +58791,9 @@ var require_purify = __commonJS({
58774
58791
  element: node3
58775
58792
  });
58776
58793
  try {
58777
- node3.parentNode.removeChild(node3);
58794
+ getParentNode(node3).removeChild(node3);
58778
58795
  } catch (_) {
58779
- node3.remove();
58796
+ remove3(node3);
58780
58797
  }
58781
58798
  };
58782
58799
  const _removeAttribute = function _removeAttribute2(name, node3) {
@@ -58851,9 +58868,7 @@ var require_purify = __commonJS({
58851
58868
  );
58852
58869
  };
58853
58870
  const _isClobbered = function _isClobbered2(elm) {
58854
- return elm instanceof HTMLFormElement && // eslint-disable-next-line unicorn/no-typeof-undefined
58855
- (typeof elm.__depth !== "undefined" && typeof elm.__depth !== "number" || // eslint-disable-next-line unicorn/no-typeof-undefined
58856
- typeof elm.__removalCount !== "undefined" && typeof elm.__removalCount !== "number" || typeof elm.nodeName !== "string" || typeof elm.textContent !== "string" || typeof elm.removeChild !== "function" || !(elm.attributes instanceof NamedNodeMap) || typeof elm.removeAttribute !== "function" || typeof elm.setAttribute !== "function" || typeof elm.namespaceURI !== "string" || typeof elm.insertBefore !== "function" || typeof elm.hasChildNodes !== "function");
58871
+ return elm instanceof HTMLFormElement && (typeof elm.nodeName !== "string" || typeof elm.textContent !== "string" || typeof elm.removeChild !== "function" || !(elm.attributes instanceof NamedNodeMap) || typeof elm.removeAttribute !== "function" || typeof elm.setAttribute !== "function" || typeof elm.namespaceURI !== "string" || typeof elm.insertBefore !== "function" || typeof elm.hasChildNodes !== "function");
58857
58872
  };
58858
58873
  const _isNode = function _isNode2(object3) {
58859
58874
  return typeof Node === "function" && object3 instanceof Node;
@@ -58882,11 +58897,11 @@ var require_purify = __commonJS({
58882
58897
  _forceRemove(currentNode);
58883
58898
  return true;
58884
58899
  }
58885
- if (currentNode.nodeType === 7) {
58900
+ if (currentNode.nodeType === NODE_TYPE.progressingInstruction) {
58886
58901
  _forceRemove(currentNode);
58887
58902
  return true;
58888
58903
  }
58889
- if (SAFE_FOR_XML && currentNode.nodeType === 8 && regExpTest(/<[/\w]/g, currentNode.data)) {
58904
+ if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(/<[/\w]/g, currentNode.data)) {
58890
58905
  _forceRemove(currentNode);
58891
58906
  return true;
58892
58907
  }
@@ -58922,7 +58937,7 @@ var require_purify = __commonJS({
58922
58937
  _forceRemove(currentNode);
58923
58938
  return true;
58924
58939
  }
58925
- if (SAFE_FOR_TEMPLATES && currentNode.nodeType === 3) {
58940
+ if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
58926
58941
  content3 = currentNode.textContent;
58927
58942
  arrayForEach([MUSTACHE_EXPR2, ERB_EXPR2, TMPLIT_EXPR2], (expr) => {
58928
58943
  content3 = stringReplace(content3, expr, " ");
@@ -58997,6 +59012,10 @@ var require_purify = __commonJS({
58997
59012
  hookEvent.forceKeepAttr = void 0;
58998
59013
  _executeHook("uponSanitizeAttribute", currentNode, hookEvent);
58999
59014
  value2 = hookEvent.attrValue;
59015
+ if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|title)/i, value2)) {
59016
+ _removeAttribute(name, currentNode);
59017
+ continue;
59018
+ }
59000
59019
  if (hookEvent.forceKeepAttr) {
59001
59020
  continue;
59002
59021
  }
@@ -59042,7 +59061,11 @@ var require_purify = __commonJS({
59042
59061
  } else {
59043
59062
  currentNode.setAttribute(name, value2);
59044
59063
  }
59045
- arrayPop(DOMPurify2.removed);
59064
+ if (_isClobbered(currentNode)) {
59065
+ _forceRemove(currentNode);
59066
+ } else {
59067
+ arrayPop(DOMPurify2.removed);
59068
+ }
59046
59069
  } catch (_) {
59047
59070
  }
59048
59071
  }
@@ -59057,19 +59080,7 @@ var require_purify = __commonJS({
59057
59080
  if (_sanitizeElements(shadowNode)) {
59058
59081
  continue;
59059
59082
  }
59060
- const parentNode = getParentNode(shadowNode);
59061
- if (shadowNode.nodeType === 1) {
59062
- if (parentNode && parentNode.__depth) {
59063
- shadowNode.__depth = (shadowNode.__removalCount || 0) + parentNode.__depth + 1;
59064
- } else {
59065
- shadowNode.__depth = 1;
59066
- }
59067
- }
59068
- if (shadowNode.__depth >= MAX_NESTING_DEPTH) {
59069
- _forceRemove(shadowNode);
59070
- }
59071
59083
  if (shadowNode.content instanceof DocumentFragment2) {
59072
- shadowNode.content.__depth = shadowNode.__depth;
59073
59084
  _sanitizeShadowDOM2(shadowNode.content);
59074
59085
  }
59075
59086
  _sanitizeAttributes(shadowNode);
@@ -59116,7 +59127,7 @@ var require_purify = __commonJS({
59116
59127
  } else if (dirty instanceof Node) {
59117
59128
  body = _initDocument("<!---->");
59118
59129
  importedNode = body.ownerDocument.importNode(dirty, true);
59119
- if (importedNode.nodeType === 1 && importedNode.nodeName === "BODY") {
59130
+ if (importedNode.nodeType === NODE_TYPE.element && importedNode.nodeName === "BODY") {
59120
59131
  body = importedNode;
59121
59132
  } else if (importedNode.nodeName === "HTML") {
59122
59133
  body = importedNode;
@@ -59141,19 +59152,7 @@ var require_purify = __commonJS({
59141
59152
  if (_sanitizeElements(currentNode)) {
59142
59153
  continue;
59143
59154
  }
59144
- const parentNode = getParentNode(currentNode);
59145
- if (currentNode.nodeType === 1) {
59146
- if (parentNode && parentNode.__depth) {
59147
- currentNode.__depth = (currentNode.__removalCount || 0) + parentNode.__depth + 1;
59148
- } else {
59149
- currentNode.__depth = 1;
59150
- }
59151
- }
59152
- if (currentNode.__depth >= MAX_NESTING_DEPTH) {
59153
- _forceRemove(currentNode);
59154
- }
59155
59155
  if (currentNode.content instanceof DocumentFragment2) {
59156
- currentNode.content.__depth = currentNode.__depth;
59157
59156
  _sanitizeShadowDOM(currentNode.content);
59158
59157
  }
59159
59158
  _sanitizeAttributes(currentNode);
@@ -268044,7 +268043,7 @@ export {
268044
268043
  /*! Bundled license information:
268045
268044
 
268046
268045
  dompurify/dist/purify.js:
268047
- (*! @license DOMPurify 3.1.2 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.1.2/LICENSE *)
268046
+ (*! @license DOMPurify 3.1.6 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.1.6/LICENSE *)
268048
268047
 
268049
268048
  lodash-es/lodash.js:
268050
268049
  (**