Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Without a type and a title feature not working #6

Open
JoinChang opened this issue Jul 26, 2024 · 1 comment
Open

Without a type and a title feature not working #6

JoinChang opened this issue Jul 26, 2024 · 1 comment

Comments

@JoinChang
Copy link

This feature is not working properly: https://github.com/ipikuka/remark-flexible-containers?tab=readme-ov-file#without-a-type-and-a-title

Browser console:
image

Markdown file:

:::
手动创建错误成绩,或是通过其他方式导入了错误成绩,均会导致查分器计算出的 Best 50 与玩家 DX Rating 不一致。
:::

Source code:

const Content = ({ markdown }: { markdown: string }) => {
  const navigate = useNavigate();

  return (
    <Markdown
      remarkPlugins={[remarkGfm, remarkFlexibleContainers]}
      rehypePlugins={[
        rehypeSlug,
        [rehypeAutolinkHeadings, {
          behavior: 'wrap',
          properties: {
            className: classes.sectionHeading,
          },
        }]
      ]}
      components={{
...
        div({ className, children, ...props }) {
          const classesName = className ? className.split(" ") : [];

          if (classesName.includes("remark-container")) {
            let icon = <IconInfoCircle />;
            let color = "blue";
            if (classesName.includes("warning")) {
              icon = <IconAlertCircle />;
              color = "yellow";
            }
            if (classesName.includes("danger")) {
              icon = <IconAlertCircle />;
              color = "red";
            }

            const childrenArray = React.Children.toArray(children);
            const titleChild = childrenArray.find(
              child => React.isValidElement(child) && child.props.className?.includes('remark-container-title')
            ) as React.ReactElement;

            return <Alert className={classes.alert} radius="md" variant="light" color={color} title={titleChild?.props.children} icon={icon}>
              {childrenArray.filter(
                (child) => !React.isValidElement(child) || !child.props.className?.includes('remark-container-title')
              )}
            </Alert>
          }
          return <div className={className} {...props}>{children}</div>;
        },
...
      }}
    >
      {markdown}
    </Markdown>
  )
}

Expect result:
image

@talatkuyuk
Copy link
Contributor

Thanks for reporting the issue, I will take care it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants