Skip to content

Conversation

@boboqun
Copy link
Contributor

@boboqun boboqun commented Aug 20, 2025

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-it plugin (markdownItAutoPicture.js) is added to the VitePress build process. It parses Markdown content and injects data-light-src and data-dark-src attributes into image tags for theme-aware loading.

  • The plugin is specifically designed to handle both standard Markdown image syntax (![alt](src)) and, more importantly, raw <img> HTML tags found in the source .topic files, which are treated as html_block tokens by the parser.

  • A client-side script (image-switcher.js) is added to the theme. It uses a MutationObserver to efficiently detect theme changes on the <html> element and dynamically swaps the src attribute 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:

  • On mobile, cards had a fixed height, causing long content (like titles or descriptions) to be clipped and hidden.
  • Multi-line titles had insufficient line-height, leading to overlapping text.
  • Large padding and font sizes consumed excessive screen real estate on small devices, harming usability.

Solution:

  • Replaced the fixed height on .card with min-height to allow cards to grow dynamically with their content.
  • Added a line-height to .cardTitle to ensure multi-line titles are legible.
  • Introduced media queries (@media) to:
    • Decrease padding within .cardContent on smaller screens.
    • Scale down font-size for titles and descriptions on mobile viewports for a more balanced layout.

Ikutsu and others added 8 commits August 18, 2025 21:15
Migrating from npm to pnpm and using Rolldown to build and update Vitepress to 2.0.0-alpha.11
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.
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-it` plugin (`markdownItAutoPicture.js`) is added to the VitePress build process. It parses Markdown content and injects `data-light-src` and `data-dark-src` attributes into image tags for theme-aware loading.

- The plugin is specifically designed to handle both standard Markdown image syntax (`![alt](src)`) and, more importantly, raw `<img>` HTML tags found in the source `.topic` files, which are treated as `html_block` tokens by the parser.

- A client-side script (`image-switcher.js`) is added to the theme. It uses a `MutationObserver` to efficiently detect theme changes on the `<html>` element and dynamically swaps the `src` attribute 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.
Refactored the Card component's CSS to ensure proper rendering and readability across all device sizes, specifically addressing issues on mobile.

Problem:
- On mobile, cards had a fixed height, causing long content (like titles or descriptions) to be clipped and hidden.
- Multi-line titles had insufficient line-height, leading to overlapping text.
- Large padding and font sizes consumed excessive screen real estate on small devices, harming usability.

Solution:
- Replaced the fixed `height` on `.card` with `min-height` to allow cards to grow dynamically with their content.
- Added a `line-height` to `.cardTitle` to ensure multi-line titles are legible.
- Introduced media queries (`@media`) to:
  - Decrease `padding` within `.cardContent` on smaller screens.
  - Scale down `font-size` for titles and descriptions on mobile viewports for a more balanced layout.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants