Skip to content

Conversation

@dereuromark
Copy link
Contributor

@dereuromark dereuromark commented Dec 21, 2025

Summary

Fixes nested [quote] tag handling in BbcodeToDjot converter and improves quote attribution formatting.

Changes

1. Fix Nested Quotes

The previous regex-based approach failed on nested quotes because .*? (non-greedy) matches to the first [/quote] regardless of nesting depth. Replaced with depth-tracking parser.

2. Proper Djot Caption Syntax

Changed from inline *Author wrote:* to proper Djot caption syntax (^ Author) which renders as <figcaption>.

3. Parse Quote Attributes

Extract ID, name, date/time from various BBCode quote formats:

Input Output
[quote=John] ^ John
[quote=John date="2024-01-01"] ^ John (2024-01-01)
[quote=John date="2024-01-01" time="12:30"] ^ John (2024-01-01 12:30)
[quote="9" name="admin" date="2024-01-01 12:30"] ^ admin (2024-01-01 12:30) #9
[quote id="42" name="user" date="2024-01-01"] ^ user (2024-01-01) #42

4. PHPStan Fixes

Fixed redundant $depth > 0 comparisons.

Test Plan

  • Added test cases for nested quote scenarios
  • Added tests for date/time attribute parsing
  • Added tests for full forum format with ID
  • All 35 BbcodeToDjot tests pass
  • Full test suite passes (1320 tests)
  • PHPStan passes with no errors

The previous regex-based approach using .*? (non-greedy) failed to
properly match nested [quote] tags because it would match from an
opening tag to the first closing tag, regardless of nesting.

For example: [quote=A]outer[quote=B]inner[/quote][/quote]
Would incorrectly match [quote=A]outer[quote=B]inner[/quote]
leaving an orphan [/quote] tag.

This fix replaces the regex approach with depth tracking that:
- Tracks nesting depth as it encounters opening/closing tags
- Properly matches each opening tag with its corresponding closing tag
- Recursively processes nested quotes to convert them all

Added 7 new test cases covering:
- Basic nested quotes with authors
- Deeply nested quotes (3 levels)
- Nested quotes without authors
- Text before/after quotes
- Multiple quotes at same level
- Complex quote attributes
@codecov
Copy link

codecov bot commented Dec 21, 2025

Codecov Report

❌ Patch coverage is 95.83333% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.40%. Comparing base (1ea357f) to head (2f3c970).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/Converter/BbcodeToDjot.php 95.83% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             master      #56   +/-   ##
=========================================
  Coverage     93.40%   93.40%           
- Complexity     1928     1952   +24     
=========================================
  Files            74       74           
  Lines          5183     5233   +50     
=========================================
+ Hits           4841     4888   +47     
- Misses          342      345    +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

- Remove redundant `$depth > 0` checks flagged by PHPStan
- Use proper Djot caption syntax `^ Author` after blockquote instead
  of inline `*Author wrote:*` within the quote
Extract date/time attributes from BBCode quote values and format
as "name (datetime)" in the caption. Handles:
- [quote=user] -> ^ user
- [quote=user date="2024-01-01"] -> ^ user (2024-01-01)
- [quote=user date="2024-01-01" time="12:30"] -> ^ user (2024-01-01 12:30)
Handle BBCode quote formats like:
- [quote="9" name="superadmin" date="2025-12-06 18:35:26"]
- [quote id="42" name="admin" date="2024-01-01"]

Output format: ^ name (datetime) #id
@dereuromark dereuromark merged commit 218a96b into master Dec 21, 2025
6 checks passed
@dereuromark dereuromark deleted the fix/nested-bbcode-quotes branch December 21, 2025 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants