Skip to content

fix: Improve CodeGroupExtension with better language parsing and attribute preservation#9

Open
dereuromark wants to merge 1 commit intojosbeir:mainfrom
dereuromark:fix/code-group-extension-improvements
Open

fix: Improve CodeGroupExtension with better language parsing and attribute preservation#9
dereuromark wants to merge 1 commit intojosbeir:mainfrom
dereuromark:fix/code-group-extension-improvements

Conversation

@dereuromark
Copy link
Copy Markdown

Summary

This PR improves the CodeGroupExtension with changes aligned with djot-php's upstream implementation.

Bug Fixes

  • Language regex now supports special characters (c++, c#, text/html, etc.)
    • Old regex: /[A-Za-z0-9_-]+/ - only alphanumeric, underscore, dash
    • New regex: /[^\s\[]+/ - any non-whitespace characters

New Features

  • Attribute preservation: custom id, classes, and data-* attributes from the div are now preserved in the rendered output
  • Multiple custom classes are merged with glaze-code-group class

Example

{#my-code .custom-theme data-section="intro"}
::: code-group
``` php
$config = [];

:::


Now renders:
```html
<div class="glaze-code-group custom-theme" id="my-code" data-section="intro" role="tablist">
  ...
</div>

Dependencies

Requires: php-collective/djot ^0.1.21 for attribute preservation to work (contains fix for class merging in fenced divs - php-collective/djot-php#137)

Related

…ibute preservation

This PR improves the CodeGroupExtension with changes aligned with djot-php's
upstream CodeGroupExtension implementation:

**Bug fixes:**
- Language regex now supports special characters (c++, c#, text/html, etc.)
  - Old regex: `/[A-Za-z0-9_-]+/` - only alphanumeric
  - New regex: `/[^\s\[]+/` - any non-whitespace chars

**New features:**
- Attribute preservation: custom id, classes, and data-* attributes from the
  div are now preserved in the rendered output
- Multiple custom classes are merged with glaze-code-group class

**Requires:** php-collective/djot ^0.1.21 for attribute preservation to work
(contains fix for class merging in fenced divs)

Aligned with: php-collective/djot-php#132
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.

1 participant