markdown-link-extractor icon indicating copy to clipboard operation
markdown-link-extractor copied to clipboard

Marked.js doesn't parse links in front matter headers correctly

Open NicolasMassart opened this issue 5 years ago • 3 comments

Description of the issue

As indicated in tcort/markdown-link-check#128 the parsing of links in front matter YAML is buggy and returns all the characters even after the end of the link, so it includes quotes (as quotes are ok in YAML to delimitate string values). This seems to be a choice on the Marked.js side not to support this: markedjs/marked#485

Solving leads

We first need to check if latest Marked.js behaves in a better way.

Then there's two options:

  1. exclude the front matter header parsing from Marked.js parsing and parse it separately for links
  2. switch to a parser that handles front matter and would provide the correct result

1st option is clearly the easiest in my opinion as we don't know the effect of switching to a new parser on existing user projects.

Expectations

Markdown-link-extractor is expected to extract for all the links in markdown files including those in a front matter header.

Linked issue

#7 also asks for links to be extracted from html code included in markdown. This is the same kind of request. Maybe both could be handled at the same time?

NicolasMassart avatar Nov 12 '20 13:11 NicolasMassart

And looking more at Marked.js, there's markedjs/marked#1716 which seems to be exactly what we need here to be fixed.

NicolasMassart avatar Nov 12 '20 14:11 NicolasMassart

I'm experiencing the same issue.

I also stumbled across the front-matter library that has methods to extract the front-matter and the body (i.e., Markdown less the front-matter): https://www.npmjs.com/package/front-matter#fmstring--allowunsafe-false-

Would it be possible to insert a call to use the body to grab just the Markdown and skip the front-matter, possibly here: https://github.com/tcort/markdown-link-check/blob/master/markdown-link-check#L166

wesley-dean-flexion avatar Feb 08 '22 15:02 wesley-dean-flexion