Skip to content

stringify() appears to mishandle reference links with inline code #850

@Trott

Description

@Trott

Initial checklist

Affected packages and versions

[email protected]

Link to runnable example

No response

Steps to reproduce

import {unified} from 'unified'
import remarkParse from 'remark-parse'
import remarkStringify from 'remark-stringify'

const u = unified()

const input = '[`foo`][]\n\n[`foo`]: http://example.com/'

const ast = u()
  .use(remarkParse)
  .parse(input)

const output = u()
  .use(remarkStringify)
  .stringify(ast)

if (input !== output) {
  console.log(`INPUT: ${input}`)
  console.log(`OUTPUT: ${output}`)
  console.log(`AST: ${JSON.stringify(ast, null, 1)}`)
}

Expected behavior

I would expect the link on the first line of the input/output to either be left as it is in the input, or else converted to [`foo`][`foo`].

Actual behavior

The output breaks the reference link on the first line by changing it from [`foo`][] to [`foo`][foo].

Runtime

Node v16

Package manager

npm v7

OS

macOS

Build and bundle tools

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions