yuin / goldmark

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

`Node.Text` returns HTML elements as plain text (regression from 1.7.4) #471

Closed rhysd closed 2 hours ago

rhysd commented 2 hours ago

goldmark has https://github.com/yuin/goldmark/discussions in github. You should post only issues here. Feature requests and questions should be posted at discussions.

Please answer the following before submitting your issue:

  1. What version of goldmark are you using? : 1.7.8
  2. What version of Go are you using? : 1.23.1
  3. What operating system and processor architecture are you using? : macOS 13
  4. What did you do? : Ran the following code.
  5. What did you expect to see? : Expected to print "foo"
  6. What did you see instead? : Printed "<code>foo</code>", which means that the <code> and </code> are plain texts. But actually they should be part of HTML elements.
  7. Did you confirm your output is different from CommonMark online demo or other official renderer correspond with an extension?: Node.Text is not a functionality the online demo provides.
package main

import (
    "fmt"

    "github.com/yuin/goldmark"
    "github.com/yuin/goldmark/text"
)

func main() {
    md := goldmark.New()

    input := []byte("<code>foo</code>")
    root := md.Parser().Parse(text.NewReader(input))

    fmt.Printf("%q\n", root.Text(input))
}

This is a regression from v1.7.4. With goldmark v1.7.4, the above code prints "foo" as expected.

yuin commented 2 hours ago

See https://github.com/yuin/goldmark/releases/tag/v1.7.8

rhysd commented 2 hours ago

So the meaning of the Node.Text has changed, am I correct?

yuin commented 2 hours ago

Yes. As I've wrote there's no 1 'correct' text representation of most nodes. All Node.Text methods are deprecated now. If you applies some linter, it will claim that Node.Text is deprecated. I recommend you to update your code to avoid Node.Text. All Node.Text can be replaced with other public functions or properties.

rhysd commented 2 hours ago

Thank you for the clarification. Yes, I understood that the method had been deprecated and I will stop using it as soon as possible. I just wanted a clarification with this comment :)