Skip to content

roundtrippping content causes definition to disappear #47

Closed
@ChristianMurphy

Description

@ChristianMurphy

Initial checklist

Affected packages and versions

1.2.4

Link to runnable example

https://stackblitz.com/edit/node-st1b3g?file=index.js

Steps to reproduce

Run

import { remark as remarFactory } from 'remark';
import { visit } from 'unist-util-visit';

const remark = remarFactory();

// clean extra attributes that make it hard to see issue
function scrubber(tree) {
  visit(tree, function (node) {
    node.value = undefined;
    node.position = undefined;
    node.spread = undefined;
    node.lang = undefined;
    node.identifier = undefined;
    node.label = undefined;
    node.title = undefined;
    node.url = undefined;
  });
}

const content = `[a]: `;

const originalAst = remark.parse(content);
const newContent = remark.stringify(originalAst);
const newAst = remark.parse(newContent);

scrubber(originalAst);
scrubber(newAst);

console.log(JSON.stringify(originalAst, null, 4));
console.log(JSON.stringify(newAst, null, 4));

result is:

{
    "type": "root",
    "children": [
        {
            "type": "definition"
        }
    ]
}

then

{
    "type": "root",
    "children": [
        {
            "type": "paragraph",
            "children": [
                {
                    "type": "text"
                }
            ]
        }
    ]
}

and the output text is

[a]: 

Expected behavior

definition content is preserved

Actual behavior

definition content disapepars

Runtime

Node v16

Package manager

npm v7

OS

Linux

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