-
-
Notifications
You must be signed in to change notification settings - Fork 772
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Innei <[email protected]>
- Loading branch information
Showing
6 changed files
with
114 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import clsx from 'clsx' | ||
import { blockRegex, Priority } from 'markdown-to-jsx' | ||
import type { MarkdownToJSX } from 'markdown-to-jsx' | ||
|
||
import { | ||
FluentShieldError20Regular, | ||
FluentWarning28Regular, | ||
IonInformation, | ||
} from '~/components/icons/status' | ||
|
||
import { Markdown } from '../Markdown' | ||
|
||
const textColorMap = { | ||
NOTE: 'text-always-blue-500 dark:text-always-blue-400', | ||
IMPORTANT: 'text-accent', | ||
WARNING: 'text-amber-500 dark:text-amber-400', | ||
} as any | ||
|
||
const borderColorMap = { | ||
NOTE: 'border-always-blue-500 dark:border-always-blue-400', | ||
IMPORTANT: 'border-accent', | ||
WARNING: 'border-amber-500 dark:border-amber-400', | ||
} as any | ||
|
||
const typedIconMap = { | ||
NOTE: IonInformation, | ||
IMPORTANT: FluentWarning28Regular, | ||
WARNING: FluentShieldError20Regular, | ||
} as any | ||
|
||
/** | ||
* | ||
* > [!NOTE] | ||
* > Highlights information that users should take into account, even when skimming. | ||
*/ | ||
const ALERT_BLOCKQUOTE_R = | ||
// /^( *> *\[!(NOTE|IMPORTANT|WARNING)\] *\n(?: *>.*(?:\n|$))+)/m | ||
// /^( *> *\[!(?:(?<type>NOTE|IMPORTANT|WARNING))\](?<body>.*(\n *>.*?)*))(?=\n *> *\[(NOTE|IMPORTANT|WARNING)\]|$)/ | ||
// /^(> *\[!(?<type>NOTE|IMPORTANT|WARNING)\](?<body>(?:\n?.*?)*))((?:\n{2,})|$)/ | ||
// /^*> *\[!(?<type>NOTE|IMPORTANT|WARNING)\](?<body>(?:\n? *>.*?)*?)(?=\n{2,}|$)/ | ||
// /^( *> *\[!(?<type>NOTE|IMPORTANT|WARNING)\].*?(?:\n(?! *> *\[(NOTE|IMPORTANT|WARNING)\]).*?)*)/ | ||
|
||
// /^(> \[!(?<type>NOTE|IMPORTANT|WARNING)\])(?<body>(?:\n? *>.*?(?!\n *> *\[(?:NOTE|IMPORTANT|WARNING)\]))*)/ | ||
/^(> \[!(?<type>NOTE|IMPORTANT|WARNING)\].*?)(?<body>(?:\n *>.*?)*)(?=\n{2,}|$)/ | ||
|
||
export const AlertsRule: MarkdownToJSX.Rule = { | ||
match: blockRegex(ALERT_BLOCKQUOTE_R), | ||
order: Priority.HIGH, | ||
parse(capture) { | ||
return { | ||
raw: capture[0], | ||
parsed: { | ||
...capture.groups, | ||
}, | ||
} | ||
}, | ||
react(node, output, state) { | ||
const { type, body } = node.parsed | ||
const bodyClean = body.replace(/^> */gm, '') | ||
|
||
const typePrefix = type[0] + type.toLowerCase().slice(1) | ||
|
||
const Icon = typedIconMap[type] || typedIconMap.info | ||
return ( | ||
<blockquote className={clsx(borderColorMap[type], 'not-italic')}> | ||
<span | ||
className={clsx( | ||
'text-semibold mb-1 inline-flex items-center', | ||
textColorMap[type], | ||
)} | ||
> | ||
<Icon | ||
className={clsx( | ||
`flex-shrink-0 text-3xl md:mr-2 md:self-start md:text-left`, | ||
typedIconMap[type] || typedIconMap.info, | ||
)} | ||
/> | ||
|
||
{typePrefix} | ||
</span> | ||
<br /> | ||
|
||
<Markdown | ||
allowsScript | ||
className="not-prose w-full [&>p:first-child]:mt-0" | ||
> | ||
{bodyClean} | ||
</Markdown> | ||
</blockquote> | ||
) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1f3d95c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
shiro – ./
shiro-innei.vercel.app
springtide.vercel.app
shiro-git-main-innei.vercel.app
innei.in