Themes
@ant-design/x-markdown/themes/theme-name.css
.import XMarkdown from '@ant-design/x-markdown';import '@ant-design/x-markdown/themes/light.css';return <XMarkdown className="x-markdown-light" content="Hello XMarkdown!" />;
Use script and link tags to directly import files in the browser, and inject the className
into the component.
<script src="**/dist/themes/light.css"></script>
We welcome community contributions for new themes! Please follow these specifications for theme development:
Theme files should follow these naming rules:
theme-name.css
x-markdown-theme-name
x-markdown-ocean.css
corresponds to class name x-markdown-ocean
Place your theme files in the packages/x-markdown/src/themes/
directory:
packages/x-markdown/src/themes/├── light.css # Default light theme├── dark.css # Default dark theme├── ocean.css # Custom theme example└── your-theme-name.css # Your theme file
Theme styles must follow these naming conventions:
/* Base container */.x-markdown-theme-name {/* Base style variables */--x-markdown-color-text: #333;--x-markdown-color-bg: #fff;--x-markdown-color-border: #e8e8e8;/* Code block styles */--x-markdown-color-code-bg: #f5f5f5;--x-markdown-color-code-text: #333;/* Heading styles */--x-markdown-color-heading: #262626;/* Link styles */--x-markdown-color-link: #1890ff;--x-markdown-color-link-hover: #40a9ff;}/* Code block highlighting */.x-markdown-theme-name .x-markdown-highlight-code {background: var(--x-markdown-color-code-bg);border: 1px solid var(--x-markdown-color-border);}/* Table styles */.x-markdown-theme-name .x-markdown-table {border-color: var(--x-markdown-color-border);}/* Blockquote styles */.x-markdown-theme-name .x-markdown-blockquote {border-left-color: var(--x-markdown-color-link);}
Create Theme File:
touch packages/x-markdown/src/themes/your-theme-name.css
Define Base Variables: Use CSS variables to define colors, spacing, and other base styles.
Implement Component Styles: Implement styles for various Markdown elements:
Test Theme: Test your theme in the demo:
import '@ant-design/x-markdown/themes/your-theme-name.css';<XMarkdown className="x-markdown-your-theme-name" content="# Test Content" />
Before submitting your theme, please ensure:
Code Standards:
npm run lint
checksnpm run test
testsDocumentation:
themes.en-US.md
Pull Request:
master
Here is a complete theme example:
/* x-markdown-ocean.css */.x-markdown-ocean {/* Ocean theme color scheme */--x-markdown-color-text: #2c3e50;--x-markdown-color-bg: #f8fafc;--x-markdown-color-border: #e2e8f0;--x-markdown-color-primary: #0ea5e9;--x-markdown-color-secondary: #64748b;/* Code blocks */--x-markdown-color-code-bg: #f1f5f9;--x-markdown-color-code-border: #cbd5e1;/* Headings */--x-markdown-color-h1: #0f172a;--x-markdown-color-h2: #1e293b;--x-markdown-color-h3: #334155;}.x-markdown-ocean h1 {color: var(--x-markdown-color-h1);border-bottom: 2px solid var(--x-markdown-color-primary);}.x-markdown-ocean pre {background: var(--x-markdown-color-code-bg);border: 1px solid var(--x-markdown-color-code-border);border-radius: 6px;}
We welcome community contributions for various theme styles, such as:
Please submit your themes to GitHub Issues or send a Pull Request!