Issue with Codeblocks

Operating system

Windows

Joplin version

3.3.12

Desktop version info

Joplin 3.3.12 (prod, win32)

Device: win32, 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
Client ID: 46ebe00c537f48049cc5566fa9c12eb5
Sync Version: 3
Profile Version: 47
Keychain Supported: Yes
Alternative instance ID: -

Revision: 4d790b6

Backup: 1.4.3
Freehand Drawing: 3.0.1

Editor

Rich Text Editor

What issue do you have?

So I have this issue with code blocks. I've been using them fine for a few weeks, but recently I've notifed some code blocks are for want of a better word - corrupting.

They will look fine in editor view, but if I were to close joplin and re-open OR as I've tested, switched to markup, change nothing then switch back to editor, they block will deform.

This is not all of them , which is what is puzzling.

A point about my notes, I'm using a 2 column table to help with layout and I'll insert some text and a related codeblock within a cell.

If click into the corrupted codeblock I will only see a proportion of the text that should be contained within it.

Here is the code that seems to repeatedly cause an issue

template = '{0}, {1} and {2}'
template.format ('spam', 'ham', 'eggs') #format by position

template = '{motto}, {pork} and {food}'
template.format (motto='spam', pork='ham', food='eggs') #format by keyword

template = '{motto}, {0} and {food}'
template.format ('ham', motto='spam', food='eggs') #format by both keyword and position

template = '{}, {} and {}'
template.format ('spam', 'ham', 'eggs') #format by relative position in python 2.7 and 3.1

Any help would be appreciated. I do have a screenshot of how it looks fine, but I can only upload one for newcomer rules.

Screenshots

Screenshot straight after typing codeblock

and straight after switching to markup and back

seems to be a bug, I can re-create the same behavior when there's a code block in a table

It only seems to happen if there's line breaks in the code block. For example:

Test
ABC
123

Will work fine after switching editors

But:

Test
ABC

123

Will become skewed (you'll no longer see the 123 line)

I think it's this issue (or a variant of it): Rich Text mode: embedding “Code block” inside tables injects raw HTML tags · Issue #12189 · laurent22/joplin · GitHub

Appreciate you digging into this.

I did some arbritrary testing myself.

Outside of table cell, my sample code no issue whatsoever.

In cell I gradually increased the number of lines and sure enough started to break after the first line break as you noted.

The fact it's a bug is a slight annoyance, however having a workaround (no breaks) will keep me from losing my hair.

Thank you

Just one word of caution: Code blocks inside tables are not supported in most markdown standards. For example in Github flavored Markdown:

Block-level elements cannot be inserted in a table.

I guess the table is converted to HTML in this case, which makes it less readable. So if you want to edit your notes with the Markdown editor at some time in the future, I would recommend not to use (code) blocks within tables. This is a limitation of Markdown. If you are using the rich text editor only, it's fine I guess.

1 Like

Thanks for that consideration. Yeah, I should be ok as I'm not the biggest fan of the markdown mode - I just wanted to scribble some notes down without the added faff that markdown requires.

I appreciate your response though, thank you.

2 Likes