Open
Conversation
- Add README_zh.md with complete Chinese translation - Add language switcher links in both README files - Maintain original formatting and code examples - Support bilingual documentation navigation
- 新增 InlineAfterDepth 编码选项,当嵌套深度超过指定级别时自动启用内联格式化 - 在 Encoder 结构体中添加深度跟踪字段 - 修改 encodeValue 函数以在适当的深度动态切换到 flow 样式 - 添加全面的测试用例验证功能正确性 - 提供示例程序演示不同深度阈值的效果 - 保持向后兼容性,不影响现有编码功能
- Add InlineAfterDepth encoding option - Implement depth tracking in Encoder - Add comprehensive tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🎯 Add InlineAfterDepth Option for Depth-Based Inline Formatting
This PR introduces a new encoding option
InlineAfterDepththat automatically switches to inline (flow) style formatting when YAML nesting depth exceeds a specified threshold. This feature is particularly useful for deeply nested configuration files, making them more compact while maintaining readability at higher levels.✨ Features
📝 Usage Examples
Basic Usage
Real-world Example (Clash Configuration)
🔄 Before/After Comparison
Standard Format:
With InlineAfterDepth(1):
With InlineAfterDepth(2):
🔧 Implementation Details
File Changes:
option.go: AddedInlineAfterDepth()function with validationencode.go: EnhancedEncoderstruct with depth tracking fields and logicinline_depth_test.go: Comprehensive test suite covering all scenariosDepth Tracking: Automatically increments/decrements depth when encoding complex types (structs, maps, arrays)
Flow Style Switching: Temporarily enables flow style when depth exceeds threshold, restores original style afterward
🧪 Testing Coverage
📊 Benefits
📋 Files Modified
option.go- New encoding option implementationencode.go- Depth tracking and inline formatting logicinline_depth_test.go- Comprehensive test suite.gitignore- Added examples/ directory to exclude temporary test files🚀 Ready for Production
This feature has been thoroughly tested and is ready for production use. It provides a powerful new way to control YAML formatting based on structural complexity, making it especially valuable for configuration management and data serialization scenarios.