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

Add Markdown Alert Component Support #1791

Merged
merged 23 commits into from
Jan 29, 2025

Conversation

hexart
Copy link
Contributor

@hexart hexart commented Jan 23, 2025

Features

  • Add support for alert containers in markdown using ::: syntax
  • Alert type case-insensitive
  • Support custom alert types
  • Multiple alert types for different scenarios:
    • Basic alerts: info, note, tip, important, warning, caution
    • Development related: debug, example
    • Functional alerts: success, help, idea
    • Status alerts: pending, security, beta, best-practice

Compare tech route

Technical Aspect VuePress/Markdown-it (:::) GitHub ([!TYPE])
Markdown Parser Works with most remark parsers Requires GitHub's custom parser
Plugin Support Supported by remark-directive Needs custom parser implementation
Integration Cost Low - uses existing chainlit deps High - requires new parser logic
Code Implementation Simple AST transformation Complex blockquote & reference parsing
Base Framework Already supported by remark Needs additional parsing rules

Related issue

#1767

Technical Implementation

  • Leverages existing remark-directive plugin for ::: syntax parsing
  • Built on top of chainlit's i18n system for multi-language support
  • Uses tailwindcss for theme-aware styling (light/dark mode)
  • Integrates lucide-react icons for consistent visual design

Usage Example

Tested code & Recommended Format

Basic alerts

::: InFo
Information message with a list:
Item 1
Item 2
:::

::: NOTE
Note message
:::

::: tip
Helpful tip with code
:::

::: Important
Critical information!
:::

::: warning
Warning with emphasis
:::

::: caution
Caution message
:::

Development related

::: debug
Debug information
:::

::: example
Example usage
:::

Functional alerts

::: success
Operation successful
:::

::: help
Help message
:::

::: idea
Innovative idea
:::

Status alerts

::: pending
Work in progress
:::

::: security
Security notice
:::

::: beta
Beta feature
:::

::: best-practice
Recommended practice
:::

Caution

Inside MarkdownAlert does not support common Markdown formats, please use plain text instead.
Incorrect formatting may result in plain text rendering or content disappearance.

Tip

Alert type is case-insensitive

Testing Done

  • Tested alert rendering in both light and dark themes
  • Verified i18n support works correctly
  • Confirmed all alert types render properly

Screenshots

2025-01-24 16 18 55 2025-01-24 16 19 27

Dependencies

No new dependencies required - using existing chainlit packages:

  • remark-directive
  • lucide-react
  • tailwindcss

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. frontend Pertains to the frontend. labels Jan 23, 2025
Copy link
Collaborator

@willydouhard willydouhard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, few comments before merging!

frontend/src/components/Markdown.tsx Outdated Show resolved Hide resolved
frontend/src/components/Markdown.tsx Outdated Show resolved Hide resolved
frontend/src/components/Markdown.tsx Outdated Show resolved Hide resolved
libs/react-client/package.json Outdated Show resolved Hide resolved
libs/copilot/package.json Outdated Show resolved Hide resolved
- Add case-insensitive flag to regex pattern
- Convert alert type to lowercase before rendering
- Change regex pattern from \w+ to [\w-]+ to handle hyphenated types like best-practice
Copy link
Collaborator

@willydouhard willydouhard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

almost there!

libs/react-client/pnpm-lock.yaml Outdated Show resolved Hide resolved
frontend/src/components/Markdown_Alert.tsx Outdated Show resolved Hide resolved
@hexart hexart requested a review from willydouhard January 24, 2025 00:07
- Fix best-practice key name in translation files
- Remove console.log in MarkdownAlert.tsx
@hexart
Copy link
Contributor Author

hexart commented Jan 24, 2025

Do I need to add a class in emitter.py? @willydouhard

def send_alert(self, variant: str, content: str):
    """Send alert message to UI."""
    return self.emit("alert", {
        "variant": variant.lower(),
        "content": content
    })

frontend/package.json Outdated Show resolved Hide resolved
frontend/package.json Outdated Show resolved Hide resolved
@hexart hexart requested a review from willydouhard January 24, 2025 16:26
@hexart
Copy link
Contributor Author

hexart commented Jan 25, 2025

截屏2025-01-26 19 09 56 截屏2025-01-26 19 54 37

How are these new modern styles? Should we change Markdown alert's visual design to unify it with the Chainlit official web style?

@jmanhype
Copy link

jmanhype commented Jan 25, 2025 via email

@hexart
Copy link
Contributor Author

hexart commented Jan 25, 2025

Can't agree more, need more opinions.

@jmanhype
Copy link

jmanhype commented Jan 25, 2025 via email

@hexart
Copy link
Contributor Author

hexart commented Jan 25, 2025

How about this idea? Let's make an alert theme style switch between old style and new modern style?

@jmanhype
Copy link

jmanhype commented Jan 25, 2025 via email

@hexart
Copy link
Contributor Author

hexart commented Jan 25, 2025

It's easy to achieve, but I need the permit of reviewers.

@willydouhard Please confirm the following two items:

  • Whether to use the traditional variantStyles or the new modernVariantStyles?
  • Is style switching needed? If needed, should it be switched through frontend config.ts or backend Python FastAPI?

@jmanhype
Copy link

jmanhype commented Jan 25, 2025 via email

libs/react-client/pnpm-lock.yaml Outdated Show resolved Hide resolved
@hexart hexart requested a review from willydouhard January 28, 2025 14:41
Copy link
Collaborator

@willydouhard willydouhard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@willydouhard willydouhard added this pull request to the merge queue Jan 29, 2025
Merged via the queue into Chainlit:main with commit de1636e Jan 29, 2025
9 checks passed
@hexart hexart deleted the feature/markdown-alert-new branch January 29, 2025 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
frontend Pertains to the frontend. size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants