Skip to content

Clarification required on ideal markup for multiline code in <pre> tag. #9596

@Girgias

Description

@Girgias

This has come up in a discussion about changing the markup of the PHP highlight_string() and highlight_file() functions.

My understanding is that the markup should be as follows:

<pre><code>
<?php
function foo() {
    echo "Hello world";
}
?>
</code></pre>

And if one would to add syntactic colouring, one would go about by adding <span> tags as follows:

<pre><code>
<span class="tag"><?php</span>
<span class="keyword">function</span> <span class="name">foo</span>() {
    <span class="keyword">echo</span> <span class="string">"Hello world"</span>;
}
<span class="tag">?></span>
</code></pre>

However, the following MDN note:

The <code> element by itself only represents a single phrase of code or line of code.

Leads to the interpretation that the following markup is acceptable:

<pre>
<code class="tag"><?php</code>
<code class="keyword">function</code> <code class="name">foo</code>() {
    <code class="keyword">echo</code> <code class="string">"Hello world"</code>;
}
<code class="tag">?></code>
</pre>

However, in the current living document there is no mention of doing the above and the examples provides for the <code> tag and <pre> tag only demonstrate using a single <code> tag.

Moreover, the markup used by the living document follows the markup of using only one <code> tag and using custom elements for individual pieces to syntactically highlight.

I think it would be a good idea to clarify more how the <code> tag should be used. As the current specification seems to be lacklustre on details.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions