Mobile app version of vmapp.org
Login or Join
Jennifer507

: Html: Should be placed within a paragraph? Markdown creates output like this: <p>see this example:</p> <pre><code>code</code></pre> Is this correct or should it be:

@Jennifer507

Posted in: #Html

Markdown creates output like this:

<p>see this example:</p>
<pre><code>code</code></pre>


Is this correct or should it be:

<p>see this example
<pre><code>code</code></pre>
</p>


To me the second one seems correct, since the paragraph and the code example are one unit. What are your thoughts about this?

edit: actually I could argue the same about a list (eg "order any of the following:") but a list can't be placed withing a paragraph.

edit2: to clarify, technically both are correct, as a table based layout is technically possible. But what would you argue is the way that best expresses the intention of the tags given a paragraph like this? Or maybe it doesn't matter? Note that the pre element isn't very relevant here (but included because markdown outputs it too).

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Jennifer507

2 Comments

Sorted by latest first Latest Oldest Best

 

@Kristi941

As John said, code is an in-line element, and can be placed in paragraphs. (Not necessarily should; there are plenty of other places it's also allowed.) Either your title or examples above are wrong, so I'll cover both possible cases, stealing from Gruber's docs.

To produce a code block requires pre, which is a block element and isn't allowed inside a p tag.
Use the following Markdown:

This is a normal paragraph:

This is a code block.


...which will output:

<p>This is a normal paragraph:</p>
<pre><code>This is a code block.</code></pre>


as you showed above.
Markdown is correct in doing this; the paragraph and code are related, but they're not a unit. (But as I said in my comment above, I'm unclear whether this is what you're actually trying to do.)

 

To produce an in-line code element, you should be using the following Markdown:

Use the `printf()` function.


...which will output:

<p>Use the <code>printf()</code> function.</p>

10% popularity Vote Up Vote Down


 

@Sarah324

According to the w3c <code> is an inline element so it can be placed inside a <p> element.

FYI, your <pre> tag is redundant. Not only do most user-agents display content as if it was wrapped in a <pre> (e.g. no word wrap and monospace type) but you should be using CSS to control the presentation of <code> elements anyway.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme