From 67ee589b5b6f886a047905a470f270694eb2ee0b Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Thu, 30 Dec 2021 17:59:44 +0100 Subject: [PATCH] Add question markup renderer --- app/services/question_markdown.rb | 10 ++++++++++ app/views/answerbox/_header.haml | 2 +- app/views/inbox/_entry.haml | 2 +- app/views/question/_question.haml | 2 +- 4 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 app/services/question_markdown.rb diff --git a/app/services/question_markdown.rb b/app/services/question_markdown.rb new file mode 100644 index 00000000..51d144a9 --- /dev/null +++ b/app/services/question_markdown.rb @@ -0,0 +1,10 @@ +require 'uri' + +class QuestionMarkdown < Redcarpet::Render::Base + include Rails.application.routes.url_helpers + include SharedMarkers + + def paragraph(text) + "

#{text}

" + end +end \ No newline at end of file diff --git a/app/views/answerbox/_header.haml b/app/views/answerbox/_header.haml index 0e31058f..33f975dc 100644 --- a/app/views/answerbox/_header.haml +++ b/app/views/answerbox/_header.haml @@ -29,4 +29,4 @@ %a{ href: show_user_question_path(a.question.user.screen_name, a.question.id) } = pluralize(a.question.answer_count, t('views.general.answer')) .answerbox__question-text - = a.question.content + = question_markdown a.question.content diff --git a/app/views/inbox/_entry.haml b/app/views/inbox/_entry.haml index ae46e93a..d58d5a9d 100644 --- a/app/views/inbox/_entry.haml +++ b/app/views/inbox/_entry.haml @@ -11,7 +11,7 @@ ยท %a{ href: show_user_question_path(i.question.user.screen_name, i.question.id) } = pluralize(i.question.answer_count, t('views.inbox.entry.response')) - %p.answerbox__question-text= i.question.content + %p.answerbox__question-text= question_markdown i.question.content - if i.question.user_id != current_user.id || current_user.has_role?(:administrator) .pull-right .btn-group diff --git a/app/views/question/_question.haml b/app/views/question/_question.haml index c7844a16..7fd7aeed 100644 --- a/app/views/question/_question.haml +++ b/app/views/question/_question.haml @@ -30,4 +30,4 @@ = user_screen_name question.user, anonymous: question.author_is_anonymous, url: false - else = raw t('views.answerbox.asked', user: user_screen_name(question.user, anonymous: question.author_is_anonymous), time: time_tooltip(question)) - %p.answerbox__question-text= question.content + %p.answerbox__question-text= question_markdown question.content