Skip to content

feat: make block spacing configurable via MarkdownRenderConfig - #90

Merged
Jun Yan (junyan72) merged 3 commits into
microsoft:mainfrom
szguicheng:feat/configurable-block-spacing
Jun 20, 2026
Merged

feat: make block spacing configurable via MarkdownRenderConfig#90
Jun Yan (junyan72) merged 3 commits into
microsoft:mainfrom
szguicheng:feat/configurable-block-spacing

Conversation

@szguicheng

Copy link
Copy Markdown
Contributor

Summary

Adds a blockSpacing property to MarkdownRenderConfig so callers can control the vertical gap between adjacent Markdown blocks (paragraphs, headings, code blocks, lists, etc.). The default value is 30, preserving the existing hardcoded behavior.

Closes #87.

Problem

All block-level spacing was hardcoded in BlockView.swift:

VStack(alignment: .leading, spacing: 30) { ... }

MarkdownRenderConfig provides a clean configuration surface for fonts and colors, but had no spacing properties. Apps that need different visual density — a chat bubble versus a full-width article view — had no way to adjust spacing without forking.

Changes

Three files, 31 insertions / 3 deletions:

  • MarkdownRenderConfig.swift — new blockSpacing: CGFloat property (default 30), wired into init
  • MarkdownRenderConfig+Builders.swift — new withBlockSpacing(value:) builder, and updated withTextContextMenu(value:) to forward the new property
  • BlockView.swift — reads blockSpacing from @Environment(\.markdownConfig) instead of the hardcoded literal

Usage

MarkdownView(text: markdown, config: .default.withBlockSpacing(value: 10))

Test plan

  • All existing tests pass (make test — ✅)
  • Default spacing unchanged (30 = prior hardcoded value)
  • Custom spacing applies correctly when set via withBlockSpacing(value:)

Notes

  • This is intentionally minimal — per block-type spacing and configurable lineSpacing are left for follow-up work if there is demand.
  • Follows the exact same pattern as every other MarkdownRenderConfig property.

🤖 Generated with Claude Code

Add a `blockSpacing` property (default 30) that controls the vertical gap
between adjacent blocks in the rendered Markdown output. This follows the
same pattern as every other config property — stored in MarkdownRenderConfig,
exposed through a `withBlockSpacing(value:)` builder, and consumed by
BlockView via the `\.markdownConfig` environment.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a blockSpacing configuration surface to MarkdownRenderConfig so callers can control the vertical spacing between adjacent block-level renderables, instead of relying on a hardcoded VStack(... spacing: 30) in the UI layer.

Changes:

  • Introduces blockSpacing: CGFloat on MarkdownRenderConfig with a default of 30 to preserve existing behavior.
  • Adds a withBlockSpacing(value:) builder (and updates withTextContextMenu(value:) to forward the new property).
  • Updates BlockView to read spacing from @Environment(\.markdownConfig).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
Sources/MarkdownText/UI/BlockView.swift Replaces hardcoded VStack spacing with config.blockSpacing from the environment.
Sources/MarkdownText/Models/MarkdownRenderConfig+Builders.swift Adds withBlockSpacing and updates withTextContextMenu to forward blockSpacing (and citationConfig).
Sources/MarkdownText/Models/MarkdownRenderConfig.swift Adds the new blockSpacing property, default constant, and initializer wiring.

Comment thread Sources/MarkdownText/Models/MarkdownRenderConfig+Builders.swift
@szguicheng
Cheng Gui (szguicheng) marked this pull request as draft June 19, 2026 15:22
@junyan72
Jun Yan (junyan72) marked this pull request as ready for review June 19, 2026 21:34
@junyan72

Copy link
Copy Markdown
Contributor

Copilot resolve merge conflict, add snapshot test case to cover the configurability

@szguicheng

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

Cheng Gui (szguicheng) and others added 2 commits June 20, 2026 08:13
Adds a snapshot test that renders multi-block markdown with
blockSpacing set to 10, verifying the config property is
plumbed through correctly to the rendered output.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@junyan72
Jun Yan (junyan72) merged commit ab4ce05 into microsoft:main Jun 20, 2026
4 checks passed
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.

Feature request: Make block spacing configurable via MarkdownRenderConfig

3 participants