From b29d4063a87c1fcbc09c7c46bfcc8c2639b3cdcd Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 09:53:58 +0800 Subject: [PATCH 1/5] fix bug --- .../exercise_export/blank_exercise.html.erb | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index 74cea75f1..995d04995 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -57,7 +57,7 @@
- <% @exercise_questions.each do |q| %> + <% @exercise_questions.each_with_index do |q,index| %>
@@ -68,15 +68,27 @@ (<%= q&.question_score %>分)
- <% q_title = q.question_title&.html_safe %> + <% q_title = q.question_title&.include?("src=\"") ? q.question_title&.gsub("src=\"","src=\"#{@request_url}")&.html_safe : q.question_title&.html_safe %> <% if q.question_type == 5 %> - <% q_name = q.shixun_name&.html_safe %> - <%= q_name&.include?("src=\"") ? q_name&.gsub("src=\"","src=\"#{@request_url}") : q_name %> + <% q_name = q.shixun_name&.include?("src=\"") ? q.shixun_name&.gsub("src=\"","src=\"#{@request_url}")&.html_safe : q.shixun_name&.html_safe %> + <%= q_name %>
- <%= q_title&.include?("src=\"") ? q_title&.gsub("src=\"","src=\"#{@request_url}") : q_title %> + <%= q_title %>
+ <% else %> - <%= q_title&.include?("src=\"") ? q_title&.gsub("src=\"","src=\"#{@request_url}") : q_title %> + <%= q_title %> + <% end %>
@@ -134,4 +146,6 @@
+<%= ApplicationController.helpers.pdf_load_sources(*%w(react/public/js/jquery-1.8.3.min.js react/public/js/editormd/marked.min.js))%> + \ No newline at end of file From 93d18fac5dbba3bd15d925dcc958c42b681b06dd Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 10:12:26 +0800 Subject: [PATCH 2/5] fix bug --- Gemfile | 2 ++ Gemfile.lock | 2 ++ app/helpers/application_helper.rb | 12 +++++++++++ .../exercise_export/blank_exercise.html.erb | 21 +++++-------------- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/Gemfile b/Gemfile index 31af87f14..b8b174a6f 100644 --- a/Gemfile +++ b/Gemfile @@ -39,6 +39,8 @@ gem 'pdfkit' gem 'wkhtmltopdf-binary' #gem 'iconv' +# markdown 转html +gem 'redcarpet', '~> 3.4' gem 'rqrcode', '~> 0.10.1' gem 'rqrcode_png' diff --git a/Gemfile.lock b/Gemfile.lock index 83bd79628..86f524bc2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -193,6 +193,7 @@ GEM rb-inotify (0.9.10) ffi (>= 0.5.0, < 2) rchardet (1.8.0) + redcarpet (3.4.0) redis (4.1.0) redis-actionpack (5.0.2) actionpack (>= 4.0, < 6) @@ -328,6 +329,7 @@ DEPENDENCIES rails (~> 5.2.0) rails-i18n (~> 5.1) rchardet (~> 1.8) + redcarpet (~> 3.4) redis-rails roo-xls rqrcode (~> 0.10.1) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index d8ea8cd60..8d92362cc 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -334,6 +334,18 @@ module ApplicationHelper raw arr.join('') end + def to_markdown(text) + nil if text.blank? + html_render_options = { + fenced_code_blocks: true, + tables: true, + autolink: true + } + + markdown = Redcarpet::Markdown.new(html_render_options) + raw markdown.render(h(text)).html_safe + end + end diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index 995d04995..bdb86d9d9 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -57,7 +57,7 @@
- <% @exercise_questions.each_with_index do |q,index| %> + <% @exercise_questions.each do |q| %>
@@ -68,27 +68,17 @@ (<%= q&.question_score %>分)
- <% q_title = q.question_title&.include?("src=\"") ? q.question_title&.gsub("src=\"","src=\"#{@request_url}")&.html_safe : q.question_title&.html_safe %> + <% q_markdown = to_markdown(q.question_title) %> + <% q_title = q_markdown&.include?("src=\"") ? q_markdown&.gsub("src=\"","src=\"#{@request_url}")&.html_safe : q_markdown %> <% if q.question_type == 5 %> - <% q_name = q.shixun_name&.include?("src=\"") ? q.shixun_name&.gsub("src=\"","src=\"#{@request_url}")&.html_safe : q.shixun_name&.html_safe %> + <% q_markdown_name = to_markdown(q.shixun_name) %> + <% q_name = q_markdown_name&.include?("src=\"") ? q_markdown_name&.gsub("src=\"","src=\"#{@request_url}")&.html_safe : q_markdown_name %> <%= q_name %>
<%= q_title %>
- <% else %> <%= q_title %> - <% end %>
@@ -146,6 +136,5 @@
-<%= ApplicationController.helpers.pdf_load_sources(*%w(react/public/js/jquery-1.8.3.min.js react/public/js/editormd/marked.min.js))%> \ No newline at end of file From 4f21bcb3bb479f43b08ba755dbcd3e5e947a2255 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 10:17:09 +0800 Subject: [PATCH 3/5] fix bug --- app/helpers/application_helper.rb | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8d92362cc..34848fd51 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -335,15 +335,19 @@ module ApplicationHelper end def to_markdown(text) - nil if text.blank? - html_render_options = { - fenced_code_blocks: true, - tables: true, - autolink: true + return nil if text.blank? + options = { + :autolink => true, + :no_intra_emphasis => true, + :fenced_code_blocks => true, + :lax_html_blocks => true, + :strikethrough => true, + :superscript => true, + :tables => true } - markdown = Redcarpet::Markdown.new(html_render_options) - raw markdown.render(h(text)).html_safe + markdown = Redcarpet::Markdown.new(options) + markdown.render(h(text)).html_safe end end From 5bfd514211a3ab67621230684ef04c3990373bb4 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 10:22:03 +0800 Subject: [PATCH 4/5] fix bug --- app/helpers/application_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 34848fd51..acb1089ec 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -346,7 +346,7 @@ module ApplicationHelper :tables => true } - markdown = Redcarpet::Markdown.new(options) + markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,options) markdown.render(h(text)).html_safe end From a6ea8d139a1c9861701d28bfbfa498f76e46d3f9 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 10:23:02 +0800 Subject: [PATCH 5/5] fix bug --- app/helpers/application_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index acb1089ec..055731168 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -347,7 +347,7 @@ module ApplicationHelper } markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,options) - markdown.render(h(text)).html_safe + markdown.render(text).html_safe end end