0

I have following markdown file with frontmatter. The markdown content sometimes contains inline URLs which are not formatted with markdown's URL syntax. Is there any way to deal with those non-markdown URLs inside the markdown file, and somehow parse them into HTML urls with some regex plugin, etc? Need little tip here from experienced front end guys

Example .md file:
---
category: "general"
medium: "forum"
date: "July 25, 2010"
---

For future reference, here's my public key. **http://www.iamyourfather.org/papa.asc**

I then as usual process with with remark using the HTML plugin like this:

// Use gray-matter to parse the quote metadata section
const matterResult = matter(fileContents)

// Use remark to convert markdown into HTML string
const processedContent = await remark()
    .use(html)
    .process(matterResult.content)

const contentHtml = processedContent.toString()

I would like this "contentHtml" string to contain proper clickable HTML link in case the content of the markdown contains such plaintext http/www urls.

Is there a way to combine remark, remark-html, and ANOTHER plugin to parse this in single shot? Do i need multiple steps to achieve this?

1 Answers1

0

What you are searching, is the GFM auto-link functionality.

With remark, you use it like this:

const file = await remark()
  .use(remarkGfm)
  .process(input)

Remark-gfm is a package that contains the two needed pieces:

gerardnico
  • 855
  • 11
  • 10