commonmark / commonmark/cmark

Dash-separated long list items rendered as sublist

Open
#347 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
2k
Forks
691
Avg merge
1d 16h
Merged PRs (30d)
1

Description

Here is a Markdown file with a list of very long items:

❯ cat ./dash-separated-link-list.md
- [Link 1](#link-1) - Description of line 1.
- [Link 2](#link-2) - A very long description for the second link in the list. That description is more than 80 characters wide.
- [This is a very long title, pointing to an awesome article on incredible stuff we're not used to see everyday](#link-3) - Line #3's description.
- [Link number three](#this-is-a-very-long-url-that-is-pointing-to-a-really-really-great-website) - Fourth description.

It cleanly renders into a list of 4 items:

❯ /System/Volumes/Data/usr/local/opt/cmark/bin/cmark ./dash-separated-link-list.md
<ul>
<li><a href="#link-1">Link 1</a> - Description of line 1.</li>
<li><a href="#link-2">Link 2</a> - A very long description for the second link in the list. That description is more than 80 characters wide.</li>
<li><a href="#link-3">This is a very long title, pointing to an awesome article on incredible stuff we're not used to see everyday</a> - Line #3's description.</li>
<li><a href="#this-is-a-very-long-url-that-is-pointing-to-a-really-really-great-website">Link number three</a> - Fourth description.</li>
</ul>

Now if I try to tidy up the original markdown into a 80-chars wide format, I get the following:

❯ /System/Volumes/Data/usr/local/opt/cmark/bin/cmark --to commonmark --width 80 ./dash-separated-link-list.md
  - [Link 1](#link-1) - Description of line 1.
  - [Link 2](#link-2) - A very long description for the second link in the list.
    That description is more than 80 characters wide.
  - [This is a very long title, pointing to an awesome article on incredible
    stuff we're not used to see everyday](#link-3) - Line \#3's description.
  - [Link number
    three](#this-is-a-very-long-url-that-is-pointing-to-a-really-really-great-website)
    - Fourth description.

Which renders into a list with an additional sub-list item:

❯ /System/Volumes/Data/usr/local/opt/cmark/bin/cmark --to commonmark --width 80 ./dash-separated-link-list.md | /System/Volumes/Data/usr/local/opt/cmark/bin/cmark
<ul>
<li><a href="#link-1">Link 1</a> - Description of line 1.</li>
<li><a href="#link-2">Link 2</a> - A very long description for the second link in the list.
That description is more than 80 characters wide.</li>
<li><a href="#link-3">This is a very long title, pointing to an awesome article on incredible
stuff we're not used to see everyday</a> - Line #3's description.</li>
<li><a href="#this-is-a-very-long-url-that-is-pointing-to-a-really-really-great-website">Link number
three</a>
<ul>
<li>Fourth description.</li>
</ul>
</li>
</ul>

This is due to an edge-case that is splitting an item content just before the dash located right after the link.


This bug has been reported first to the pandoc project at: https://github.com/jgm/pandoc/issues/6497 . An interesting thing here is that the previous implementation was supporting this edge case while the new one based on cmark does not.


For reference, here the version of cmark I'm using, installed with brew on macOS Catalina:

❯ brew install cmark
(...)
==> Downloading https://homebrew.bintray.com/bottles/cmark-0.29.0_1.catalina.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/3a/3af95418f96f4b0cec4bd76abaab312f3caf4cea591f38d3b725f15068d06491?__gda__=exp=1593691219~hmac=7f6c15036b995f36438e934f5bd44ec8
######################################################################## 100.0%
==> Pouring cmark-0.29.0_1.catalina.bottle.tar.gz
🍺  /usr/local/Cellar/cmark/0.29.0_1: 17 files, 724.9KB
❯ /System/Volumes/Data/usr/local/opt/cmark/bin/cmark --version
cmark 0.29.0 - CommonMark converter
(C) 2014-2016 John MacFarlane

This bug can also be reproduced with the cmark-gfm formulae provided by brew:

❯ /System/Volumes/Data/usr/local/opt/cmark-gfm/bin/cmark-gfm --version
cmark-gfm 0.29.0.gfm.0 - CommonMark with GitHub Flavored Markdown converter
(C) 2014-2016 John MacFarlane
❯ /System/Volumes/Data/usr/local/opt/cmark-gfm/bin/cmark-gfm --to commonmark --width 80 ./dash-separated-link-list.md | /System/Volumes/Data/usr/local/opt/cmark-gfm/bin/cmark-gfm
<ul>
<li><a href="#link-1">Link 1</a> - Description of line 1.</li>
<li><a href="#link-2">Link 2</a> - A very long description for the second link in the list.
That description is more than 80 characters wide.</li>
<li><a href="#link-3">This is a very long title, pointing to an awesome article on incredible
stuff we're not used to see everyday</a> - Line #3's description.</li>
<li><a href="#this-is-a-very-long-url-that-is-pointing-to-a-really-really-great-website">Link number
three</a>
<ul>
<li>Fourth description.</li>
</ul>
</li>
</ul>

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with cmark 0.29.0 using --to commonmark --width 80, then pipe the output back through cmark as shown in the report. Trace how the dash after a link is handled when wrapping list items, and verify that the round trip keeps the description in the same list item rather than creating a sublist.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, markdown
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.