Extra trailing line gets inserted to code blocks on saving
Describe the bug After i reopened a saved file, the formatting of the code block is wrong. See screenshots.
To Reproduce Steps to reproduce the behavior:
- create a new file
- write Text
- combine with code block
- save and close
- reopen
Expected behavior The reopened file should have the same formatting like before closing.
Screenshots
File i created:
Plain text:
After saving and reopening:
Client details:
- Windows 10 Pro 64bit
- Firefox 67.0.4 64bit
- Nextcloud 16.0.2
- Nextcloud Text 1.0.0
Edit: It seems the code block uses the blank line.
Might be related or have the same root cause as the plenty issues described in #593, so possibly a duplicate.
Still present with NC 20.0.7, markdown editor (by Robin Appelman) 2.3.3, qownnotes 21.1.3, see here.
Seems to happen only when using code blocks in lists, especially if the last line with the code block separator is indented:
test('failure with newline', () => {
const text = `
### Headline
* Some list item
\`\`\`
nano /var/www/html/config/config.php
\`\`\``
// markdown it already shows the issue
// expect(markdownit.render(text)).toBe("")
expect(markdownThroughEditor(markdownThroughEditor(text))).toBe(text)
})
The generated HTML that markdown it generates already contains a newline:
expect(received).toBe(expected) // Object.is equality
Expected: ""
Received: "<h3>Headline</h3>
<ul>
<li>
<p>Some list item</p>
<pre><code>nano /var/www/html/config/config.php
</code></pre>
</li>
</ul>
"
190 | \`\`\``
191 | // markdown it already shows the issue
> 192 | expect(markdownit.render(text)).toBe("")
| ^
193 | expect(markdownThroughEditor(markdownThroughEditor(text))).toBe(text)
194 | })
195 |
Not sure yet how to address that best yet though.
Seems to happen only when using code blocks in lists
Just creating a new file (md), adding a code block with text, saving/closing and re-opening does already trigger this issue (new line). I'm on NC24.0.1.
@XueSheng-GIT: can confirm this behavior on NC23.0.5. @juliushaertl: It definitely happens outside of lists too. Sounds dumb, maybe it is, but, couldn't you theoretically add a trim() to the codeblock renderer (bandaidy-solution, may have unintended side-effects, but surely better than one-liner code blocks devolving into unlimited empty lines, right)?
Issues still exist. Please resolve the new line issue in code blocks
Just creating a new file (md), adding a code block with text, saving/closing and re-opening does already trigger this issue (new line). I'm on NC24.0.1.
For me this happens only in the editor, but the markdown source file does not contain the newline. (on the master branch)
I think this is the same issue that was reported in #2344 which was fixed in #3321. So closing this.