Repository navigation
Add export appearance preference #25
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| export type ExportAppearance = 'editor' | 'light' | 'dark' | ||
| export type ExportTheme = 'light' | 'dark' | ||
|
|
||
| export function normalizeExportAppearance(value: unknown): ExportAppearance { | ||
| return value === 'light' || value === 'dark' || value === 'editor' ? value : 'editor' | ||
| } | ||
|
|
||
| export function resolveExportTheme( | ||
| appearance: ExportAppearance, | ||
| editorTheme: 'system' | 'light' | 'dark', | ||
| systemPrefersDark: boolean | ||
| ): ExportTheme { | ||
| if (appearance === 'light' || appearance === 'dark') return appearance | ||
| if (editorTheme === 'light' || editorTheme === 'dark') return editorTheme | ||
| return systemPrefersDark ? 'dark' : 'light' | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { describe, expect, it } from 'vitest' | ||
| import { normalizeExportAppearance, resolveExportTheme } from '../src/lib/exportPreferences' | ||
|
|
||
| describe('export appearance preferences', () => { | ||
| it('normalizes persisted values to the allowlisted modes', () => { | ||
| expect(normalizeExportAppearance('editor')).toBe('editor') | ||
| expect(normalizeExportAppearance('light')).toBe('light') | ||
| expect(normalizeExportAppearance('dark')).toBe('dark') | ||
| expect(normalizeExportAppearance('custom')).toBe('editor') | ||
| expect(normalizeExportAppearance(null)).toBe('editor') | ||
| }) | ||
|
|
||
| it('allows explicit export light/dark to override the editor appearance', () => { | ||
| expect(resolveExportTheme('light', 'dark', true)).toBe('light') | ||
| expect(resolveExportTheme('dark', 'light', false)).toBe('dark') | ||
| }) | ||
|
|
||
| it('matches explicit editor light/dark appearance', () => { | ||
| expect(resolveExportTheme('editor', 'light', true)).toBe('light') | ||
| expect(resolveExportTheme('editor', 'dark', false)).toBe('dark') | ||
| }) | ||
|
|
||
| it('resolves system editor appearance at export time', () => { | ||
| expect(resolveExportTheme('editor', 'system', false)).toBe('light') | ||
| expect(resolveExportTheme('editor', 'system', true)).toBe('dark') | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the export appearance differs from the editor—for example, Dark export with a Light editor—passing this theme to
createExportHtmlcalls the globalmermaid.initialize(...)even if the document contains no diagram.DiagramCodeBlockEditor.tsxuses that same Mermaid singleton for subsequent preview renders without reinitializing it, so editing or adding a diagram after exporting renders it with the export palette rather than the editor palette. Render exports without mutating the shared configuration, or restore/reapply the editor configuration afterward.Useful? React with 👍 / 👎.