Skip to content
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

Merged
merged 4 commits into from Dec 8, 2014
Merged

Conversation

attiks
Copy link
Contributor

@attiks attiks commented Dec 7, 2014

This PR adds support for any attribute as discussed in #93

Examples:

  • {:data-group=test}
  • {:rel=nofollow}

@michelf
Copy link
Owner

michelf commented Dec 7, 2014

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 key=val?

@attiks
Copy link
Contributor Author

attiks commented Dec 7, 2014

I added !$this->no_markup &&

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.

@michelf
Copy link
Owner

michelf commented Dec 7, 2014

I'd rather have key=val. Especially since there's already a precedent of doing it like this in another implementation (maruku).

@attiks
Copy link
Contributor Author

attiks commented Dec 7, 2014

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] . '"';
Copy link
Owner

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.

@michelf
Copy link
Owner

michelf commented Dec 7, 2014

a-z as the first character

Why not A-Z too?

@attiks
Copy link
Contributor Author

attiks commented Dec 7, 2014

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.

@michelf
Copy link
Owner

michelf commented Dec 7, 2014

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.

@attiks
Copy link
Contributor Author

attiks commented Dec 7, 2014

Thanks

@michelf michelf merged commit abb587a into michelf:lib Dec 8, 2014
@attiks attiks deleted the add-attribute-support branch December 8, 2014 07:42
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.

None yet

2 participants