Output of example 516

Example 516
![[[foo](uri1)](uri2)](uri3)

Proposed result:

<p><img src="uri3" alt="[foo](uri2)" /></p>

shouldn’t be:?

<p><img src="uri3" alt="foo uri1 uri2" /></p>

This example is quite complicated and furthermore it requires also the knowledge of the subsequent chapter about the images so it may be a little bit confusing.

But it is imho correct in respect to the spec wording. So lets go slowly, step by step:

  1. The specs says “links may not contain other links, at any level of nesting.” I.e., in human informal wording, if they do, then they are not links. Yet in other informal words, only the innermost link is the valid one and the outer one is just a verbatim text.

    Lets apply this at the stuff inside the image in the example. The snippet

    [[foo](uri1)](uri2)
    

    then translates to

    [<a href="uri1">foo</a>](uri2)
    

    (without some <p>...</p>, because here it is just a snippet from something bigger and not a standalone paragraph.)

  2. Images are not links and they are allowed to contain links. However the spec recommends in the section 6.6 to render the alt text for images without any nested HTML. Therefore the HTML output above is de-HTMLized. I.e. here, the HTML tags <a...> and </a> are removed and only the remaining plain text remains:

    [foo](uri2)
    

    And that is what is used as the alt text of the enclosing image.

Hope this helps.

3 Likes

Could you please detail in what part of the spec it describes the exact way of doing point 2)?

Also in what part of the spec it says what part of the content get lost in the final alt attribute? (in this case “uri1”)

In my opinion your interpretation is one possible interpretation of different ones that would be not opposed to the spec.

My proposal is to either remove this example from the spec or either to detail in much more precision all the steps in order to calculate the “alt” text content.

Could you please detail in what part of the spec it describes the exact way of doing point 2)?

Copied from Chapter 6.6., between the examples 571 and 572:

Though this spec is concerned with parsing, not rendering, it is recommended that in rendering to HTML, only the plain string content of the image description be used. Note that in the above example, the alt attribute’s value is foo bar , not foo [bar](/url) or foo <a href="/url">bar</a> . Only the plain string content is rendered, without formatting.

Also in what part of the spec it says what part of the content get lost in the final alt attribute? (in this case “uri1”)

This is due the same text. The parser parses it including the uri1. The HTML generator then throws it away together with the complete <a> tag.

In my opinion your interpretation is one possible interpretation of different ones that would be not opposed to the spec.

Indeed. The specification is about parsing, not about generating HTML. It’s only recommendation. However the examples (and their expected output) as provided within the specification follow the recommendation.

1 Like