Add Mermaid Support in Fenced Code Blocks - #169
Sam Clark (28pins) wants to merge 5 commits into
Conversation
|
Copilot Fix the code for all comments in this review thread. When a review comment includes a suggested change, apply the suggestion exactly. Do not make changes beyond what is described in the linked review thread. |
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
Critical compile errors and unresolved Mermaid view issues must be addressed before approval.
Get a fresh assessment by requesting another Copilot review.
Review details
Suppressed comments (6)
Previously missed (1) — in code that hasn't changed since the last review.
Sources/MarkdownText/Models/MarkdownRenderConfig+Builders.swift:28
- The added argument lines contain trailing spaces, and
.swiftlint.ymlleaves thetrailing_whitespacerule enabled while CI runs SwiftLint in strict mode. Remove the spaces from these lines and the repeated builder arguments so lint does not fail after the syntax errors are corrected.
Examples/SwiftStreamingMarkdownSample/SwiftStreamingMarkdownSample/Resources/Fixtures/kitchen-sink.md:224
- This fixture also tells users that Mermaid fences are interactive, but the integrated native drawing view adds no interaction handlers. Change the wording to match the actual rendered behavior or add the promised interactions.
Mermaid fences render as interactive diagrams. Configure them via `MermaidConfig`; setting `.disabled` falls back to a readable fenced code block.
README.md:107
- This adds
BeautifulMermaidand itselk-swiftdependency, but the README's Binary Size section still states the old ~1 MB estimate and lists only the previous dependencies. Please update that public size disclosure after measuring the new renderer's impact.
- [x] Mermaid diagrams — rendered as interactive diagrams for `mermaid`-tagged fenced code blocks; theme and opt-out via `MermaidConfig` (`withMermaidConfig`, `.disabled`)
README.md:107
- The dependency view used here is a native drawing view and this integration adds no gestures or other interaction handlers, so describing these diagrams as “interactive” overpromises the behavior users receive. Describe them as native/rendered diagrams, or implement the promised interaction.
- [x] Mermaid diagrams — rendered as interactive diagrams for `mermaid`-tagged fenced code blocks; theme and opt-out via `MermaidConfig` (`withMermaidConfig`, `.disabled`)
Sources/MarkdownText/Models/MarkdownRenderConfig+Builders.swift:316
- These
: was missingsuffixes are also embedded in the Swift source, making thewithImageConfiginitializer call invalid syntax and preventing compilation. Remove the annotations rather than leaving them as source text.
mermaidConfig: mermaidConfig, : was missing
blockQuoteAlertStyle: blockQuoteAlertStyle : was missing
Sources/MarkdownText/UI/MermaidBlockView.swift:71
- Once settled, the raw-code fallback is replaced by a native
MermaidDiagramView, but this branch adds no accessibility element, label, or textual value for the diagram. VoiceOver users can therefore lose the Mermaid block entirely; expose an accessible diagram label and/or the source text (and keep it synchronized withsettledSource) on the rendered view.
MermaidDiagramView(
source: settledSource,
theme: config.mermaidConfig.theme.diagramTheme(for: colorScheme),
parseError: $parseError
)
- Files reviewed: 15/16 changed files
- Comments generated: 6
- Review effort level: Lite
| mermaidConfig: mermaidConfig, | ||
| imageConfig: imageConfig, | ||
| blockQuoteAlertStyle: blockQuoteAlertStyle |
| imageConfig: imageConfig, : was missing | ||
| blockQuoteAlertStyle: blockQuoteAlertStyle : was missing |
| let alertStyle = MarkdownRenderConfig.defaultBlockQuoteAlertStyle | ||
|
|
||
| let base = MarkdownRenderConfig(imageConfig: imageConfig, blockQuoteAlertStyle: alertStyle) | ||
| let updated = base.withMermaidConfig(.disabled) | ||
|
|
||
| XCTAssertEqual(updated.mermaidConfig, .disabled) | ||
| XCTAssertEqual(updated.imageConfig, imageConfig) | ||
| XCTAssertEqual(updated.blockQuoteAlertStyle, alertStyle) |
| let settledSource = State(initialValue: "") | ||
| let parseError = State<Error?>(initialValue: nil) | ||
| let debouncer = MermaidStreamDebouncer() | ||
| debouncer.onCommit = { source in | ||
| settledSource.wrappedValue = source | ||
| parseError.wrappedValue = nil | ||
| } |
| .onAppear { | ||
| debouncer.schedule(code) | ||
| } | ||
| .onChange(of: code) { newValue in | ||
| debouncer.schedule(newValue) | ||
| } | ||
| .onDisappear { | ||
| debouncer.cancel() |
| MermaidDiagramView( | ||
| source: settledSource, | ||
| theme: config.mermaidConfig.theme.diagramTheme(for: colorScheme), | ||
| parseError: $parseError |
|
Copilot Fix the code for all comments in this review thread. When a review comment includes a suggested change, apply the suggestion exactly. Do not make changes beyond what is described in the linked review thread. |
Summary
beautiful-mermaid-swiftMermaidConfig.disabledMermaidConfigoffers theme customization options (inherits directly from package, VS Code based)Validation
Add tests, check demos, stress test
kitchen sinkdemoOSS readiness