Add the possibility to config the Markdown parser to add heading id attributes and load CommonMark extensions - #723
Merged
Conversation
…ttributes and load CommonMark extensions
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the Markdown parser by centralizing option handling, enabling automatic heading ID generation, and allowing extra CommonMark extensions to be loaded.
- Introduce
parseOptions()to extract parser configuration and extensions from input options - Add support for
addHeadingIdsviaDefaultAttributesExtensionand slugified IDs - Allow custom CommonMark extensions through a new
commonmarkExtensionsoption
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| formwork/src/Parsers/Markdown.php | Refactored parse() to use parseOptions(), load default attributes and user-specified extensions |
| formwork/src/Parsers/Extensions/CommonMark/FormworkExtension.php | Removed obsolete allowHtml schema entry |
| formwork/fields/markdown.php | Updated invocation sites to pass new options |
| formwork/config/views/methods.php | Updated invocation sites to pass new options |
| formwork/config/system.yaml | Added addHeadingIds and commonmarkExtensions defaults |
Comments suppressed due to low confidence (3)
formwork/src/Parsers/Markdown.php:40
- [nitpick] The variable name
addedExtensionscould be more descriptive (e.g.,loadedExtensions) to clarify that it tracks which extensions have been registered.
$addedExtensions = [];
formwork/src/Parsers/Markdown.php:70
- The docblock for
parseOptions()should list the recognized option keys (allowHtml,addHeadingIds,commonmarkExtensions) and their expected types to help future maintainers.
private static function parseOptions(array $options): array
formwork/src/Parsers/Markdown.php:87
- New behavior for
addHeadingIdsand slug generation is untested; please add unit tests to cover when this flag is enabled and verify generated IDs.
if ($options['addHeadingIds']) {
|
|
||
| if ($enabled) { | ||
| $extensions[] = $class; | ||
| $config = [...$config, ...$extensionConfig]; |
There was a problem hiding this comment.
Flattening all extension config directly into the root config may inadvertently override unrelated settings; consider merging nested configurations under their own namespace or using deep merge.
Suggested change
| $config = [...$config, ...$extensionConfig]; | |
| $config['extensions'] = [...($config['extensions'] ?? []), ...$extensionConfig]; |
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.
No description provided.