From 402b29130bc52119a30953df619c4c6ccc582536 Mon Sep 17 00:00:00 2001 From: BananaJeans <18456310+BananaJeanss@users.noreply.github.com> Date: Mon, 1 Dec 2025 17:40:05 +0200 Subject: [PATCH] remove .md extension from relative links (#664) --- app/controllers/docs_controller.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app/controllers/docs_controller.rb b/app/controllers/docs_controller.rb index 40c0981..3c342fa 100644 --- a/app/controllers/docs_controller.rb +++ b/app/controllers/docs_controller.rb @@ -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 + + "#{content}" + end + end + def render_markdown(content) - renderer = Redcarpet::Render::HTML.new( + renderer = DocsRenderer.new( filter_html: true, no_links: false, no_images: false,