Redcarpet replace urls on dedicated line with custom html

I'm using Redcarpet to parse markdown to HTML. Now I like internal urls (not links) to be replaced by custom cards, but only if the URL is on a dedicated line and not surrounded by any other content on the same line:

## This should be replaced by a card:

## But these should not:

- Link to [article](

Nor should this:

I have the autolink extension enabled, and my first thought was to extend this method to render the cards. This works as far as replacing all internal URLs, but afaik there is no way to detects if the URL is on a dedicated line.

class MarkdownRenderer < Redcarpet::Render::HTML
  def autolink(link, link_type)
    if internal_url?(link)
      "<a target=\"_blank\" href=\"#{link}\">#{link}</a>"

Does anyone know a way to solve this and also keep the autolink feature?

Thanks in advance!

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum