Skip to content
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

Merged
merged 7 commits into from
Feb 5, 2020

Conversation

miciasto
Copy link
Contributor

@miciasto miciasto commented Feb 5, 2020

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 other joplin-renderer dependencies) need to be added to the package.json. However for now, I've only added it to the joplin-renderer package.json until a solution to the build problem is decided.

@laurent22
Copy link
Owner

There are a few linter errors, probably due to the fact that I've imported recently the renderer into the repo.

@miciasto
Copy link
Contributor Author

miciasto commented Feb 5, 2020

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.

@tessus
Copy link
Collaborator

tessus commented Feb 5, 2020

@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.

@miciasto
Copy link
Contributor Author

miciasto commented Feb 5, 2020

just to clarify something: tabs are not converted to spaces in the editor, right? This is only for the preview, thus rendering, correct?

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.

I don't want my markdown be messed with. If I use a tab, I want a tab in my source file.

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.

@miciasto
Copy link
Contributor Author

miciasto commented Feb 5, 2020

There are a few linter errors, probably due to the fact that I've imported recently the renderer into the repo.

@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.

@laurent22
Copy link
Owner

Thanks for the explanation @mic704b. Indeed it's useful as it means rendered code will take less horizontal space.

@laurent22 laurent22 merged commit 5128190 into laurent22:master Feb 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pasted tab character is rendered as 8 characters long in codeblock
3 participants