Skip to content

fix(site): rewrite the theme of code highlight #3397

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

Merged
merged 2 commits into from
May 8, 2025
Merged

Conversation

shenjunjian
Copy link
Collaborator

@shenjunjian shenjunjian commented May 8, 2025

PR

1、调整官网的暗色代码高亮的颜色
示例代码 & 指南的代码
image
image
image

2、 示例代码统一用xml格式高亮

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@shenjunjian shenjunjian added the enhancement New feature or request (功能增强) label May 8, 2025
Copy link

coderabbitai bot commented May 8, 2025

Walkthrough

This update enhances code syntax highlighting in markdown and Vue components for a documentation site. It introduces language-specific dark mode styles, adds TypeScript highlighting support, and simplifies code highlighting logic by switching from a types prop to a filename prop. Component usage is updated accordingly.

Changes

File(s) Change Summary
examples/sites/src/assets/custom-markdown.css Enhanced .markdown-body code with larger font and monospace font family. Removed a basic dark mode string color rule and introduced detailed, language-specific syntax highlighting for bash, JavaScript, and HTML code blocks in dark mode, with fine-grained token color assignments.
examples/sites/src/main.js Added TypeScript syntax highlighting by importing and registering the TypeScript language with highlight.js under the alias 'ts'. No changes to logic or control flow.
examples/sites/src/views/components-doc/components/async-highlight.vue Renamed prop types to filename. Removed explicit language registration and highlighting logic for TypeScript and HTML. Now, highlights as HTML if filename ends with .vue, otherwise uses automatic detection. Added dark theme CSS for code blocks and updated font-family for code.
examples/sites/src/views/components-doc/components/demo.vue Updated async-highlight component usage to pass the new filename prop (from file.fileName or files[0].fileName). Removed a trailing space in a v-if directive.

Sequence Diagram(s)

sequenceDiagram
    participant DemoVue as demo.vue
    participant AsyncHighlight as async-highlight.vue
    participant HLJS as highlight.js

    DemoVue->>AsyncHighlight: Passes code and filename props
    AsyncHighlight->>AsyncHighlight: Checks if filename ends with ".vue"
    alt .vue file
        AsyncHighlight->>HLJS: Highlight code as HTML
    else other file
        AsyncHighlight->>HLJS: highlightAuto(code)
    end
    HLJS-->>AsyncHighlight: Returns highlighted HTML
    AsyncHighlight-->>DemoVue: Renders highlighted code block
Loading

Poem

🐇
In the garden of code, new colors bloom,
With TypeScript shining in markdown's room.
Props renamed, logic made light,
Dark mode glows with syntax bright.
Rabbits hop and highlight, too—
Each filename brings a vibrant hue!

Tip

⚡️ 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: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8a72dda and ccbd4d6.

📒 Files selected for processing (4)
  • examples/sites/src/assets/custom-markdown.css (2 hunks)
  • examples/sites/src/main.js (2 hunks)
  • examples/sites/src/views/components-doc/components/async-highlight.vue (2 hunks)
  • examples/sites/src/views/components-doc/components/demo.vue (2 hunks)
🔇 Additional comments (10)
examples/sites/src/main.js (2)

30-30: Good addition of TypeScript language support

Adding TypeScript highlighting support is a valuable enhancement to the code syntax highlighting functionality.


41-41: Properly registered TypeScript language

The TypeScript language is correctly registered with the highlight.js instance using the 'ts' alias, following the same pattern as the existing language registrations.

examples/sites/src/views/components-doc/components/demo.vue (2)

32-32: Code cleanup: removed trailing space

Removing the trailing space in the v-if directive improves code cleanliness.


60-60: Updated component usage with filename prop

The async-highlight component invocations now correctly pass the filename prop instead of the previous types prop, aligning with the changes in the async-highlight component.

Also applies to: 65-65

examples/sites/src/assets/custom-markdown.css (2)

100-101: Improved code block typography

The font size increase and monospace font family specification enhance code readability. The use of !important is appropriate here to ensure consistent font styling across the site.


120-179: Well-structured dark mode syntax highlighting

The dark mode syntax highlighting rules are comprehensive and well-organized with language-specific styling. The color scheme provides good contrast and readability for different code elements.

Key improvements:

  • Language-specific styling for bash, JavaScript, and HTML
  • Detailed token coloring (functions, keywords, strings, properties, etc.)
  • Consistent color palette aligned with the dark theme
examples/sites/src/views/components-doc/components/async-highlight.vue (4)

20-20: Good prop renaming for better semantics

Renaming the prop from "types" to "filename" better reflects its purpose and improves component API clarity.


33-37: Simplified highlighting logic

The highlighting logic has been streamlined to use the filename extension for language detection, which is more maintainable than explicit type checking. This aligns well with common conventions for syntax highlighting.


52-97: Comprehensive dark theme styling

The added dark mode styles provide detailed and language-specific syntax highlighting that enhances code readability in dark mode. The color scheme is consistent with the custom-markdown.css changes, ensuring a unified experience across the site.


104-104: Consistent code font styling

Updated the font family to use the same monospace fonts as in the custom-markdown.css file, ensuring consistency across all code presentations.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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? Create a ticket on our support page 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 docstrings to generate docstrings for this 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.

@github-actions github-actions bot added bug Something isn't working and removed enhancement New feature or request (功能增强) labels May 8, 2025
Copy link

Walkthrough

此PR主要调整了官网的暗色代码高亮主题,统一示例代码的高亮格式为XML,并在多个文件中更新了代码高亮的样式和逻辑。

Changes

文件 概要
examples/sites/src/assets/custom-markdown.css 更新了暗色主题下的代码高亮样式,增加了对不同语言的颜色定义。
examples/sites/src/main.js 添加了对TypeScript语言的支持。
examples/sites/src/views/components-doc/components/async-highlight.vue 修改了代码高亮的逻辑,移除了对TypeScript的单独处理,改为自动检测语言。
examples/sites/src/views/components-doc/components/demo.vue 更新了组件以支持文件名传递,用于代码高亮。

} else if (props.types && props.types === 'ts') {
highlightCode.value = getFormatCodes(props.types)
if (props.filename && props.filename.endsWith('.vue')) {
highlightCode.value = hljs.highlight(props.code, { language: 'html' }).value

Choose a reason for hiding this comment

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

The removal of specific TypeScript handling in favor of automatic language detection could potentially lead to incorrect highlighting if the automatic detection fails. Consider verifying that this change does not affect the accuracy of TypeScript code highlighting.

@shenjunjian shenjunjian added enhancement New feature or request (功能增强) and removed bug Something isn't working labels May 8, 2025
@github-actions github-actions bot added bug Something isn't working and removed enhancement New feature or request (功能增强) labels May 8, 2025
@zzcr zzcr merged commit 375757e into dev May 8, 2025
16 checks passed
@zzcr zzcr deleted the shen/site-dark-code-sytle branch May 8, 2025 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants