Skip to content

feat: markdown support language highlighting #53

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

Draft
wants to merge 11 commits into
base: develop
Choose a base branch
from

Conversation

gene9831
Copy link
Collaborator

@gene9831 gene9831 commented May 19, 2025

  • markdown 支持语法高亮。使用 shiki 实现
  • 代码块顶部增加工具栏,支持复制代码
  • markdown html增加xss防护

目前是全量引入的 shiki,支持大量语法高亮,并且默认支持按需加载。不过由于全量引入,打包后体积非常大

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added asynchronous Markdown rendering with syntax highlighting, HTML sanitization, and enhanced code block UI, including a copy-to-clipboard button for code snippets.
    • Introduced support for custom content transformation and DOMPurify configuration for secure Markdown rendering.
    • Externalized Markdown content in demos for better maintainability.
    • Updated bubble components to support Markdown content type with improved rendering and styling.
    • Added a new copy button component for easy code snippet copying.
  • Bug Fixes

    • Improved handling and sanitization of custom tags and attributes in Markdown content.
  • Documentation

    • Updated documentation and demos to reflect new Markdown rendering features and configuration options.
    • Updated demo imports to use custom element versions for better integration.
  • Chores

    • Updated dependencies to use asynchronous Markdown parsing, syntax highlighting, and sanitization libraries.
    • Refactored component imports to use custom element variants where applicable.

Copy link

coderabbitai bot commented May 19, 2025

Walkthrough

The changes introduce asynchronous markdown rendering with syntax highlighting and sanitization using new dependencies and a composable. Components now support a transformContent function for async content transformation and a domPurifyConfig for XSS protection. Demo files are updated to externalize markdown content and configure custom tag sanitization, while code block UI is enhanced with copy buttons.

Changes

File(s) Change Summary
packages/components/package.json Replaced markdown-it with markdown-it-async, shiki, and dompurify; updated dev dependencies accordingly.
packages/components/src/bubble/composables/useMarkdownIt.ts Added a new composable for async markdown parsing with syntax highlighting, sanitization, and code block toolbar/copy button.
packages/components/src/bubble/Bubble.vue Switched to async markdown parsing with reactive content updates; added code block UI enhancements and LESS styles.
packages/components/src/bubble/BubbleList.vue Integrated async markdown parsing in item props; updated types for item functions.
packages/components/src/bubble/index.type.ts Added transformContent and domPurifyConfig to BubbleProps; updated markdown options import.
packages/components/src/bubble/CopyBtn.vue Added a new component for copy-to-clipboard functionality in code blocks.
packages/components/src/icon-button/index.ts Changed component import from .vue to .ce.vue.
docs/demos/bubble/list.vue Changed "ai" role rendering from custom slot to markdown type; removed custom render function.
docs/demos/bubble/markdown.vue, docs/demos/bubble/streaming.vue Externalized markdown content to markdown-data.ts and imported it.
docs/demos/bubble/markdown-data.ts Added new module exporting sample markdown content with code blocks.
docs/demos/bubble/schema-render.vue Updated markdown and DOMPurify config usage; imported BubbleProps; allowed custom tags in config.
docs/src/components/bubble.md Updated demo component reference for schema card example; expanded API docs with new properties.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant BubbleList
    participant Bubble
    participant useMarkdownIt
    participant DOMPurify
    participant Shiki

    User->>BubbleList: Provide items with type 'markdown'
    BubbleList->>Bubble: Pass item props and transformContent (async)
    Bubble->>useMarkdownIt: Call parseMarkdown(content, mdConfig, domPurifyConfig)
    useMarkdownIt->>Shiki: Highlight code blocks (async)
    useMarkdownIt->>DOMPurify: Sanitize HTML output
    useMarkdownIt-->>Bubble: Return sanitized HTML
    Bubble-->>User: Rendered markdown with syntax highlighting and copy buttons
Loading

Poem

In the garden of code, markdown blooms anew,
Async and shiny, with highlights that woo.
Copy buttons sparkle, code blocks stand tall,
Sanitized safely—no bugs to befall!
A rabbit hops by, clipboard in paw,
Marveling at markdown, in perfect awe.
🐇✨

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Free

📥 Commits

Reviewing files that changed from the base of the PR and between b017531 and 9ef64d2.

📒 Files selected for processing (1)
  • packages/components/src/bubble/Bubble.vue (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/components/src/bubble/Bubble.vue

Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Join our Discord community for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@gene9831 gene9831 changed the title [WIP]feat: markdown support language highlighting feat: markdown support language highlighting May 20, 2025
@hexqi hexqi marked this pull request as draft July 17, 2025 01:56
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

Successfully merging this pull request may close these issues.

1 participant