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

Empty link, image, definition titles should output title="" on a, img #192

Open
wooorm opened this issue Jul 26, 2020 · 2 comments
Open

Comments

@wooorm
Copy link

wooorm commented Jul 26, 2020

The following CM:

[](<> ""), [](<> "x")

![](<> ""), ![](<> "x")

[][y], [][z]

![][y], ![][z]

[y]: <> ""
[z]: <> "w"

Yields:

<p><a href=""></a>, <a href="" title="x"></a></p>
<p><img src="" alt="" />, <img src="" alt="" title="x" /></p>
<p><a href=""></a>, <a href="" title="w"></a></p>
<p><img src="" alt="" />, <img src="" alt="" title="w" /></p>

I believe commonmark.js should output title="" if an empty title is defined in Markdown ("", '', ()). This might also be clarified in the spec with examples.

@jgm
Copy link
Member

jgm commented Jul 27, 2020

EDIT: Is this a theoretical question, or are there cases where it genuinely matters whether an empty title attribute is used or the title attribute is simply omitted?

@wooorm
Copy link
Author

wooorm commented Jul 27, 2020

It is rather meaningless, in HTML. Although there is a difference:

If this attribute is omitted from an element, then it implies that the title attribute of the nearest ancestor HTML element with a title attribute set is also relevant to this element. Setting the attribute overrides this, explicitly stating that the advisory information of any ancestors is not relevant to this element. Setting the attribute to the empty string indicates that the element has no advisory information.
https://html.spec.whatwg.org/multipage/dom.html#the-title-attribute

Hence, say there is an image in a link. If the link has a title, then the image will inherit that description. If the image has an empty title attribute, it would be removed explicitly.
Other cases would be if a title was set explicitly in wrapping HTML and then title explicitly set to empty in nested images / links.
As there is a clear difference between [](<>) and [](<> ""), I think it makes sense to support the difference between the two.


Background: I was recently looking at “empty” attributes. Other cases are:

[](), [](<>), ![](), ![](<>)

All produce a href="" or src="" respectively. There is also a difference between an a without href, and one with: w/o href, the link is a placeholder (the element represents a placeholder for where a link might otherwise have been placed, if it had been relevant, consisting of just the element's contents). Whereas an a w/ href="" means a link to the current document.
img elements are required to have src attributes.
The two images also produce alt="". I think this is the correct way to go: omitting alt means the user forgot to add alt text. alt="" means the image explicitly has no alt text. As markdown cannot differentiate between the two, alt="" makes the most sense.

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

2 participants