Module: Postnhost::ArticleHelper

Defined in:
app/helpers/postnhost/article_helper.rb

Instance Method Summary collapse

Instance Method Details

#article_excerpt(article) ⇒ Object



20
21
22
# File 'app/helpers/postnhost/article_helper.rb', line 20

def article_excerpt(article)
  article.custom_excerpt.presence || article.auto_excerpt.presence
end

#render_article_content(content) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/helpers/postnhost/article_helper.rb', line 5

def render_article_content(content)
  # Add <br> to empty <p> tags to match editor behavior
  content = content&.gsub("<p></p>", "<p><br></p>")
  content = content&.gsub(%r{<p>\s*</p>}, "<p><br></p>")

  sanitized_content = sanitize(
    content,
    tags: %w[p h1 h2 h3 h4 h5 h6 strong em u s sup sub mark code pre span blockquote ul ol li a img table colgroup col thead tbody tr th td br
             hr div iframe],
    attributes: %w[href src alt class style target rel width height colspan rowspan frameborder allow allowfullscreen title]
  )

  highlight_code_blocks(sanitized_content)
end