showdownjs / showdown

A bidirectional Markdown to HTML to Markdown converter written in Javascript
http://www.showdownjs.com/
MIT License
14.26k stars 1.56k forks source link

Code span started with newline parsed incorrectly #857

Closed kospl closed 2 years ago

kospl commented 3 years ago

Having this issue with large code block, I got tracked it down to minimal reproducable example:

` <div><\/div> `

that won't be parsed with v 1.9.1 as expected (<div></div>)

Live demo: http://demo.showdownjs.com/#!/%60%0A%3Cdiv%3E%3C%2Fdiv%3E%0A%60

Screenshot: image

Let me know if this can be fixed, thanks!

aote777 commented 2 years ago

图片 Me too

SyntaxRules commented 2 years ago

So this isn't a "Fenced code block" becuase "A code fence is a sequence of at least three consecutive backtick characters (`) or tildes (~)" Source Link

This is a "code span". Here is the closes example I can find: https://github.github.com/gfm/#example-346

aote777 commented 2 years ago

https://github.com/aote777/anki-md-template

上边那个显示错误我知道怎么回事了, 你必须保证传入showdown解析的时候是没有被转换为字符实体的. 不然你就会得到字符实体原样输出. 可以参考一下我写的anki转换模板.

kospl commented 2 years ago

@SyntaxRules thanks, changed title to be more appropriate.

Do you think this can be fixed soon? Not sure if this repo is still alive though, latest release was on 2019 (2 years ago).

kospl commented 2 years ago

Seems I got it, according to spec https://github.github.com/gfm/#container-blocks-and-leaf-blocks blocks are parsed first, so order has to be next:

  1. second line (with div tags) is parsed first because it's HTML considered to be a block structure (leaf block), and left as is.
  2. backticks parsed after that are considered inline (code span), so looking for closing backtick on same line, but found nothing, and left as is.
SyntaxRules commented 2 years ago

Thanks @kospl for looking deeper into this. I'm glad showdown is following the spec here. As for releases, hopefully we will have 2.0.0 version soon. There are a lot of backlog issues to go through before we can make that release.