New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for any attribute #186
Conversation
Nice. One thing I'll have to think about is security considerations. Currently someone can enable the no-markup mode and add a callback for changing URLs to filter javascript and other things that could be exploited in user-generated content. This PR pierces hole in those measures. Perhaps this feature should simply be disabled when the no-markup flag is set. Also, is there a reason for wanting a colon as a prefix? Why not simply accept |
I added Mainly to be consistent with the id and class attributes, since they are using a prefix as well, but I don't mind changing it. |
I'd rather have |
I removed the ':' and just checked for a-z as the first character |
$id = false; | ||
foreach ($elements as $element) { | ||
if ($element{0} == '.') { | ||
$classes[] = substr($element, 1); | ||
} else if ($element{0} == '#') { | ||
if ($id === false) $id = substr($element, 1); | ||
} else if (strpos($element, '=') > 0) { | ||
$parts = explode('=', $element); | ||
$attributes[] = $parts[0] . '="' . $parts[1] . '"'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably should use explode('=', $element, 2)
since a third equal sign shouldn't cause the attribute value to end. At least that's now HTML parses unquoted attributes.
Why not |
Common practice is to write attribute in lowercase only, the spec allows uppercase in theory, but all uppercase characters are - internally - converted to lowercase. The data- attribute spec demands lowercase only. |
I agree that from an authoring perspective it's best to use lowercase names. But from the parser's perspective, I'm not sure it's a good idea to ignore attributes blocks with attributes set in uppercase. I guess it's rare enough that we can only bother if someone reports the issue at some point. Will merge this shortly. |
Thanks |
This PR adds support for any attribute as discussed in #93
Examples:
{:data-group=test}
{:rel=nofollow}