Add GFM Alert Styling - #168
Sam Clark (28pins) wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.
Suppressed comments (1)
Sources/MarkdownText/UI/BlockQuoteView.swift:104
- These lines contain tab-indentation, which is likely to trip SwiftLint and makes the new alert view code inconsistent with the surrounding file’s spacing-based indentation.
Image(systemName: style.imageName)
.foregroundStyle(style.accentColor)
.padding(.leading, 8.0)
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
Jun Yan (@junyan72) would you mind allowing the workflow runs? These are my first PRs on this repo, so let me know if I need to do anything else. |
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved parser, rendering, test-coverage, lint, accessibility, and documentation findings remain.
Get a fresh assessment by requesting another Copilot review.
Review details
Suppressed comments (5)
Sources/MarkdownText/Block/BlockQuote+.swift:24
- The added parser test keeps
[!NOTE]and its body in one paragraph, so it does not exercise a multi-paragraph alert where a later child must inheritalertKind. Add a focused case with a quoted blank line and a second paragraph, and verify that both paragraphs remain inside the alert.
if alertKind == nil, let (kind, rest) = Self.parseAlertTag(text) {
alertKind = kind
if !rest.isEmpty {
finalQuoteTypes.append(.text(rest, alertKind))
}
} else {
finalQuoteTypes.append(.text(text, alertKind))
Sources/MarkdownText/Models/MarkdownRenderConfig.swift:110
- This public initializer also requires an
imageName, but its documentation only describes the two colors. Document the SF Symbol parameter so callers know what controls the icon shown by the alert.
/// Create an alert style with the supplied accent and background colors.
public init(accentColor: Color, backgroundColor: Color, imageName: String) {
Sources/MarkdownText/UI/BlockQuoteView.swift:50
- Nested quote items are rendered directly through
InternalBlockQuoteView, so a nested.nested(..., .warning)never passes throughBlockQuoteView's alert wrapper. A nested GFM alert is consequently rendered as an ordinary quote; recurse throughBlockQuoteView(or apply the same alert wrapper) for each child.
case .nested(let subItems, _):
ForEach(subItems.indices, id: \.self) { index in
InternalBlockQuoteView(item: subItems[index])
Sources/MarkdownText/UI/BlockQuoteView.swift:104
- After
[!NOTE]is stripped, the icon is the only indication of the alert kind, but thisImagehas no accessibility label. VoiceOver users can receive the body without knowing that it is a note/warning, and customimageNamevalues have no reliable semantic label; expose the kind as the icon's label.
Image(systemName: style.imageName)
.foregroundStyle(style.accentColor)
.padding(.leading, 8.0)
Tests/MarkdownTextTests/MarkdownParserTests.swift:74
- This test only uses
[!NOTE]and its body on the same quoted line, while the canonical GFM form in the fixture puts the marker on its own line and supports subsequent paragraphs. Add coverage for the marker-only first paragraph and multiline content; otherwise a regression in the actual syntax advertised by the README could pass the tests.
let markdown = """
> [!NOTE] This is a note.
"""
- Files reviewed: 11/11 changed files
- Comments generated: 3
- Review effort level: Lite
| imageConfig: value | ||
| ) | ||
| } | ||
|
|
| if alertKind == nil, let (kind, rest) = Self.parseAlertTag(text) { | ||
| alertKind = kind | ||
| if !rest.isEmpty { |
| if let kind = item.alertKind { | ||
| AlertBlockQuoteView(kind: kind) { | ||
| InternalBlockQuoteView(item: item, isForAlertQuote: true) | ||
| } |
Summary
What changed: Added support for alerts, like
[!NOTE]Why: to give users and LLMs more flexibility and better UX
API change:
BlockQuoteTypenow includesBlockQuoteAlertKindas an optional. See below:Old:
New:
Validation
Checked demos and stress-tested kitchen sink demo
OSS readiness