Add data-turbo-frame attribute to links in comments

This commit is contained in:
Jason Zimdars
2025-01-30 15:20:40 -06:00
parent b320b72bc6
commit 441c68b8d7
2 changed files with 20 additions and 0 deletions
+19
View File
@@ -36,9 +36,28 @@ class MarkdownRenderer < Redcarpet::Render::HTML
block_code(code, language) # call Rouge Redcarpet plugin
end
def link(url, title, content)
attributes = { href: url }
attributes[:title] = title if title
attributes["data-turbo-frame"] = "_top"
"<a #{html_attributes(attributes)}>#{content}</a>"
end
def autolink(url, link_type)
attributes = { href: url }
attributes["data-turbo-frame"] = "_top"
"<a #{html_attributes(attributes)}>#{url}</a>"
end
private
attr_reader :id_counts
def html_attributes(attributes)
attributes.map { |key, value| %Q(#{key}="#{value}") }.join(" ")
end
def unique_id(text)
text.parameterize.then do |base_id|
id_counts[base_id] += 1