[英]Markdown and external links
我有一個Rails 4應用程序(使用RedCarpet)和一個類似於以下內容的輔助方法:
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
我的問題是,例如,如果有人在[Example here](www.example.com)
,然后有人對其進行了分析,然后單擊鏈接,則該鏈接將轉到www.mywebsite.com/www.example.com ,而不是www.example.com 。
我該如何解決?
對我來說,使用"[Example here](www.example.com)"
和RedCarpet 3.0運行方法將返回以下內容:
"<p><a href=\\"www.example.com\\" rel=\\"nofollow\\" target=\\"_blank\\">Example here</a></p>\\n"
因此,它似乎是應用程序中的其他內容。 如果您在客戶端注意到該問題(例如,通過單擊瀏覽器中的鏈接),那么我猜這是在您認為HTML的某處。 我會在您應用的文件目錄(尤其是任何HTML)中搜索“ www.mywebsite.com”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.