yuin / goldmark

:trophy: A markdown parser written in Go. Easy to extend, standard(CommonMark) compliant, well structured.
MIT License
3.68k stars 255 forks source link

Table detection requires preceding empty line in contravention with GFM spec #148

Closed zeripath closed 4 years ago

zeripath commented 4 years ago

Please answer the following before submitting your issue:

  1. What version of goldmark are you using? : v1.1.32
  2. What version of Go are you using? : 1.14.6
  3. What operating system and processor architecture are you using? : Linux x86_64
  4. What did you do?
**xxx**
| hello |   hi  |
| :----: | :----:|
  1. What did you expect to see? :
<p><strong>xxx</strong></p>
<table role="table">
<thead>
<tr>
<th align="center">hello</th>
<th align="center">hi</th>
</tr>
</thead>
</table>
  1. What did you see instead? :
<strong>xxx</strong>
| hello |   hi  |
| :----: | :----:|
  1. Did you confirm your output is different from CommonMark online demo or other official renderer correspond with an extension?:

Yes differs from GFM

  1. (Feature request only): Why you can not implement it as an extension?:
    • You should avoid saying like "I'm not familiar with this project" "I'm not a Go programmer" as far as possible. This is an open source project and a library for Go programmers. I encourage you to strive to read source codes.
    • I absolutely welcome questions that are difficult even if you read the source codes. N/A

Dear @yuin,

Thank you so much for your work on Goldmark - it really is excellent.

A user on Gitea has noticed the above problem with the Table extension and reported it as https://github.com/go-gitea/gitea/issues/12376.

As far as I can see, I don't think that this is a bug specific to Gitea's use of Goldmark. The following code appears to replicate the issue:

package main

import (
    "bytes"
        "fmt"

    "github.com/yuin/goldmark"
    "github.com/yuin/goldmark/extension"
    "github.com/yuin/goldmark/parser"
    "github.com/yuin/goldmark/renderer/html"
)

func main() {

    md := goldmark.New(
        goldmark.WithExtensions(extension.GFM),
        goldmark.WithParserOptions(
            parser.WithAutoHeadingID(),
        ),
        goldmark.WithRendererOptions(
            html.WithHardWraps(),
            html.WithXHTML(),
        ),
    )
    var buf bytes.Buffer
    if err := md.Convert([]byte(`
**xxx**
| hello |   hi  |
| :----: | :----:|  
    `), &buf); err != nil {
        panic(err)
    }

    fmt.Println(buf.String())

}
jacky-2014-sn commented 4 years ago

As Github, when table is include in paragraph, It show as paragraph and table. Add a table check, then deal the lines before table as paragraph and the table will be table. So far,It works as Github. But, I worry about it has something others.

zeripath commented 4 years ago

Thanks @yuin!