diff --git a/src/Highlighter/demos/index.tsx b/src/Highlighter/demos/index.tsx index e59b2963..c3043dea 100644 --- a/src/Highlighter/demos/index.tsx +++ b/src/Highlighter/demos/index.tsx @@ -27,6 +27,7 @@ export default () => { options: ['ghost', 'block', 'pure'], value: 'block', }, + wrap: false, }, { store }, ); diff --git a/src/Highlighter/index.tsx b/src/Highlighter/index.tsx index 5519987f..b5a0b7fd 100644 --- a/src/Highlighter/index.tsx +++ b/src/Highlighter/index.tsx @@ -45,6 +45,7 @@ export interface HighlighterProps extends DivProps { * @default 'block' */ type?: 'ghost' | 'block' | 'pure'; + wrap?: boolean; } export const Highlighter = memo( @@ -62,10 +63,11 @@ export const Highlighter = memo( allowChangeLanguage = true, fileName, icon, + wrap, ...rest }) => { const { styles, cx } = useStyles(type); - const container = cx(styles.container, className); + const container = cx(styles.container, !wrap && styles.nowrap, className); if (fullFeatured) return ( diff --git a/src/Highlighter/style.ts b/src/Highlighter/style.ts index 59e7a0ad..2311070e 100644 --- a/src/Highlighter/style.ts +++ b/src/Highlighter/style.ts @@ -63,7 +63,6 @@ export const useStyles = createStyles( } code { - text-wrap: nowrap !important; background: transparent !important; } `, @@ -90,6 +89,11 @@ export const useStyles = createStyles( transition: opacity 0.1s; `, ), + nowrap: css` + code { + text-wrap: nowrap !important; + } + `, scroller: css` overflow: auto; width: 100%; diff --git a/src/Markdown/utils.test.ts b/src/Markdown/utils.test.ts deleted file mode 100644 index b798e1d3..00000000 --- a/src/Markdown/utils.test.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { describe, expect, it } from 'vitest'; -import { escapeDollarNumber } from './utils'; - -describe('escapeDollarNumber', () => { - it('should escape dollar signs followed by numbers', () => { - expect(escapeDollarNumber('This costs $10.')).toBe('This costs \\$10.'); - expect(escapeDollarNumber('I have $20 and you have $30')).toBe('I have \\$20 and you have \\$30'); - }); - - it('should not escape dollar signs in code blocks', () => { - expect(escapeDollarNumber('```\n$10\n```')).toBe('```\n$10\n```'); - expect(escapeDollarNumber('This is a inline code block: `$10`')).toBe('This is a inline code block: `$10`'); - }); - - it('should handle multiple cases', () => { - expect(escapeDollarNumber('This costs $10. But this code is fine: `$10`.')).toBe('This costs \\$10. But this code is fine: `$10`.'); - }); - - it('should handle edge cases', () => { - expect(escapeDollarNumber('')).toBe(''); - expect(escapeDollarNumber('$')).toBe('$'); - expect(escapeDollarNumber('$$')).toBe('$$'); - expect(escapeDollarNumber('$1$2$3')).toBe('\\$1\\$2\\$3'); // 多个需要转义的情况 - }); -});