feat(theme): Implement automatic dark/light image switching for ktor #33
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.
1. feat(theme): Implement automatic dark/light image switching for ktor
Introduces a new feature to automatically switch images when the user toggles between light and dark themes, replicating the behavior of JetBrains Writerside.
This is achieved through a combination of a server-side build plugin and a client-side script:
A custom
markdown-itplugin (markdownItAutoPicture.js) is added to the VitePress build process. It parses Markdown content and injectsdata-light-srcanddata-dark-srcattributes into image tags for theme-aware loading.The plugin is specifically designed to handle both standard Markdown image syntax (
) and, more importantly, raw<img>HTML tags found in the source.topicfiles, which are treated ashtml_blocktokens by the parser.A client-side script (
image-switcher.js) is added to the theme. It uses aMutationObserverto efficiently detect theme changes on the<html>element and dynamically swaps thesrcattribute of the themed images.Both the build plugin and the client script are optimized to only execute on pages under the
/ktor/path. This improves performance and prevents unintended side-effects on other sections of the documentation.2. fix: trim redundant spaces after <br/> in Markdown parsing
Added a new markdown-it plugin that removes unnecessary whitespace after <br/> tags before rendering. This prevents extra blank lines from appearing between steps in tutorials.
For example, in docs/kmp/compose-multiplatform-create-first-app.md, extra spaces after the <br/> tag caused step 3 and step 4 to render with an unwanted blank line. The <br/> itself is preserved to keep intended line breaks, but trailing spaces are stripped to ensure consistent formatting.
3. refactor(Component/DocCard): Implement robust responsive design
Refactored the Card component's CSS to ensure proper rendering and readability across all device sizes, specifically addressing issues on mobile.
Problem:
Solution:
heighton.cardwithmin-heightto allow cards to grow dynamically with their content.line-heightto.cardTitleto ensure multi-line titles are legible.@media) to:paddingwithin.cardContenton smaller screens.font-sizefor titles and descriptions on mobile viewports for a more balanced layout.