@mryhryki/markdown-preview 0.7.1 → 0.8.1
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 +2 -2
- package/src/index.js +5 -5
- package/src/markdown.js +16 -5
- package/static/convert-markdown.js +2 -2
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.
|
|
4
|
+
"version": "0.8.1",
|
|
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": "^
|
|
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
|
|
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
|
|
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 =
|
|
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
|
-
|
|
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
|
}
|
|
@@ -268027,9 +268027,9 @@ var convertMarkdownToHtml = async (element4, markdown) => {
|
|
|
268027
268027
|
marked2.use({
|
|
268028
268028
|
renderer: {
|
|
268029
268029
|
code: (token2) => {
|
|
268030
|
-
const { lang,
|
|
268030
|
+
const { lang, text: text4 } = token2;
|
|
268031
268031
|
if (lang === "mermaid") {
|
|
268032
|
-
return `<pre class="mermaid">${
|
|
268032
|
+
return `<pre class="mermaid">${text4}</pre>`;
|
|
268033
268033
|
}
|
|
268034
268034
|
return false;
|
|
268035
268035
|
}
|