Closed
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
A refactor of the li() method to replace regex-based task list detection with manual character checks and to streamline paragraph interruption and tag removal.
- Replaced
preg_matchlogic with manual substring checks for task checkbox markers. - Introduced an
$interruptedflag for blank-line interruption handling. - Enhanced paragraph tag stripping to remove both opening and closing
<p>correctly.
Comments suppressed due to low confidence (1)
src/ParsedownExtended.php:2185
- Consider adding unit tests to cover the new task list detection logic in both legacy and non-legacy branches, including cases with checked and unchecked items, and paragraph interruption scenarios.
$interrupted = in_array('', $lines, true);
Comment on lines
+2190
to
2205
| $firstFour = substr($markup, 4, 4); | ||
| $checked = false; | ||
| if ( | ||
| isset($firstFour[0], $firstFour[1], $firstFour[2], $firstFour[3]) && | ||
| $firstFour[0] === '[' && | ||
| $firstFour[2] === ']' && | ||
| ($firstFour[1] === ' ' || $firstFour[1] === 'x' || $firstFour[1] === 'X') | ||
| ) { | ||
| $checked = ($firstFour[1] === 'x' || $firstFour[1] === 'X'); | ||
| $replace = '<input type="checkbox" disabled="disabled"'; | ||
| if ($checked) { | ||
| $replace .= ' checked="checked"'; | ||
| } | ||
| $replace .= ' />'; | ||
| $markup = substr_replace($markup, $replace, 4, 4); | ||
| } |
There was a problem hiding this comment.
[nitpick] There's duplicated manual task list detection logic in both the legacy and non-legacy branches – consider extracting this into a helper method to reduce code duplication and improve readability.
Suggested change
| $firstFour = substr($markup, 4, 4); | |
| $checked = false; | |
| if ( | |
| isset($firstFour[0], $firstFour[1], $firstFour[2], $firstFour[3]) && | |
| $firstFour[0] === '[' && | |
| $firstFour[2] === ']' && | |
| ($firstFour[1] === ' ' || $firstFour[1] === 'x' || $firstFour[1] === 'X') | |
| ) { | |
| $checked = ($firstFour[1] === 'x' || $firstFour[1] === 'X'); | |
| $replace = '<input type="checkbox" disabled="disabled"'; | |
| if ($checked) { | |
| $replace .= ' checked="checked"'; | |
| } | |
| $replace .= ' />'; | |
| $markup = substr_replace($markup, $replace, 4, 4); | |
| } | |
| $markup = $this->processTaskListItem($markup); |
Comment on lines
+2222
to
+2223
| $text =& $Elements[0]['handler']['argument']; | ||
| $firstFour = substr($text, 0, 4); |
There was a problem hiding this comment.
[nitpick] Using the reference operator & when assigning $text can be confusing; consider modifying $Elements[0]['handler']['argument'] directly instead of using a variable reference.
Suggested change
| $text =& $Elements[0]['handler']['argument']; | |
| $firstFour = substr($text, 0, 4); | |
| $firstFour = substr($Elements[0]['handler']['argument'], 0, 4); |
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.
Summary
liby eliminating regexTesting
vendor/bin/phpunit --version(fails: command not found)https://chatgpt.com/codex/tasks/task_e_686bd62da0f48321b338519e54b40c48