syntax-tree/mdast-util-gfm-task-list-item

Missing checkbox in generated markdown

RichardFevrier opened this issue · 10 comments

Consider the following tree:

{
   "type":"root",
   "children":[
      {
         "type":"list",
         "start":null,
         "spread":false,
         "ordered":false,
         "children":[
            {
               "type":"listItem",
               "spread":false,
               "bullet":"-",
               "checked":false,
               "children":[
                  {
                     "type":"paragraph",
                     "children":[
                        {
                           "type":"text",
                           "value":""
                        }
                     ]
                  }
               ]
            }
         ]
      }
   ]
}

And the following code/configuration:

"mdast-util-to-markdown": "0.5.3", (latest)
"mdast-util-gfm-strikethrough": "0.2.2", (latest)
"mdast-util-gfm-task-list-item": "0.1.5", (latest)
var mdast2md = require('mdast-util-to-markdown');
var strikethrough = require('mdast-util-gfm-strikethrough');
var tasklistitem = require('mdast-util-gfm-task-list-item');

const markdown = mdast2md(mdtree, {
  extensions: [strikethrough.toMarkdown, tasklistitem.toMarkdown]
});

Here is the result of markdown:

"*\n"

Problem:
The result should be something like this: "* [ ] "

That doesn’t work on GitHub, and this project is guarding you from it:

  • [ ]

It is required to have some content in the paragraph:

if (typeof node.checked === 'boolean' && head && head.type === 'paragraph') {

bullet is not an mdast property btw.

I'm sorry but there is still a problem somewhere.

Because if you do it the other way :
From this markdown "* [ ] " (the expected output before)

To a mdtree, using this (with the latest plugins):

var md2mdast = require('mdast-util-from-markdown');
var strikethroughSyntax = require('micromark-extension-gfm-strikethrough')
var strikethrough = require('mdast-util-gfm-strikethrough');
var tasklistitemSyntax = require('micromark-extension-gfm-task-list-item');
var tasklistitem = require('mdast-util-gfm-task-list-item');

const mdtree = md2mdast("* [ ] ", {
  extensions: [strikethroughSyntax(), tasklistitemSyntax],
  mdastExtensions: [strikethrough.fromMarkdown, tasklistitem.fromMarkdown]
});

You will retrive my tree at the beginning (minus the property 'bullet' like you pointed out and minus the 'Text' nested in the 'Paragraph').

A -> B
C <- B

Any thoughts about that @wooorm ?

I have confirmed this is a bug in micromark-extension-gfm-task-list-item, I’ll fix it there.

Sorry @wooorm to continue this thread but I want to be sure the actual behavior is right.
If we take "- [ ] " in Input, the last space is trimmed in the tree and if we convert it back to markdown we find this "- [ ]\n"
Is it the expected result?
(As always all modules are up to date)

Trimming initial and final spaces on lines is part of how markdown works, too.

Adding a final line ending is to ensure files are valid: it’s not really part of markdown but unix wants it that way

So yes, the input/output you show is expected. Does that answer your question, or is there something I missed?

That's perfectly clear!
Thank you to take time to answer 🙏
Your lib is amazing by the way ❤️

Thank you!!