@graphql-markdown/docusaurus
Version:
Docusaurus plugin for generating Markdown documentation from a GraphQL schema.
86 lines (85 loc) • 3.89 kB
JavaScript
;
/**
* @module mdx
* This module provides utilities for generating MDX content in Docusaurus format.
* It includes functions for creating badges, admonitions, bullet points, collapsible sections,
* specification links, and other MDX-specific formatting for GraphQL documentation.
*
* @primaryExport
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatMDXLink = exports.formatMDXNameEntity = exports.formatMDXSpecifiedByLink = exports.formatMDXDetails = exports.formatMDXBullet = exports.formatMDXAdmonition = exports.formatMDXBadge = exports.generateIndexMetafile = exports.mdxDeclaration = void 0;
const utils_1 = require("@graphql-markdown/utils");
const MARKDOWN_EOL = "\n";
const MARKDOWN_EOP = `${MARKDOWN_EOL.repeat(2)}`;
const LINK_MDX_EXTENSION = ".mdx";
const DEFAULT_CSS_CLASSNAME = "badge--secondary";
var components_1 = require("./components");
Object.defineProperty(exports, "mdxDeclaration", { enumerable: true, get: function () { return components_1.mdxDeclaration; } });
var category_1 = require("./category");
Object.defineProperty(exports, "generateIndexMetafile", { enumerable: true, get: function () { return category_1.generateIndexMetafile; } });
const formatMDXBadge = ({ text, classname }) => {
const style = typeof classname === "string" ? `badge--${classname.toLowerCase()}` : "";
return `<Badge class="badge ${DEFAULT_CSS_CLASSNAME} ${style}" text="${text}"/>`;
};
exports.formatMDXBadge = formatMDXBadge;
/**
* Formats an admonition block in MDX format
* @param param - The admonition configuration object
* @param meta - Optional metadata for generator configuration
* @returns Formatted MDX string for the admonition
*/
const formatMDXAdmonition = ({ text, title, type }, meta) => {
const isDocusaurus = meta?.generatorFrameworkName === "docusaurus";
if (isDocusaurus && meta.generatorFrameworkVersion?.startsWith("2")) {
const oldType = type === "warning" ? "caution" : type;
return `${MARKDOWN_EOP}:::${oldType} ${title}${text}:::`;
}
return `${MARKDOWN_EOP}:::${type}[${title}]${text}:::`;
};
exports.formatMDXAdmonition = formatMDXAdmonition;
/**
* Creates a bullet point element in MDX format
* @param text - Optional text to append after the bullet point
* @returns Formatted MDX string for the bullet point
*/
const formatMDXBullet = (text = "") => {
return `<Bullet />${text}`;
};
exports.formatMDXBullet = formatMDXBullet;
/**
* Creates a collapsible details section in MDX format
* @param param - The collapsible section configuration
* @returns Formatted MDX string for the collapsible section
*/
const formatMDXDetails = ({ dataOpen, dataClose, }) => {
return `${MARKDOWN_EOP}<Details dataOpen="Hide ${dataOpen}" dataClose="Show ${dataClose}">${MARKDOWN_EOP}\r${MARKDOWN_EOP}</Details>${MARKDOWN_EOP}`;
};
exports.formatMDXDetails = formatMDXDetails;
/**
* Creates a link to the specification documentation
* @param url - The URL to the specification
* @returns Formatted MDX string for the specification link
*/
const formatMDXSpecifiedByLink = (url) => {
return `<SpecifiedBy url="${url}"/>`;
};
exports.formatMDXSpecifiedByLink = formatMDXSpecifiedByLink;
/**
* Formats a name entity with optional parent type
* @param name - The name to format
* @param parentType - Optional parent type to prefix the name
* @returns Formatted MDX string for the name entity
*/
const formatMDXNameEntity = (name, parentType) => {
const parentName = parentType ? `${parentType}.` : "";
return `<code style={{ fontWeight: 'normal' }}>${(0, utils_1.escapeMDX)(parentName)}<b>${(0, utils_1.escapeMDX)(name)}</b></code>`;
};
exports.formatMDXNameEntity = formatMDXNameEntity;
const formatMDXLink = ({ text, url }) => {
return {
text,
url: `${url}${LINK_MDX_EXTENSION}`,
};
};
exports.formatMDXLink = formatMDXLink;