shurcooL/markdownfmt

Paragraph unwrapping missing spaces

moorereason opened this issue · 5 comments

Given the following paragraphs:

text
[link](https://github.com)

text
*italic*

text
**bold**

text
***massive***

text
`noformat`

markdownfmt yields:

text[link](https://github.com)

text*italic*

text**bold**

text***massive***

text`noformat`

I expect it to yield:

text [link](https://github.com)

text *italic*

text **bold**

text ***massive***

text `noformat`

There may be other instances where formatting inside a paragraph gets rendered in a similar way. I only tests these.

This looks like a legitimate bug. I agree with your expected output. Thanks for reporting.

I don't have a lot of bandwidth for this project, but I will try to look into it. If someone else is willing to dig into code (it's not my prettiest Go code), help is welcome.

Can you give me some pointers? I'm trying to understand how blackfriday+markdownfmt work together. Which functions should I target?

If I add out.WriteString(" ") to L370, it seems to fix it, but I'm not sure what the ramifications are. That change does cause the "Test" and "Example" tests to fail.

My edit:

369   if string(text) == "\n" { // TODO: See if this can be cleaned up... It's needed for lists.
370       out.WriteString(" ")
371       return
372   }

Do you remember what that TODO comment was about? Also, how do I utilize the debug package?

Blackfriday is used to parse the Markdown. Markdownfmt provides a blackfriday.Renderer implementation which is used to render formatted Markdown (rather than HTML).

NormalText and skipSpaceIfNeededNormalText are very likely relevant. However, as you can see, it's not super clean. There are some hardcoded edge cases to fix lists, etc. The goal is to solve this, but not break existing tests.

I see that the problem does not occur for these cases:

text
text

[link](https://github.com)
text

*italic*
text

**bold**
text

***massive***
text

`noformat`
text

It gets correctly formatted to:

text text

[link](https://github.com) text

*italic* text

**bold** text

***massive*** text

`noformat` text

I would try to look into what causes the difference.

I have a fix for this.