remark icon indicating copy to clipboard operation
remark copied to clipboard

code blocks not rendered if newlines present

Open utdrmac opened this issue 7 years ago • 10 comments

Consider the following slide. Note that the code blocks do not have a newline separating them from the bullet-point lines. This is intentional in order to achieve bullet-indented code blocks and this works fine. However, if you add a newline inside one of the codeblocks, to separate lines 'node1' and 'node2', the codeblock is no longer recognized.

Now look at this slide. You'll notice there are now newlines between the codeblocks and a newline within the codeblock. This is closer to the intended result, however, the codeblocks are no longer "indented" with the bullets as they were before.

How can I achieve the result of having "intended" codeblocks as in slide 1 but also support newlines like slide 2?

utdrmac avatar Mar 09 '17 22:03 utdrmac

My apologies for using pastebin. github won't let you do codeblock within codeblock.

utdrmac avatar Mar 09 '17 22:03 utdrmac

You simply need to indent your code block. Eg:

  • bullet point
  • bullet point (indent) ```sql (indent) your code block... (indent) ```
  • bullet point

joel-porquet avatar Apr 06 '17 18:04 joel-porquet

@joel-porquet thanks. I'll give it a try.

utdrmac avatar Apr 11 '17 17:04 utdrmac

@joel-porquet Gave it a try as you suggested. Your solution, unfortunately, adds extra linebreaks in the rendered HTML.

utdrmac avatar Apr 12 '17 21:04 utdrmac

Where? Can you copy the HTML output maybe and point to where there shouldn't be linebreaks?

joel-porquet avatar Apr 12 '17 22:04 joel-porquet

Take a look at these screenshots. You can see in the last screenshot, I added space in the remark code along with your suggestion of indenting all the blocks. You'll notice in the rendered HTML, there are additional newlines above and below the codeblocks.

screen shot 2017-04-12 at 5 28 24 pm screen shot 2017-04-12 at 5 28 46 pm screen shot 2017-04-12 at 5 29 12 pm

utdrmac avatar Apr 12 '17 22:04 utdrmac

Well, it just means that you can't add new lines in between your bullets and your codeblocks in the source file.

The reason is that each empty line ends the current paragraph and starts a new one.

But if you're able to obtain a HTML result that looks like what you want (which seems to be the case in your first screenshot), then I don't see the issue (apart from the fact that your source code might look a bit packed, but well...) :)

joel-porquet avatar Apr 12 '17 22:04 joel-porquet

Some more examples. The 3rd screenshot demonstrates the main issue of line breaks within codeblocks. If I indent the code block 2 spaces inward, then extra linebreaks are added to the rendered HTML as seen in screenshot 1. Screenshot 2 demonstrates proper handling of linebreaks within the codeblocks, but the codeblocks are no longer indented with the bullet points in the rendered html.

screen shot 2017-04-13 at 2 23 20 pm screen shot 2017-04-13 at 2 23 41 pm screen shot 2017-04-13 at 2 24 51 pm

utdrmac avatar Apr 13 '17 19:04 utdrmac

This is the result I'm after. But you'll notice I had to remove the linebreak within the codeblock in order to get the right rendered HTML. So, this is a bug.

screen shot 2017-04-13 at 2 30 34 pm

utdrmac avatar Apr 13 '17 19:04 utdrmac

It seems like adding the newline within the codeblock transform the second bullet point into a paragraph for some reason. I just tried on a simple example, and I can reproduce the "issue" (if it's really one - AFAIK, it could be like that by design).

First code:

* my first bullet
* my second bullet
    ```sql
    -- This is a comment
    -- This is a comment too
    node3# iptables -A INPUT; \
        iptables -A OUTPUT; \
        iptables -A OUTPUT -j DROP;
    ```
* my last bullet point

The generated HTML code is:

<ul>
<li>my first bullet</li>
<li>my second bullet<pre><code class="sql hljs remark-code"><div class="remark-code-line"><span class="hljs-comment">-- Pay attention to the indentation</span></div><div class="remark-code-line"><span class="hljs-comment">-- This is a comment</span></div><div class="remark-code-line">node3# iptables -A INPUT; \</div><div class="remark-code-line">    iptables -A OUTPUT; \</div><div class="remark-code-line">    iptables -A OUTPUT -j <span class="hljs-keyword">DROP</span>;</div></code></pre>
</li>
<li>my last bullet point</li>
</ul>

Now, when adding a new line in the codeblock:

* my first bullet
* my second bullet
    ```sql
    -- This is a comment
    -- This is a comment too

    node3# iptables -A INPUT; \
        iptables -A OUTPUT; \
        iptables -A OUTPUT -j DROP;
    ```
* my last bullet point

The generated HTML is (notice the <p></p> around the second bullet):

<ul>
<li>my first bullet</li>
<li><p>my second bullet</p>
<pre><code class="sql hljs remark-code"><div class="remark-code-line"><span class="hljs-comment">-- Pay attention to the indentation</span></div><div class="remark-code-line"><span class="hljs-comment">-- This is a comment</span></div><div class="remark-code-line"></div><div class="remark-code-line">node3# iptables -A INPUT; \</div><div class="remark-code-line">    iptables -A OUTPUT; \</div><div class="remark-code-line">    iptables -A OUTPUT -j <span class="hljs-keyword">DROP</span>;</div></code></pre>
</li>
<li>my last bullet point</li>
</ul>

Maybe someone else can give their opinion, as I don't know if it's an expected behavior.

joel-porquet avatar Apr 13 '17 19:04 joel-porquet