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

rel attribute #388

Open
wintstar opened this issue Feb 3, 2023 · 8 comments
Open

rel attribute #388

wintstar opened this issue Feb 3, 2023 · 8 comments

Comments

@wintstar
Copy link

wintstar commented Feb 3, 2023

How to enter multiple attributes for rel?

php-markdown 2.0.0

$parser = new MarkdownExtra;
$parser->empty_element_suffix = ">";
$url = $parser->transform([Link](url){.link  target=_blank rel=noreferrer noopener});
echo $url;

This results
<a href="url" class="link" target="_blank" rel="noreferrer">Link</a>

noopener missing.

@michelf
Copy link
Owner

michelf commented Feb 3, 2023

You can use quotes:

[Link](url){.link  target=_blank rel="noreferrer noopener"}

@wintstar
Copy link
Author

wintstar commented Feb 3, 2023

Not work

[Link](url){.css target=_blank rel="noreferrer noopener"}

with quotes this result

<a href="url">Link</a>{.link target=_blank rel="noreferrer noopener"}

@michelf
Copy link
Owner

michelf commented Feb 3, 2023

I was confused. You're right: there's no way at the moment to have a space in a custom attribute. You can write the link in HTML form though (if the context allows HTML).

(Some work would need to be done in doExtraAttributes and the regular expressions above it to make that work.)

@wintstar
Copy link
Author

wintstar commented Feb 3, 2023

For the css attribute the following works
.css .link
[Link](url){.css .link target=_blank rel="noreferrer noopener"}

result
<a href="url" class="css link" target="_blank" rel="noreferrer">Link</a>

but not work with rel
rel=noreferrer rel=noopener
[Link](url){.css .link target=_blank rel="noreferrer rel=noopener"}

Could you do it like with the css attribute?

@wintstar
Copy link
Author

wintstar commented Feb 3, 2023

My solution

$parts = explode('=', $element, 2);
$attributes[] = $parts[0] . '="' . $parts[1] . '"';

change

				$parts = explode('=', $element, 2);
				$attributes[] = $parts[0] . '="' . $parts[1] . '"';

to

				$parts = explode('=', $element, 2);
				$parts[1] = preg_replace('~_~', ' ', $parts[1]);
				$attributes[] = $parts[0] . '="' . $parts[1] . '"';

replace the space with underscore

[Link](url){.link target=_blank rel="noreferrer_noopener"}

result
<a href="url" class="link" target="_blank" rel="noreferrer noopener">Link</a>

@cdp1337
Copy link

cdp1337 commented Feb 4, 2023

Won't work, given the example {.class name=my_field} Now you have name="my field" when you were expecting my_field.

In theory, potentially a better solution would be to support {.class_name rel=att1 rel=att2}, this also better matches your first comment of utilizing the multiple class functionality.

This would require more than just a 1-line change though. I've done something very similiar with another project and if Michelf is interested I could probably whip up something to accommodate this.

@wintstar
Copy link
Author

wintstar commented Feb 4, 2023

@cdp1337

It works. Also with the img tag. With the tag title there are now also no more problems with the spaces.

![alt-tag](path/to/image){.w3-image .w3-border .w3-padding title=title_text_with_space width=800 height=613 loading=lazy}

result
<img src="path/to/image" alt="alt-tag" class="w3-image w3-border w3-padding" title="title text with space" width="800" height="613" loading="lazy">

@michelf
Copy link
Owner

michelf commented Feb 5, 2023

It works using _, but it's not a great solution. People will expect things like target=_blank to work correctly too.

rel=att1 rel=att2 could be made to work, but it doesn't feel right since that's not how attributes work in HTML.

Adding support for quotes would be the best solution.

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

No branches or pull requests

3 participants