UNPKG

nexpi-ui

Version:

An elegant and minimalist Next.js 14 component library

71 lines 3.36 kB
import { __awaiter, __generator } from "tslib"; import React from 'react'; import Markdown from './Markdown'; import CodeBlock from './Codeblock'; import hljs from 'highlight.js'; import Box from './Box'; var Documentation = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) { var elaborateText, res, data, doc; var path = _b.path, id = _b.id, children = _b.children; return __generator(this, function (_c) { switch (_c.label) { case 0: elaborateText = function (text) { var splitDocCodeString = '```'; var crunchs = text.split(splitDocCodeString); var indexLine = 0; var supportedLanguages = hljs.listLanguages(); supportedLanguages.push('inline'); var newDoc = crunchs.map(function (item, index) { var tmp = supportedLanguages.find(function (elem) { return elem === crunchs[index].split('\n')[0].trim(); }); if (tmp !== undefined) { var arrayTmp = item.split(tmp); if (tmp === 'inline') { var tmpIndex = indexLine; indexLine += 1; return { payload: '', docType: 2, lang: '', indexInline: tmpIndex }; } return { payload: arrayTmp.slice(1).join(tmp), docType: 1, lang: tmp }; } return { payload: item, docType: 0, lang: '' }; }); return newDoc; }; return [4 /*yield*/, fetch(path)]; case 1: res = _c.sent(); return [4 /*yield*/, res.text()]; case 2: data = _c.sent(); doc = elaborateText(data); return [2 /*return*/, (React.createElement(Box, { id: id }, doc.map(function (item, index) { switch (item.docType) { case 1: return React.createElement(CodeBlock, { key: index, language: item.lang, value: item.payload }); case 0: return (React.createElement("div", { key: index, style: { color: 'var(--nxp-primary-color)' } }, React.createElement(Markdown, null, item.payload))); case 2: return React.createElement(React.Fragment, null, children && item.indexInline !== undefined ? children[item.indexInline] : null); default: return null; } })))]; } }); }); }; export default Documentation; //# sourceMappingURL=Documentation.js.map