Skip to content

Conversation

@paveldedik
Copy link
Member

Fixes #125

This adds support for passing raw attributes that bypass the automatic underscore-to-dash conversion. This is useful for libraries like Datastar that use underscores as part of their DSL syntax.

Users can now pass an attrs parameter with a dictionary of attributes that should not be converted:

html.div("content", attrs={"data_store": "value"})
# Renders: <div data_store="value">content</div>

This works alongside regular attributes that continue to be converted:

html.button(
    "Click",
    class_="btn",
    attrs={"data-on-click_increment": "$store.count++"}
)
# Renders: <button class="btn" data-on-click_increment="$store.count++">Click</button>

Changes:

  • Added extract_raw_attrs() function to extract attrs parameter
  • Modified format_attrs() to handle raw attributes without conversion
  • Added comprehensive tests for the new functionality

Fixes #125

This adds support for passing raw attributes that bypass the automatic
underscore-to-dash conversion. This is useful for libraries like Datastar
that use underscores as part of their DSL syntax.

Users can now pass an `attrs` parameter with a dictionary of attributes
that should not be converted:

    html.div("content", attrs={"data_store": "value"})
    # Renders: <div data_store="value">content</div>

This works alongside regular attributes that continue to be converted:

    html.button(
        "Click",
        class_="btn",
        attrs={"data-on-click_increment": "$store.count++"}
    )
    # Renders: <button class="btn" data-on-click_increment="$store.count++">Click</button>

Changes:
- Added extract_raw_attrs() function to extract attrs parameter
- Modified format_attrs() to handle raw attributes without conversion
- Added comprehensive tests for the new functionality
@paveldedik paveldedik force-pushed the claude/fix-github-issue-125-011CUrXrnhc4JDBh1cz5Xqvp branch from 43192f1 to 4bb6507 Compare November 6, 2025 11:46
@codecov
Copy link

codecov bot commented Nov 6, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
ludic/attrs.py 100.00% <100.00%> (ø)
ludic/format.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Add test case for when a raw attribute has the same key as a
converted regular attribute, ensuring concatenation logic is covered.
Mapping[str, Any]: A dictionary containing raw attributes with keys as-is.
"""
extracted_attrs = {}
if (raw_attrs := attrs.get("attrs")) and isinstance(raw_attrs, dict):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it should warn the user that attrs is not a dict.
It might be that swallowing the attr silently is surprising.

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.

Ability to disable underscore -> dashes replacement

4 participants