yogthos / markdown-clj

Markdown parser in Clojure
Eclipse Public License 1.0
540 stars 120 forks source link

Code quotes bug #136

Closed ilevd closed 7 years ago

ilevd commented 7 years ago

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>"
yogthos commented 7 years ago

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 7 years ago

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

yogthos commented 7 years ago

Ok yeah that looks like a bug

yogthos commented 7 years ago

Should be fixed by this commit https://github.com/yogthos/markdown-clj/commit/4c719e661550d9bc0d84c8c490fc8e7ed22d191f

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 7 years ago

@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"
yogthos commented 7 years ago

yeah looks like that still needs some work

yogthos commented 7 years ago

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 7 years ago

@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 ?
yogthos commented 7 years ago

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.

yogthos commented 7 years ago

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 7 years ago

@yogthos thank you for your work!

yogthos commented 7 years ago

no problem, thanks for bringing this up :)