Skip to content

Attribute name parsing converts double underscores to double hyphens, breaking some frontend frameworks #118

@watzon

Description

@watzon

Problem

The AttributesRenderer#parse_name method converts all underscores to hyphens:

private def parse_name(name) : String
  name.to_s.gsub("_", "-")
end

This works well for standard HTML attributes (e.g., data_foo_bar → data-foo-bar), but breaks frameworks that use double underscores as meaningful syntax.

For example, https://data-star.dev uses double underscores for action modifiers:
- `data-on:click__prevent` - prevents default behavior
- `data-on:click__debounce_500ms` - debounces the action

With the current implementation, "data-on:click__prevent" becomes data-on:click--prevent, which is invalid.

## Current Workaround

I'm monkey-patching parse_name in my adapter to preserve double underscores:

```crystal
module Blueprint::HTML::AttributesRenderer
  private def parse_name(name) : String
    result = name.to_s.gsub("__", "\x00\x01\x00")
    result = result.gsub("_", "-")
    result.gsub("\x00\x01\x00", "__")
  end
end

Suggested Solutions

  1. Preserve double underscores by default - Change parse_name to only convert single underscores, leaving __ intact.
  2. Make the conversion configurable - Allow users to customize or disable the underscore-to-hyphen conversion.

Would either of these approaches be acceptable? Happy to submit a PR if so.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions