facelessuser / sublime-markdown-popups

Markdown popup dependency for Sublime
https://facelessuser.github.io/sublime-markdown-popups/
Other
112 stars 13 forks source link

Stray empty lines when creating code blocks using indentation #116

Closed rchl closed 3 years ago

rchl commented 3 years ago

There are some stray empty lines added with markdown like:

Examples:

    res.json(null);
    res.json({ user: 'tj' });
    res.status(500).json('oh noes!');
    res.status(404).json('I dont have that');

An example for testing from the console:

mdpopups.show_popup(view, '''Examples:

    res.json(null);
    res.json({ user: 'tj' });
    res.status(500).json('oh noes!');
    res.status(404).json('I dont have that');''')

This produces:

<p>Examples:</p>
<div class="highlight"><pre><span style="color: #d8dee9;">res.json(null);</span><br><span style="color: #d8dee9;">res.json({ user: 'tj' });</span><br><span style="color: #d8dee9;">res.status(500).json('oh noes!');</span><br><span style="color: #d8dee9;">res.status(404).json('I dont have that');</span><br><span style="color: #d8dee9;">&nbsp;</span><br><span style="color: #d8dee9;">&nbsp;</span><br></pre></div>

Screenshot 2021-02-02 at 16 24 47

It works correctly when the code is followed by unindented line, for example:

mdpopups.show_popup(view, '''Examples:

    res.json(null);
    res.json({ user: 'tj' });
    res.status(500).json('oh noes!');
    res.status(404).json('I dont have that');
Hey''')

Screenshot 2021-02-02 at 16 25 33

facelessuser commented 3 years ago

I'll take a look. We might be doing something funny in the Sublime syntax highlighter.

facelessuser commented 3 years ago

This doesn't appear to be something innate with Python Markdown. Nor does it seem innate with any of the extensions, so it must be something in the custom highlighter for mdpopups.

facelessuser commented 3 years ago

Probably just need to rstrip() the source before highlighting it. I'll run some tests, but I'm betting that will fix it.

facelessuser commented 3 years ago

Yup, Pygments always strips trailing empty lines in code blocks, and Python Markdown seems to do the same to code blocks at the very end. Should they? That is a subjective question as CommonMark and some others will preserve empty lines at the tail of a fenced code block (not an indented code block). Is that useful? 🤷

So, multiple lines actually come from the Markdown parser. Not sure why, but they were always cleaned up at the end so you never see them, except with our homegrown ST highlighter. We don't rstrip() the tail because we didn't think to do so. That is why you are seeing the results that you are.

So, rstrip() is the way to at least bring consistency to everything.

facelessuser commented 3 years ago

So with the fix, this:

mdpopups.show_popup(view, '''Examples:

    res.json(null);
    res.json({ user: 'tj' });
    res.status(500).json('oh noes!');
    res.status(404).json('I dont have that');''')

Now yields:

Screen Shot 2021-02-08 at 6 03 12 PM

Sanity restored!