From ffb794a7255b8cbb89d2a4f5490feb59911b8014 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Mon, 27 Jan 2025 22:01:42 +0100 Subject: Replace underscores with the proper HTML tags MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This was already handled correctly in the case of TeX and CSV, but the HTML rendering was still to be handled. Signed-off-by: Miquel Sabaté Solà --- app/helpers/title_helper.rb | 14 ++++++++++++++ app/views/comments/_comment.html.erb | 2 +- app/views/things/_thing.html.erb | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 app/helpers/title_helper.rb (limited to 'app') diff --git a/app/helpers/title_helper.rb b/app/helpers/title_helper.rb new file mode 100644 index 0000000..4de2779 --- /dev/null +++ b/app/helpers/title_helper.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +# Helper functions for dealing with titles of Things. +module TitleHelper + # Returns the given string with underscores to . + def title_to_html(title:) + replace_underscores_with(string: title, open_char: '', close_char: '').html_safe # rubocop:disable Rails/OutputSafety + end + + # Replace underscores from a string with the given open/close characters. + def replace_underscores_with(string:, open_char:, close_char:) + string.gsub(/_([^_]+)_/, "#{open_char}\\1#{close_char}") + end +end diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index 8c0975e..5ee9ec3 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -4,7 +4,7 @@ <% if defined?(idx) %> <%= I18n.t('comments.title') %> #<%= idx + 1 %> <% else %> - <%= I18n.t('comments.title') %> <%= I18n.t('general.in') %> <%= link_to comment.thing.title, thing_path(comment.thing) %> + <%= I18n.t('comments.title') %> <%= I18n.t('general.in') %> <%= link_to title_to_html(title: comment.thing.title), thing_path(comment.thing) %> <% end %> diff --git a/app/views/things/_thing.html.erb b/app/views/things/_thing.html.erb index 5a31ccc..7c5ea93 100644 --- a/app/views/things/_thing.html.erb +++ b/app/views/things/_thing.html.erb @@ -2,6 +2,6 @@
">
-
<%= link_to thing.title, edit_thing_path(thing) %>
+
<%= link_to title_to_html(title: thing.title), edit_thing_path(thing) %>
<%= thing.rate %>
-- cgit v1.2.3