Patterns icon indicating copy to clipboard operation
Patterns copied to clipboard

Markdown: problem when rendering source with prepending whitespace

Open thet opened this issue 6 years ago • 3 comments

In a template like this:

<pre class="pat-markdown">
    ${context/text}
</pre>

Where ${context/text} outputs this:

    *This is markdown*

The rendered markdown is:

<pre class="pat-syntax-highlight" tabindex="0"><code data-inner="1">*This is markdown*</code></pre>

Instead of:

<p><em>This is markdown</em></p>

thet avatar Jan 22 '20 10:01 thet

I just realized that this is actually expected behavior. Prepending text with whitespace starts a code secion in markdown.

Solutions to the problem above is changing the template to:

<pre class="pat-markdown">${context/text/raw}</pre>

or

<pre class="pat-markdown"
    >${context/text/raw}
</pre>

or

<pre class="pat-markdown">
 ${context/text/raw}
</pre>

However, this can easily been overlooked and lead into unnecessary bug hunting. Not sure how to handle this except by documentation.

thet avatar Jan 22 '20 11:01 thet

@pilz @cornae would like to get your opinions here.

thet avatar Jan 22 '20 11:01 thet

My 2 cents: In OiRA we also use pat-markdown. There we have learned to never prepend whitespace in any <pre> tag, like you show in your solutions 1 and 2 above.

I think it is the very nature of the <pre> tag to render everything literally, including spaces. So I think the problem described here is independent of pat-markdown. The <pre> tag simply needs to be used correctly.

And yes,

a block of text with 4 prepended spaces is rendered as code in markdown.

Even here :) It seems that you stumbled over a problem that was caused by an unfortunate combination of 2 different effects.

pysailor avatar Jan 22 '20 12:01 pysailor