API docs: dedent examples + scrollbar#54
Conversation
PrzemyslawKlys
commented
Feb 5, 2026
- Dedent XML code examples to fix misaligned code blocks.
- Style API sidebar scrollbars for consistency.
Pull Request ReviewThis PR makes two focused improvements to the API documentation system: dedenting XML code examples and styling sidebar scrollbars. Overall, the changes are well-implemented, but I have a few suggestions for consideration. ✅ What's Good
🔍 Potential Issues & Suggestions1. Tab Character Handling (Minor Bug)Location: The current dedent logic only counts space characters: while (indent < line.Length && line[indent] == ' ') indent++;Issue: If XML code examples use tabs or mixed spaces/tabs, the dedent calculation will be incorrect. Suggestion: Consider handling tabs, or at minimum, document this limitation: // Count leading whitespace (spaces only; tabs not supported)
while (indent < line.Length && line[indent] == ' ') indent++;Or handle tabs more robustly: while (indent < line.Length && char.IsWhiteSpace(line[indent])) indent++;Note: If you use 2. Empty Line Handling Inconsistency (Code Clarity)Location: if (string.IsNullOrWhiteSpace(line))
sb.Append("");Issue: Appending an empty string is a no-op. The intent appears to be preserving empty lines, but this is already handled by the Suggestion: Either remove the redundant append or add a clarifying comment: if (string.IsNullOrWhiteSpace(line))
continue; // Empty lines are preserved via newlinesOr if you intentionally want to preserve whitespace-only lines as truly empty: if (string.IsNullOrWhiteSpace(line))
sb.Append(string.Empty); // Normalize whitespace-only lines to empty3. Test Coverage GapObservation: There's no unit test for the new Suggestion: Add test cases covering:
Example test structure: [Theory]
[InlineData(" line1\n line2", "line1\nline2")]
[InlineData(" line1\n line2", "line1\n line2")]
[InlineData("line1\nline2", "line1\nline2")]
public void Dedent_RemovesCommonLeadingWhitespace(string input, string expected)
{
// Test implementation
}4. CSS Specificity (Minor Consideration)Location: The scrollbar styles target both Question: Are these separate elements, or is 🎯 Performance & Security
📋 SummaryApprove with suggestions: The core functionality is sound and the changes are beneficial. The main improvement would be adding tests and clarifying the tab handling behavior. Recommended actions before merge:
Rating: 8/10 — Good implementation with room for minor improvements in edge case handling and test coverage. 🔗 References
Reviewed by Claude Sonnet 4.5 |
There was a problem hiding this comment.
Pull request overview
This PR improves the API documentation rendering by dedenting XML code examples to prevent misaligned code blocks and adds custom scrollbar styling to API sidebars for better visual consistency.
Changes:
- Added a new
Dedentmethod to remove common leading whitespace from XML code examples - Applied the dedenting logic to code blocks in API documentation
- Styled scrollbars for
.api-sidebarand.sidebar-navwith webkit-specific and standard CSS properties
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| PowerForge.Web/Services/WebApiDocsGenerator.cs | Implements dedenting logic for XML code examples to fix alignment issues |
| PowerForge.Web/Assets/ApiDocs/fallback.css | Adds consistent scrollbar styling for API navigation sidebars |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| var line = lines[i]; | ||
| if (string.IsNullOrWhiteSpace(line)) continue; | ||
| var indent = 0; | ||
| while (indent < line.Length && line[indent] == ' ') indent++; |
There was a problem hiding this comment.
The Dedent method only counts space characters for indentation, but does not handle tab characters. If XML code examples use tabs for indentation, those lines will be treated as having zero indentation, which will cause incorrect dedenting behavior. Consider also counting tab characters or normalizing tabs to spaces before processing.
| while (indent < line.Length && line[indent] == ' ') indent++; | |
| while (indent < line.Length && (line[indent] == ' ' || line[indent] == '\t')) indent++; |
| if (string.IsNullOrWhiteSpace(line)) | ||
| sb.Append(""); | ||
| else |
There was a problem hiding this comment.
Appending an empty string has no effect. This line can be removed since the StringBuilder will already contain an empty string representation for blank lines (just the newline character from line 2115).
| if (string.IsNullOrWhiteSpace(line)) | |
| sb.Append(""); | |
| else | |
| if (!string.IsNullOrWhiteSpace(line)) |
|
|
||
| private static string Dedent(string code) | ||
| { | ||
| var lines = code.Split('\n'); |
There was a problem hiding this comment.
When splitting by '\n', any remaining '\r' characters from Windows line endings (\r\n) will be included in each line element. While this doesn't break the dedenting logic, it results in inconsistent line endings in the output. Consider splitting by '\n' and then trimming '\r' from each line, or using Split(new[] {"\r\n", "\n"}, StringSplitOptions.None) to handle both line ending styles consistently.
| var lines = code.Split('\n'); | |
| var lines = code.Split(new[] { "\r\n", "\n" }, StringSplitOptions.None); |