fix (components): Navie now properly renders indented code blocks#2287
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes an issue whereby code blocks indented along with their fences were rendered with extra indentation. The changes refactor the stripCodeFences utility into smaller helper functions and add comprehensive tests for various edge cases.
- Refactored and documented stripCodeFences, removeFenceLines, and dedentLines.
- Improved test coverage for code block parsing.
- Minor test file cleanups in the MermaidDiagram component.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/components/tests/unit/lib/stripCodeFences.spec.js | Added extensive tests for the new code fence parsing logic. |
| packages/components/tests/unit/chat/MermaidDiagram.spec.js | Removed unused import and updated expected values for external links. |
| packages/components/src/lib/stripCodeFences.ts | Refactored utility functions with added documentation and updated logic to properly handle indented code fences. |
Comments suppressed due to low confidence (1)
packages/components/src/lib/stripCodeFences.ts:25
- [nitpick] Consider refactoring the closing fence detection logic into a separate, clearly named function or adding extra inline comments to clarify the conditions used, which can improve readability and future maintainability.
const closingMatch = (lines.length > 1 || !openingMatch) ? lines[lines.length - 1].match(fenceRegex) : null;
|
This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation. |
|
🎉 This PR is included in version @appland/components-v4.46.4 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
This pull request addresses an issue where code blocks enclosed in triple backticks (```) were not rendered correctly if the entire block, including the opening and closing fences, was indented.
Problem:
The previous implementation of
stripCodeFencesdid not account for leading whitespace before the code fences. This resulted in the indentation being incorrectly included as part of the code content, disrupting formatting.Solution:
The
stripCodeFencesutility has been refactored to correctly handle indented code blocks:```).Testing:
Comprehensive unit tests have been added for the updated utility and its helper functions, covering various scenarios including: