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

mdast extension to parse and serialize GFM task list items
https://unifiedjs.com
MIT License
5 stars 2 forks source link

Missing checkbox in generated markdown #2

Closed RichardFevrier closed 4 years ago

RichardFevrier commented 4 years ago

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: "* [ ] "

wooorm commented 4 years ago

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

It is required to have some content in the paragraph: https://github.com/syntax-tree/mdast-util-gfm-task-list-item/blob/26584d70469a3528ead5510662830982e247bae2/to-markdown.js#L13

wooorm commented 4 years ago

bullet is not an mdast property btw.

RichardFevrier commented 4 years ago

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

RichardFevrier commented 4 years ago

Any thoughts about that @wooorm ?

wooorm commented 4 years ago

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

wooorm commented 4 years ago

Fixed: https://github.com/micromark/micromark-extension-gfm-task-list-item/releases/tag/0.3.2. Thanks again @RichardFevrier!

RichardFevrier commented 4 years ago

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)

wooorm commented 4 years ago

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?

RichardFevrier commented 4 years ago

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

wooorm commented 4 years ago

Thank you!!