text icon indicating copy to clipboard operation
text copied to clipboard

Extra trailing line gets inserted to code blocks on saving

Open akjir opened this issue 6 years ago • 7 comments

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:

  1. create a new file
  2. write Text
  3. combine with code block
  4. save and close
  5. reopen

Expected behavior The reopened file should have the same formatting like before closing.

Screenshots

File i created:

1

Plain text:

2

After saving and reopening:

3

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.

akjir avatar Jul 09 '19 19:07 akjir

Might be related or have the same root cause as the plenty issues described in #593, so possibly a duplicate.

claell avatar Mar 13 '21 11:03 claell

Still present with NC 20.0.7, markdown editor (by Robin Appelman) 2.3.3, qownnotes 21.1.3, see here.

herrdeh avatar May 02 '21 09:05 herrdeh

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.

juliusknorr avatar Jun 07 '22 13:06 juliusknorr

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 avatar Jun 07 '22 14:06 XueSheng-GIT

@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)?

Praetorian1410 avatar Jun 07 '22 17:06 Praetorian1410

Issues still exist. Please resolve the new line issue in code blocks

the-s-a-m avatar Jul 23 '22 15:07 the-s-a-m

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)

susnux avatar Jul 24 '22 13:07 susnux

I think this is the same issue that was reported in #2344 which was fixed in #3321. So closing this.

max-nextcloud avatar Nov 23 '22 19:11 max-nextcloud