yogthos/markdown-clj

Code quotes bug

ilevd opened this issue · 12 comments

ilevd commented

Then there is some spaces after code block, It produces code with quotes:

(markdown.core/md-to-html-string "```\n<html>\n</html>\n```  ")
=> "<pre><code>&lt;html&gt;\n&lt;/html&gt;\n``</code></pre>"

(markdown.core/md-to-html-string "```\n\n``` ")
=> "<pre><code>\n`</code></pre>"

Are you on the latest version of the library, this is what I see locally:

(markdown/md-to-html-string "```\n```")
=> "<pre><code><pre><code>\n"
ilevd commented

@yogthos yes, I have updated my first message with samples

Ok yeah that looks like a bug

Should be fixed by this commit 4c719e6

If you could try locally to confirm it looks good, I'll push out a new version. You can just clone the repo and run lein install to try a local verison.

ilevd commented

@yogthos, works fine now, but we overlooked a bug in your code snippet:

(markdown/md-to-html-string "```\n```")
=> "<pre><code><pre><code>\n"
; should be "<pre><code></code></pre>" 

Also

(markdown.core/md-to-html-string "```go\n```")
=> "<pre><code class=\"go\"><pre><code>\n"
; "<pre><code class=\"go\"></code></pre>"

And it seems this is not correct too:

(markdown.core/md-to-html-string "```go```")
=> "<pre><code class=\"go```\">\n"

yeah looks like that still needs some work

I added a fix for handling empty codeblocks, however I don't treat the last example isn't an actual code block since there isn't a new line there. There's already `...` available for inline code.

ilevd commented

@yogthos maybe the last example isn't a correct code, but shouldn't the library process it more accurate? :)
I just tried this code in online markdown editors - https://stackedit.io/editor, http://dillinger.io/ both of them for:

`go`
``go``
```go```
````go````

produce

<p>
<code>go</code><br>
<code>go</code><br>
<code>go</code><br>
<code>go</code>
</p>

Not sure that's right behavior, slack produces different html with backticks (inline, simple text, block, block with backticks)

(markdown.core/md-to-html-string "`go`\n``go``\n```go```\n````go````\n")
=> "<p><code>go</code> ``go``</p><pre><code class=\"go```\"></code></pre>"
; something strange

(markdown.core/md-to-html-string "```go```\n````go````")
=> "<p><pre><code class=\"go```\"></code></pre></p>"
; something strange

(markdown.core/md-to-html-string "```go\ncontent\n```")
=> "<pre><code class=\"go\">content\n</code></pre>"
; should there be \n ?

I guess that depends on what we mean by accurate. I think making the library more lenient in what it accepts makes it more unpredictable and leads to more edge cases. Since the code blocks are defined by having ``` on an empty line followed by code, a line with ``` for closing, I think it's reasonable to be explicit here.

I'm going to close this one, since correct output gets generated for the expected case. We can discuss an enhancement for supporting alternate syntax as a separate issue.

ilevd commented

@yogthos thank you for your work!

no problem, thanks for bringing this up :)