-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Markdown containing tabs not converted properly to spaces #1559
Comments
@UziTech you are right! |
Marked should be more compliant with tabs. I think we should only replace the tabs at the start of a line. There is still one CommonMark test that is failing for tabs. marked/test/specs/commonmark/commonmark.0.29.json Lines 51 to 52 in 4584a8a
|
@UziTech sounds better! |
@smartankur4u I am going to answer your questions here:
Tab characters don't have an inherit size. The size can be set by the user. You choose to have them be size 4, I choose to have them be size 2, I know a developer who prefers them to be size 8. My point is that just because the input looks aligned with tabs to the user (who can define any size for a tab character) when converting them to spaces we have to pick an arbitrary size (in CommonMark spec that size is 4) so using tabs with that type of alignment never works for everyone. Which is why IMHO tabs should only be used for indentation not alignment.
According to the common mark spec only tabs at the beginning of a line (used for indentation) are converted to 4 spaces. All other tabs are left as tab characters. This does need to be fixed in marked to be spec compliant.
ParseDown PHP doesn't convert everything as every user expects. If the user doesn't have tab size set to 4 the alignment is off
Yes, I expect developers to understand their users better than me. If their users will always have tab size set to 4 than they can convert tabs using your const html = marked(tabToSpace(markdown)); |
Thanks for the reply @UziTech. |
Hello, my problem is that Marked is actually changing tabs into spaces. I need tabs to remain as tabs, that's why I put them in there. I can't copy/paste code snippets in markdown because the tabs are gone. Is there a way to force Marked to stop doing that? Thanks |
@jvalrog not currently. But we are always accepting PRs |
Only replaces tabs at the beginning of a block construct. Tabs in the middle of the item are unaffected. All tests passing. Tabs in both GFM and CommonMark at 100% fixes markedjs#1559
* fix: non leading-tabs in markdown content (#1559) Only replaces tabs at the beginning of a block construct. Tabs in the middle of the item are unaffected. All tests passing. Tabs in both GFM and CommonMark at 100% fixes #1559 * update new/html_comments.html to preserve tab * combine redundant if condition * add test for tab immediately after blockquote character
🎉 This issue has been resolved in version 4.0.14 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Markedjs by default changes leading tabs to spaces. More details: markedjs/marked#1559 As workaround we extract user suggestion from content of gr-formatted-text which has tabs and not spaces. Release-Notes: skip Google-Bug-Id: b/279925682 Change-Id: I0a6d0223b384838b29753c41437b9174dda0da46
Markedjs by default changes leading tabs to spaces. More details: markedjs/marked#1559 As workaround we extract user suggestion from content of gr-formatted-text which has tabs and not spaces. Release-Notes: skip Google-Bug-Id: b/279925682 Change-Id: I0a6d0223b384838b29753c41437b9174dda0da46 (cherry picked from commit a37ffe3)
Describe the bug
The package converts the tabs in the markdown to 4 spaces every time. It breaks the alignment of the text. It's not how tabs work. The tab indentation of the current tab in a string will be
tabsize - ((number of characters occupied in current tab buffer) % tabsize)
To Reproduce
Steps to reproduce the behaviour:
Below is the text that contains tabs that I am parsing to HTML.
# markdown alignment
Demo links:
The CommonMark was also not able to parse the tabs to appropriate number od spaces.
The ParseDown PHP package was able to parse the tabs in text to appropriate number of spaces. Its how any user will expect the HTML output to look like. You can paste the above given markdown text in ParseDown Demo
Expected behavior
When I am writing a markdown containing tabs, I will expect it to give the same alignment when converted to HTML. It how any user will expect.
I am using this text:
The arrows aren't aligned upon parsing. It gets parsed to HTML like this:
While, any user will expect it to be like this:
The text was updated successfully, but these errors were encountered: