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

New Lines not adding <Softbreak /> node #393

Closed khanakia closed 1 year ago

khanakia commented 1 year 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.5.4
  2. What version of Go are you using? : 1.20.1
  3. What operating system and processor architecture are you using? : Mac
  4. What did you do? : ran the below code
  5. What did you expect to see? : it should add softbreak
  6. What did you see instead? : not adding softbreak
  7. Did you confirm your output is different from CommonMark online demo or other official renderer correspond with an extension?: yes
package main

import (
    "fmt"
    "github.com/yuin/goldmark"
    "github.com/yuin/goldmark/ast"
    "github.com/yuin/goldmark/text"
)

var source = `
**2. Click "Rankings Distribution"
Click "Landscape"
Click "SEO Dashboard
COMPETITIVE RESEARCH
Domain Overview
Traffic Analytics
Organic Research
Keyword Gap
Backlink Gap
KEYWORD RESEARCH
Keyword Overview..."**
`
func main() {
    doc := goldmark.DefaultParser().Parse(text.NewReader([]byte(source)))
    ast.Walk(doc, func(n ast.Node, entering bool) (ast.WalkStatus, error) {
        s := ast.WalkStatus(ast.WalkContinue)
        var err error
        fmt.Println(n.Kind(), entering, string(n.Text([]byte(source))))
        return s, err
    })
}

Outputs

............
Text true 2. Click "Rankings Distribution"
Text false 2. Click "Rankings Distribution"
Text true Click "Landscape"
Text false Click "Landscape"
Text true Click "SEO Dashboard
Text false Click "SEO Dashboard
Text true COMPETITIVE RESEARCH
Text false COMPETITIVE RESEARCH
Text true Domain Overview
Text false Domain Overview
Text true Traffic Analytics
Text false Traffic Analytics
Text true Organic Research
Text false Organic Research
....

It should add the softbreak between lines print like this according to https://spec.commonmark.org/dingus/

<text>2. Click </text>
    <text>&quot;</text>
    <text>Rankings Distribution</text>
    <text>&quot;</text>
    <softbreak />
    <text>Click </text>
    <text>&quot;</text>
    <text>Landscape</text>
    <text>&quot;</text>
    <softbreak />
yuin commented 1 year ago

Spec is defined only for HTML outputs

khanakia commented 1 year ago

I do not understand you can see there is softbreak node the package does NOT provides.

Then how do i detect the line breaks ??