Skip to content

Commit fc37a53

Browse files
committed
cleaner support of now deprecated old PluggableList type
1 parent debafc2 commit fc37a53

3 files changed

Lines changed: 431 additions & 15 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
"react-flow-renderer-lts": "npm:react-flow-renderer@^10.3.17",
9696
"react-inlinesvg": "^3.0.3",
9797
"react-markdown": "^10.1.0",
98+
"react-markdown-deprecated": "npm:react-markdown@^8.0.7",
9899
"react-syntax-highlighter": "^15.6.1",
99100
"rehype-external-links": "^3.0.0",
100101
"rehype-raw": "^7.0.0",

src/cmem/markdown/Markdown.tsx

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
import React from "react";
22
import ReactMarkdown from "react-markdown";
3+
/**
4+
* Recreate the old type to provide support until next major
5+
*/
6+
import { PluggableList as PluggableListDeprecated } from "react-markdown-deprecated/lib/react-markdown";
37
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
48
// @ts-ignore: No declaration file for module (TODO: should be @ts-expect-error but GUI elements is used inside project with `noImplicitAny=false`)
59
import remarkTypograf from "@mavrin/remark-typograf";
610
import rehypeExternalLinks from "rehype-external-links";
711
import rehypeRaw from "rehype-raw";
812
import { remarkDefinitionList } from "remark-definition-list";
913
import remarkGfm from "remark-gfm";
10-
import type { PluggableList as UnifiedPluggableList } from "unified";
11-
12-
export type OldPluginTuple = boolean | string | object | Array<OldPluginTuple>;
13-
export type OldPluggable = object | Array<OldPluginTuple>;
14-
15-
export type OldPluggableList = Array<OldPluggable>;
16-
17-
type CompatiblePluggableList = UnifiedPluggableList | OldPluggableList;
14+
import { PluggableList as PluggableListUnified } from "unified";
1815

1916
import { CLASSPREFIX as eccgui } from "../../configuration/constants";
2017
import { HtmlContentBlock, HtmlContentBlockProps, TestableComponent } from "../../index";
18+
type PluggableList = PluggableListUnified | PluggableListDeprecated;
2119

2220
export interface MarkdownProps extends TestableComponent {
2321
children: string;
@@ -45,7 +43,7 @@ export interface MarkdownProps extends TestableComponent {
4543
* @see https://github.com/remarkjs/react-markdown#architecture
4644
* @deprecated (v25) this property won't support `PluggableList` from "react-markdown/lib/react-markdown" with the next major version, only the one from `unified` will be supported then.
4745
*/
48-
reHypePlugins?: CompatiblePluggableList;
46+
reHypePlugins?: PluggableList;
4947
/**
5048
* Name for browser target where links withing the Markdown content are opened.
5149
* Set to `false` to disable this feature.
@@ -63,9 +61,9 @@ const configDefault = {
6361
@see https://github.com/remarkjs/react-markdown#api
6462
*/
6563
// @see https://github.com/remarkjs/remark/blob/main/doc/plugins.md#list-of-plugins
66-
remarkPlugins: [remarkGfm, remarkTypograf, remarkDefinitionList] as UnifiedPluggableList,
64+
remarkPlugins: [remarkGfm, remarkTypograf, remarkDefinitionList] as PluggableListUnified,
6765
// @see https://github.com/rehypejs/rehype/blob/main/doc/plugins.md#list-of-plugins
68-
rehypePlugins: [] as UnifiedPluggableList,
66+
rehypePlugins: [] as PluggableListUnified,
6967
allowedElements: [
7068
// default markdown
7169
"a",
@@ -175,8 +173,8 @@ export const Markdown = ({
175173
};
176174

177175
if (reHypePlugins) {
178-
reHypePlugins.forEach(
179-
(plugin) => (reactMarkdownProperties.rehypePlugins = [...reactMarkdownProperties.rehypePlugins, plugin])
176+
reactMarkdownProperties.rehypePlugins = reactMarkdownProperties.rehypePlugins.concat(
177+
reHypePlugins as PluggableListUnified
180178
);
181179
}
182180

0 commit comments

Comments
 (0)