Closed bwplotka closed 3 years ago
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Still valid.
On Tue, 26 Jan 2021 at 17:37, stale[bot] notifications@github.com wrote:
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/yuin/goldmark/issues/177#issuecomment-767707388, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABVA3OYMW7DNMKI3G6HYAQ3S334XFANCNFSM4VKXATUQ .
It will actually necessitate huge refactor :(
Basically, it treats tabs as spaces, at one point in program it counts the number of spaces, takes tabs as spaces, and then on other point it puts the spaces back, incorrectly. If I get the flow right.
The way I look at the code, when it reads the text in text/reader.go, it first detects the padding (by util/util.go IndentPosition), and then it puts the padding "back" in text/segment.go Value, where it adds Padding number of spaces to left.
This breaks however in code blocks, where there is a difference between tabs and spaces.
maybe I will be able to convince IndentPosition to ignore the \t paddings? but then it will randomly break when someone uses tabs for indenting the items...
however I am a bit confused why that doesn't happen without the item list. IndentPosition
never gets run in that case. 🤔
oh, the util... gets called just in listItemParser. OK
Yeah I got why 2 spaces instead of tab now
Goldmark treats tabs like 4 spaces, but normally in text (not in code block) <space><space><tab>
is still treated "like four spaces", because the tab "finishes" the spaces
because normally if you have
<space><space><space><space>something
<space><space><tab>something
those are at same width.
so anyway when you have <space><space><tab>
in the goimports
stuff, the list item parser sees "hey let's treat this as 4 spaces, but 2 spaces are for me as the list, so the code parser gets the remaining two", and it gives the code parser "<space><space>
" instead of tab.
Ugh.
No idea how to even approach this
I guess there can be a way for the code block parser to "cheat", and to look if the padding spaces are actually not spaces and they are tabs? We still have the buffer, we can look at the "padding positions" if they aren't actually tabs?
~But still, that would mean creating a new method of Segment, something like func (t *Segment) CodeBlockValue(buffer []byte) []byte {
, which can break someone that extends goldmark that implements its own Reader
~ uh I am stupid no
And btw, what would happen if following happens:
<tab><space><tab>foo
*.list
...*..sublist
......```Makefile
[tb].[t]text
......```
what even should be in the code block? .... I will look at commonmark, how it handles this tab/space mess
Thanks for debugging!
So: There is a way to hack markdownfmt to.. hide this? 🤔
I don't even know what should the correct behavior be :D
Oh that's easy: markdownfmt
has to deterministic. It's kind of stupid If I reformat md with markdownfmt
it will produce X and then if reformat again it produces Y and then again, it's X 🤦🏽
So: There is a way to hack markdownfmt to.. hide this? 🤔
I think it will require change in goldmark, possibly not backwards compatible (requiring new version), I am not sure :D
Although I am not sure why it is not deterministic in markdownfmt, but I guess that's a different story xD
(sorry @yuin for all the spam)
I'm afraid to say, I'm up to my neck in work every day. So I can not have time for this project. I promise to see this issue in the future.
I fixed it in https://github.com/yuin/goldmark/pull/187
However it is a breaking change because I needed to change Reader
interface. So strictly speaking we should increase major version and also import path to /v2
edit: hm, seems I fixed only one of the two bugs.
edit2: opened a second PR for the second bug
@karelbilek @bwplotka I've tried to fix this issue in 2ffadcefcf0c8ffe3a0baa3a96441eb3c9045cea with the way simpler than #187.
Could you confirm this issue is fixed?
I think this is still needed?
(see the testcases there)
https://github.com/yuin/goldmark/pull/188
there were actually two independent issues. One is the code starting with tab which you fixed (thx!), other is the empty line which is fixed by #188 (which is simple)
I've tested test cases in #188 with current head(2ffadce). It passes all test cases.
OK then! thanks. Then we can close. (or maybe add those test cases too but as you wish).
Thanks again.
On Sun, 7 Feb 2021 at 18:33 Yusuke Inuzuka notifications@github.com wrote:
I've tested test cases in #188 https://github.com/yuin/goldmark/pull/188 with current head(2ffadce https://github.com/yuin/goldmark/commit/2ffadcefcf0c8ffe3a0baa3a96441eb3c9045cea). It passes all test cases.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/yuin/goldmark/issues/177#issuecomment-774658615, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAZT4KVM2TAHKMGJSZDRE3S5Z275ANCNFSM4VKXATUQ .
@karelbilek, Thanks for your contribution!
Amazing!
@yuin that branch is still needed.
The tests were wrong, sorry. (It's hard to check as there is whitespace....)
Now I fixed the tests so they are actually testing the bug.
Thank you for the amazing project! 🤗
I think I found a small bug, which is a bit annoying in our markdown formatting project. Particular problem is showcased in this draft PR
v1.1.24
and latest6c741ae251abd461bb7b5ce28e7df7a9306bd005
go version go1.15 linux/amd64
go version go1.15 linux/amd64
Parsed nested code block (valid markdown):
I am pretty sure it's somehow easy to fix (: