Module: CoPlan::MarkdownHelper
- Defined in:
- app/helpers/coplan/markdown_helper.rb
Constant Summary collapse
- ALLOWED_TAGS =
%w[ h1 h2 h3 h4 h5 h6 p div span ul ol li table thead tbody tfoot tr th td pre code a img strong em b i u s del blockquote hr br dd dt dl sup sub ].freeze
- ALLOWED_ATTRIBUTES =
%w[id class href src alt title].freeze
Instance Method Summary collapse
Instance Method Details
#render_line_view(content) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/helpers/coplan/markdown_helper.rb', line 24 def render_line_view(content) lines = content.to_s.split("\n", -1) line_divs = lines.each_with_index.map do |line, index| n = index + 1 escaped = ERB::Util.html_escape(line) inner = escaped.blank? ? " ".html_safe : escaped tag.div(inner, class: "line-view__line", id: "L#{n}", data: { line: n }) end tag.div(safe_join(line_divs), class: "line-view", data: { controller: "line-selection" }) end |
#render_markdown(content) ⇒ Object
18 19 20 21 22 |
# File 'app/helpers/coplan/markdown_helper.rb', line 18 def render_markdown(content) html = Commonmarker.to_html(content.to_s.encode("UTF-8"), plugins: { syntax_highlighter: nil }) sanitized = sanitize(html, tags: ALLOWED_TAGS, attributes: ALLOWED_ATTRIBUTES) tag.div(sanitized, class: "markdown-rendered") end |