mirror of
https://github.com/System-End/hackatime.git
synced 2026-04-20 00:35:22 +00:00
remove .md extension from relative links (#664)
This commit is contained in:
parent
0bf4ff4e38
commit
402b29130b
1 changed files with 15 additions and 1 deletions
|
|
@ -116,8 +116,22 @@ class DocsController < ApplicationController
|
|||
title_line&.sub(/^# /, "")&.strip
|
||||
end
|
||||
|
||||
# removes .md extension from links
|
||||
class DocsRenderer < Redcarpet::Render::HTML
|
||||
def link(link, title, content)
|
||||
if link && !link.match?(/\A[a-z]+:/)
|
||||
link = link.sub(/\.md(?=[#?]|$)/, "")
|
||||
end
|
||||
|
||||
attributes = "href=\"#{link}\""
|
||||
attributes += " title=\"#{title}\"" if title
|
||||
|
||||
"<a #{attributes}>#{content}</a>"
|
||||
end
|
||||
end
|
||||
|
||||
def render_markdown(content)
|
||||
renderer = Redcarpet::Render::HTML.new(
|
||||
renderer = DocsRenderer.new(
|
||||
filter_html: true,
|
||||
no_links: false,
|
||||
no_images: false,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue