UNPKG

@lobehub/ui

Version:

Lobe UI is an open-source UI component library for building AIGC web apps

33 lines (32 loc) 2.84 kB
'use client'; function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } import { useMemo } from 'react'; import { rehypeGithubAlerts } from 'rehype-github-alerts'; import rehypeKatex from 'rehype-katex'; import rehypeRaw from 'rehype-raw'; import { useMarkdownContext } from "../../Markdown/components/MarkdownProvider"; import { animatedPlugin } from "../../Markdown/plugins/animated"; import { rehypeFootnoteLinks } from "../../Markdown/plugins/footnote"; import { rehypeKatexDir } from "../../Markdown/plugins/katexDir"; export var useMarkdownRehypePlugins = function useMarkdownRehypePlugins() { var _useMarkdownContext = useMarkdownContext(), animated = _useMarkdownContext.animated, enableLatex = _useMarkdownContext.enableLatex, enableCustomFootnotes = _useMarkdownContext.enableCustomFootnotes, allowHtml = _useMarkdownContext.allowHtml, _useMarkdownContext$r = _useMarkdownContext.rehypePlugins, rehypePlugins = _useMarkdownContext$r === void 0 ? [] : _useMarkdownContext$r, _useMarkdownContext$r2 = _useMarkdownContext.rehypePluginsAhead, rehypePluginsAhead = _useMarkdownContext$r2 === void 0 ? [] : _useMarkdownContext$r2; var memoPlugins = useMemo(function () { return [rehypeGithubAlerts, allowHtml && rehypeRaw, enableLatex && rehypeKatex, enableLatex && rehypeKatexDir, enableCustomFootnotes && rehypeFootnoteLinks, animated && animatedPlugin].filter(Boolean); }, [animated, enableLatex, enableCustomFootnotes, allowHtml]); return useMemo(function () { return [].concat(_toConsumableArray(rehypePluginsAhead), _toConsumableArray(memoPlugins), _toConsumableArray(rehypePlugins)); }, [rehypePlugins, memoPlugins, rehypePluginsAhead]); };