dev_forum
SylorHuang 6 years ago
parent b29d4063a8
commit 93d18fac5d

@ -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'

@ -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)

@ -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

@ -57,7 +57,7 @@
</div>
</div>
<div class="mbt10">
<% @exercise_questions.each_with_index do |q,index| %>
<% @exercise_questions.each do |q| %>
<div class="bdc">
<div class="pbt10">
<div class="pbt5">
@ -68,27 +68,17 @@
<span class="text-gray mlr5">(<%= q&.question_score %>分)</span>
</div>
<div class="pbt5">
<% 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 %>
<span class="ques-title" id="ques_marked_<%= index %>"><%= q_name %></span>
<div class="mt8 text-gray">
<span id="ques_title_<%= index %>"><%= q_title %></span>
</div>
<script>
$(function () {
$("#ques_marked_<%= index %>").html(marked(<%= q_name %>))
$("#ques_title_<%= index %>").html(marked(<%= q_title %>))
})
</script>
<% else %>
<span class="ques-title" id="ques_title_<%= index %>"><%= q_title %></span>
<script>
$(function () {
$("#ques_title_<%= index %>").html(marked(<%= q_title %>))
})
</script>
<% end %>
</div>
<div class="pbt5">
@ -146,6 +136,5 @@
</div>
</div>
</body>
<%= ApplicationController.helpers.pdf_load_sources(*%w(react/public/js/jquery-1.8.3.min.js react/public/js/editormd/marked.min.js))%>
</html>
Loading…
Cancel
Save