diff --git a/core/README.md b/core/README.md index 4bf69e58..011e1a8f 100644 --- a/core/README.md +++ b/core/README.md @@ -21,6 +21,7 @@ React component preview markdown text in web browser. The minimal amount of CSS - 🍭 Support automatic code block highlight. - 🐝 Support for defining styles via comment. - ⛳️ Support for [GFM footnotes](https://github.blog/changelog/2021-09-30-footnotes-now-supported-in-markdown-fields/) +- ⛳️ Support for [Github Alert](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#alerts) ## Quick Start @@ -609,6 +610,39 @@ Output:

Good!

``` +### Support for Github Alerts + +```jsx mdx:preview&checkered=0 +import React from 'react'; +import MarkdownPreview from '@uiw/react-markdown-preview'; + +const source = `> +> +> [!NOTE] +> Useful information that users should know, even when skimming content. + +> [!TIP] +> Helpful advice for doing things better or more easily. + +> [!IMPORTANT] +> Key information users need to know to achieve their goal. + +> [!WARNING] +> Urgent info that needs immediate user attention to avoid problems. + +> [!CAUTION] +> Advises about risks or negative outcomes of certain actions. + + +`; + +export default function Demo() { + return ( + + ) +} +``` + ## Support dark-mode/night-mode By default, the [`dark-mode`](https://github.com/jaywcjlove/dark-mode/) is automatically switched according to the system. If you need to switch manually, just set the `data-color-mode="dark"` parameter for body. diff --git a/core/package.json b/core/package.json index 2c82adee..6ee95ff6 100644 --- a/core/package.json +++ b/core/package.json @@ -1,6 +1,6 @@ { "name": "@uiw/react-markdown-preview", - "version": "5.0.10", + "version": "5.1.0", "description": "React component preview markdown text in web browser. The minimal amount of CSS to replicate the GitHub Markdown style.", "homepage": "https://uiwjs.github.io/react-markdown-preview", "funding": "https://jaywcjlove.github.io/#/sponsor", @@ -66,6 +66,7 @@ "rehype-rewrite": "~4.0.0", "rehype-slug": "~6.0.0", "remark-gfm": "~4.0.0", + "remark-github-blockquote-alert": "^1.0.0", "unist-util-visit": "^5.0.0" } } diff --git a/core/src/Props.tsx b/core/src/Props.tsx index 3d4c417b..ac09f1f3 100644 --- a/core/src/Props.tsx +++ b/core/src/Props.tsx @@ -1,6 +1,6 @@ import { type Options } from 'react-markdown'; import { type RehypeRewriteOptions } from 'rehype-rewrite'; -import { PluggableList } from 'unified'; +import { type PluggableList } from 'unified'; export interface MarkdownPreviewProps extends Omit { prefixCls?: string; diff --git a/core/src/index.tsx b/core/src/index.tsx index 12cbdc87..00636412 100644 --- a/core/src/index.tsx +++ b/core/src/index.tsx @@ -1,10 +1,10 @@ import React from 'react'; -import MarkdownPreview from './preview'; import rehypePrism from 'rehype-prism-plus'; -import { PluggableList } from 'unified'; +import type { PluggableList } from 'unified'; import rehypeRewrite from 'rehype-rewrite'; import rehypeAttrs from 'rehype-attr'; import rehypeRaw from 'rehype-raw'; +import MarkdownPreview from './preview'; import { reservedMeta } from './plugins/reservedMeta'; import { retrieveMeta } from './plugins/retrieveMeta'; import { rehypeRewriteHandle, defaultRehypePlugins } from './rehypePlugins'; diff --git a/core/src/nodes/copy.ts b/core/src/nodes/copy.ts index bd751642..7058d96a 100644 --- a/core/src/nodes/copy.ts +++ b/core/src/nodes/copy.ts @@ -1,4 +1,4 @@ -import { Element } from 'hast'; +import type { Element } from 'hast'; export function copyElement(str: string = ''): Element { return { diff --git a/core/src/nodes/octiconLink.ts b/core/src/nodes/octiconLink.ts index f635be9d..af93b313 100644 --- a/core/src/nodes/octiconLink.ts +++ b/core/src/nodes/octiconLink.ts @@ -1,4 +1,4 @@ -import { Element } from 'hast'; +import type { Element } from 'hast'; export const octiconLink: Element = { type: 'element', diff --git a/core/src/nohighlight.tsx b/core/src/nohighlight.tsx index 001d581f..16b5a9cc 100644 --- a/core/src/nohighlight.tsx +++ b/core/src/nohighlight.tsx @@ -1,11 +1,11 @@ import React from 'react'; import MarkdownPreview from './preview'; -import { PluggableList } from 'unified'; +import { type PluggableList } from 'unified'; import rehypeRewrite from 'rehype-rewrite'; -import { reservedMeta } from './plugins/reservedMeta'; -import { retrieveMeta } from './plugins/retrieveMeta'; import rehypeAttrs from 'rehype-attr'; import rehypeRaw from 'rehype-raw'; +import { reservedMeta } from './plugins/reservedMeta'; +import { retrieveMeta } from './plugins/retrieveMeta'; import { rehypeRewriteHandle, defaultRehypePlugins } from './rehypePlugins'; import type { MarkdownPreviewProps, MarkdownPreviewRef } from './Props'; diff --git a/core/src/plugins/reservedMeta.ts b/core/src/plugins/reservedMeta.ts index fab2b1c6..efa9e86d 100644 --- a/core/src/plugins/reservedMeta.ts +++ b/core/src/plugins/reservedMeta.ts @@ -1,4 +1,4 @@ -import { Plugin } from 'unified'; +import type { Plugin } from 'unified'; import { Root, RootContent } from 'hast'; import { visit } from 'unist-util-visit'; diff --git a/core/src/plugins/retrieveMeta.ts b/core/src/plugins/retrieveMeta.ts index f0b216fa..c8f0e7e7 100644 --- a/core/src/plugins/retrieveMeta.ts +++ b/core/src/plugins/retrieveMeta.ts @@ -1,5 +1,5 @@ -import { Plugin } from 'unified'; -import { Root, RootContent } from 'hast'; +import type { Plugin } from 'unified'; +import type { Root, RootContent } from 'hast'; import { visit } from 'unist-util-visit'; export interface RetrieveMetaOptions {} diff --git a/core/src/preview.tsx b/core/src/preview.tsx index 5294a6b6..f195d804 100644 --- a/core/src/preview.tsx +++ b/core/src/preview.tsx @@ -1,8 +1,9 @@ import React, { useImperativeHandle } from 'react'; -import ReactMarkdown, { UrlTransform } from 'react-markdown'; -import { PluggableList } from 'unified'; +import ReactMarkdown, { type UrlTransform } from 'react-markdown'; +import { type PluggableList } from 'unified'; import gfm from 'remark-gfm'; import raw from 'rehype-raw'; +import { remarkAlert } from 'remark-github-blockquote-alert'; import { useCopied } from './plugins/useCopied'; import { type MarkdownPreviewProps, type MarkdownPreviewRef } from './Props'; import './styles/markdown.less'; @@ -33,7 +34,6 @@ export default React.forwardRef((props useImperativeHandle(ref, () => ({ ...props, mdp }), [mdp, props]); const cls = `${prefixCls || ''} ${className || ''}`; useCopied(mdp); - const rehypePlugins: PluggableList = [...(other.rehypePlugins || [])]; const customProps: MarkdownPreviewProps = { allowElement: (element, index, parent) => { @@ -46,7 +46,7 @@ export default React.forwardRef((props if (skipHtml) { rehypePlugins.push(raw); } - const remarkPlugins = [...(other.remarkPlugins || []), gfm]; + const remarkPlugins = [remarkAlert, ...(other.remarkPlugins || []), gfm]; const wrapperProps = { ...warpperElement, ...wrapperElement }; return (
diff --git a/core/src/rehypePlugins.tsx b/core/src/rehypePlugins.tsx index 0f631d5a..680ce6aa 100644 --- a/core/src/rehypePlugins.tsx +++ b/core/src/rehypePlugins.tsx @@ -1,11 +1,11 @@ -import { PluggableList } from 'unified'; +import type { PluggableList } from 'unified'; import slug from 'rehype-slug'; import headings from 'rehype-autolink-headings'; import rehypeIgnore from 'rehype-ignore'; -import { getCodeString, RehypeRewriteOptions } from 'rehype-rewrite'; +import { getCodeString, type RehypeRewriteOptions } from 'rehype-rewrite'; +import type { Root, Element, RootContent } from 'hast'; import { octiconLink } from './nodes/octiconLink'; import { copyElement } from './nodes/copy'; -import { Root, Element, RootContent } from 'hast'; export const rehypeRewriteHandle = (disableCopy: boolean, rewrite?: RehypeRewriteOptions['rewrite']) => diff --git a/core/src/styles/markdown.less b/core/src/styles/markdown.less index 3d3fd0dc..cf111f35 100644 --- a/core/src/styles/markdown.less +++ b/core/src/styles/markdown.less @@ -44,6 +44,13 @@ --color-accent-emphasis: #1f6feb; --color-attention-subtle: rgba(187, 128, 9, 0.15); --color-danger-fg: #f85149; + --color-danger-emphasis: #da3633; + --color-attention-fg: #d29922; + --color-attention-emphasis: #9e6a03; + --color-done-fg: #a371f7; + --color-done-emphasis: #8957e5; + --color-success-fg: #3fb950; + --color-success-emphasis: #238636; --color-copied-active-bg: #2e9b33; } } @@ -93,7 +100,14 @@ --color-accent-fg: #0969da; --color-accent-emphasis: #0969da; --color-attention-subtle: #fff8c5; - --color-danger-fg: #cf222e; + --color-danger-fg: #d1242f; + --color-danger-emphasis: #cf222e; + --color-attention-fg: #9a6700; + --color-attention-emphasis: #9a6700; + --color-done-fg: #8250df; + --color-done-emphasis: #8250df; + --color-success-fg: #1a7f37; + --color-success-emphasis: #1f883d; --color-copied-active-bg: #2e9b33; } } @@ -1053,6 +1067,59 @@ body[data-color-mode*='light'] { } } +.wmde-markdown { + .markdown-alert { + padding: 0.5rem 1em; + color: inherit; + margin-bottom: 16px; + border-left: 0.25em solid var(--borderColor-default, var(--color-border-default)); + > :last-child { + margin-bottom: 0 !important; + } + .markdown-alert-title { + display: flex; + align-items: center; + line-height: 1; + font-weight: 600; + font-family: initial; + font-size: 14px; + svg.octicon { + margin-right: var(--base-size-8, 8px) !important; + } + } + &.markdown-alert-note { + border-left-color: var(--borderColor-accent-emphasis, var(--color-accent-emphasis)); + .markdown-alert-title { + color: var(--fgColor-accent, var(--color-accent-fg)); + } + } + &.markdown-alert-tip { + border-left-color: var(--borderColor-success-emphasis, var(--color-success-emphasis)); + .markdown-alert-title { + color: var(--fgColor-success, var(--color-success-fg)); + } + } + &.markdown-alert-important { + border-left-color: var(--borderColor-done-emphasis, var(--color-done-emphasis)); + .markdown-alert-title { + color: var(--fgColor-done, var(--color-done-fg)); + } + } + &.markdown-alert-warning { + border-left-color: var(--borderColor-attention-emphasis, var(--color-attention-emphasis)); + .markdown-alert-title { + color: var(--fgColor-attention, var(--color-attention-fg)); + } + } + &.markdown-alert-caution { + border-left-color: var(--borderColor-danger-emphasis, var(--color-danger-emphasis)); + .markdown-alert-title { + color: var(--fgColor-danger, var(--color-danger-fg)); + } + } + } +} + .wmde-markdown { .highlight-line { background-color: var(--color-neutral-muted); diff --git a/lerna.json b/lerna.json index 7632bad7..2159daaf 100644 --- a/lerna.json +++ b/lerna.json @@ -1,4 +1,4 @@ { - "version": "5.0.10", + "version": "5.1.0", "packages": ["core", "website"] }