1

I have a Rails 4 app (which uses RedCarpet) and a helper method that looks like:

def markdown(text)
  options = {
    escape_html:     true,
    hard_wrap:       true, 
    link_attributes: { rel: 'nofollow', target: "_blank" },
    space_after_headers: true,
    fenced_code_blocks: true
  }

  extensions = {
    autolink:           true,
    superscript:        true,
    disable_indented_code_blocks: true
  }

  renderer = Redcarpet::Render::HTML.new(options)
  markdown = Redcarpet::Markdown.new(renderer, extensions)

  markdown.render(text).html_safe
end

My problem is that if someone puts in for example [Example here](www.example.com), then is parsed, and someone clicks on the link, it goes to www.mywebsite.com/www.example.com, instead of www.example.com.

How do I fix this?

the_
  • 1,183
  • 2
  • 30
  • 61
  • it doesn't really answer your question, but one thing user can do is input full url, as in `https://www.example.com` or `//example.com` – AndreiMotinga Aug 14 '16 at 01:50

1 Answers1

0

For me, running your method with "[Example here](www.example.com)" and RedCarpet 3.0 returns the following:

"<p><a href=\"www.example.com\" rel=\"nofollow\" target=\"_blank\">Example here</a></p>\n"

So, it appears it is something else in your application. If you're noticing the problem on the client side (ie from clicking on a link in your browser), my guess is it's in your views somewhere in the HTML. I'd search your app's file directory, particularly any HTML, for "www.mywebsite.com".

Jake Shorty
  • 717
  • 6
  • 17
  • Not going to lie. I was pulling my hair out trying to figure out why it wasn't working. And your answer was the best. It indeed was in the views. Not sure why anyone would downvote. Cheers. – Andy Mar 15 '17 at 01:25