Homepage    |    GitHub    |    API    |    FAQ

Checkbox Rendering Questions (#4070)

I have a couple questions regarding this PR I have been working on.

Essentially, the issue was that having more than one space between the hyphen and the bracket of a checkbox allowed it to be rendered, but clicking on the rendered checkbox button did not properly change the markdown text.

-    [ ]
 *^^^ space we are interested in. (if only 1 space (*), then it works fine)

In order to fix the rendering of checkboxes I patched the renderer rule to check the markdown source code stored in the markdown-it state object. This was not ideal because I had to store the source as a variable, even for files not containing checkboxes. Also, I believe that the rendering step in markdown-it should only depend on tokens generated by parsing.

Unless I am mistaken, I don't think the information (number of spaces between the opening dash and the first opening bracket) we are looking for is contained in the token list. Here is an example of a note containing a problematic checkbox as well as the list of tokens generated for it.

My question is: should we allow multiple spaces between the hyphen and the bracket? If so, we would need to fix the checkbox button in the viewer. If the hyphen and bracket are considered separate entities, this would adhere well to the CommonMark spec which allows multiple spaces between the hyphen in a list and the first characters in the paragraph.

However, if the hyphen and bracket are considered a single entity, which probably makes more sense, allowing multiple spaces would not be appropriate. Laurent mentioned here that the preferred behavior is one space, but I just wanted to double check.

If we are allowing just one space, I feel like we may need to write or use an existing checkbox parsing plugin for markdown-it rather than the current renderer rule, or write a markdown-it plugin that appends this information to the list tokens, then check the tokens in the renderer.

Any other ideas? Am I just missing something in the tokens?

Thanks for reading.