fumadocs-typescript
Version:
Typescript Integration for Fumadocs
133 lines (129 loc) • 3.67 kB
JavaScript
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __objRest = (source, exclude) => {
var target = {};
for (var prop in source)
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
target[prop] = source[prop];
if (source != null && __getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(source)) {
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
target[prop] = source[prop];
}
return target;
};
var __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};
// src/markdown.ts
import { remark } from "remark";
import {
rehypeCode,
remarkGfm
} from "fumadocs-core/mdx-plugins";
import remarkRehype from "remark-rehype";
import { highlightHast } from "fumadocs-core/highlight";
var shikiOptions = {
lazy: true,
themes: {
light: "github-light",
dark: "github-dark"
}
};
var processor = remark().use(remarkGfm).use(remarkRehype).use(rehypeCode, shikiOptions);
function renderTypeToHast(type) {
return __async(this, null, function* () {
const nodes = yield highlightHast(type, __spreadProps(__spreadValues({}, shikiOptions), {
lang: "ts",
structure: "inline"
}));
return {
type: "element",
tagName: "span",
properties: {
class: "shiki"
},
children: [
{
type: "element",
tagName: "code",
properties: {},
children: nodes.children
}
]
};
});
}
function renderMarkdownToHast(md) {
return __async(this, null, function* () {
md = md.replace(new RegExp("{@link (?<link>[^}]*)}", "g"), "$1");
return processor.run(processor.parse(md));
});
}
// src/lib/parse-tags.ts
function parseTags(tags) {
var _a;
const typed = {};
for (const { name: key, text } of tags) {
if (key === "default" || key === "defaultValue") {
typed.default = text;
continue;
}
if (key === "param") {
const [param, description] = text.split("-", 2);
(_a = typed.params) != null ? _a : typed.params = [];
typed.params.push({
name: param.trim(),
description: description.trim()
});
continue;
}
if (key === "returns") {
typed.returns = text;
}
}
return typed;
}
export {
__spreadValues,
__spreadProps,
__objRest,
__async,
renderTypeToHast,
renderMarkdownToHast,
parseTags
};