UNPKG

nix-api

Version:

<div align="center"> <img src="./docs/.vuepress/public/images/logo.png" width="200px"> </div>

78 lines (59 loc) 4.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _fs = _interopRequireDefault(require("fs")); var _marked = _interopRequireDefault(require("marked")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } var MarkdownModule = /*#__PURE__*/ function () { function MarkdownModule() { _classCallCheck(this, MarkdownModule); this.accept = /md/g; } _createClass(MarkdownModule, [{ key: "getResponseHTML", value: function getResponseHTML(content) { return "\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n <html>\n <head>\n <link rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/3.0.1/github-markdown.css\">\n <link rel=\"stylesheet\" href=\"//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/styles/default.min.css\">\n\n <style>\n body {\n box-sizing: border-box;\n min-width: 200px;\n max-width: 980px;\n margin: 0 auto;\n padding: 45px;\n }\n </style>\n </head>\n <body class=\"markdown-body\">\n ".concat((0, _marked.default)(content), "\n <script src=\"//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/highlight.min.js\"></script>\n <script>hljs.initHighlightingOnLoad();</script>\n </body>\n </html>\n "); } }, { key: "resolve", value: function () { var _resolve = _asyncToGenerator( /*#__PURE__*/ regeneratorRuntime.mark(function _callee(filepath, _ref) { var req, res, content; return regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: req = _ref.req, res = _ref.res; _context.next = 3; return _fs.default.readFileSync(filepath); case 3: content = _context.sent; res.send(this.getResponseHTML(content.toString())); case 5: case "end": return _context.stop(); } } }, _callee, this); })); function resolve(_x, _x2) { return _resolve.apply(this, arguments); } return resolve; }() }]); return MarkdownModule; }(); var _default = new MarkdownModule(); exports.default = _default;