-
-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Desktop: Fix rendering of tabs in code blocks #2446
Desktop: Fix rendering of tabs in code blocks #2446
Conversation
There are a few linter errors, probably due to the fact that I've imported recently the renderer into the repo. |
Yes, I'll check them out as soon as I can. They are coming up in files completely unrelated to this PR, so I thought maybe I branched at a bad time. I'll look into it. |
The problems exist on master prior to the branch.
…r-pasted-code-tabs
@mic704b just to clarify something: tabs are not converted to spaces in the editor, right? This is only for the preview, thus rendering, correct? I don't want my markdown be messed with. If I use a tab, I want a tab in my source file. |
If you enter a tab in the code block in Joplin, then the tab is converted to 4 spaces. This is the existing behaviour, I have not changed this here. If you copy code from outside Joplin that contains tabs, and paste into a code block, then those tabs will be retained in Joplin. This PR just means they will be displayed as 4 spaces (instead of 8). If you then copy that code and paste into another editor, those tabs will be there.
If I understand you correctly, then yes, your tabs will be completely retained. It concerns just how they are displayed. I thought it was important from a coder point of view, so wanted to make sure of that. |
@laurent22 this branch now also contains fixes for the various linter issues that are existing on master. The changes related to this PR topic are contained only in the first two commits on this branch. |
Thanks for the explanation @mic704b. Indeed it's useful as it means rendered code will take less horizontal space. |
Fixes #2330
Summary of the Issue
Tabs entered directly into the code block are rendered as 4 spaces.
Tabs pasted into the code block from an external source are rendered as 8 spaces.
Solution
The solution is a simple renderer plugin markdown-it-expand-tabs
The solution ensures the tabs are displayed correctly and consistently in Joplin code blocks, no matter the source.
It also ensures the tabs are kept as tabs, in order for Joplin to maintain the pasted code in its original form. This means the user can copy the code back out and get back exactly what they pasted in.
Comment
To build the
ElectronClient
, the new package (as well as all the otherjoplin-renderer
dependencies) need to be added to thepackage.json
. However for now, I've only added it to thejoplin-renderer
package.json
until a solution to the build problem is decided.