Module: SirTrevorRails::Helpers::ViewHelper
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/sir_trevor_rails/helpers/view_helper.rb
Instance Method Summary collapse
- #sir_trevor_format(text, format: :markdown) ⇒ Object
- #sir_trevor_html(text) ⇒ Object
- #sir_trevor_markdown(text) ⇒ Object
- #without_p_wrap(html) ⇒ Object
Instance Method Details
#sir_trevor_format(text, format: :markdown) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/sir_trevor_rails/helpers/view_helper.rb', line 9 def sir_trevor_format(text, format: :markdown) if format.to_s.to_sym == :html sir_trevor_html(text) else sir_trevor_markdown(text) end end |
#sir_trevor_html(text) ⇒ Object
17 18 19 |
# File 'lib/sir_trevor_rails/helpers/view_helper.rb', line 17 def sir_trevor_html(text) sanitize(text, tags: %w(b i a br p)) end |
#sir_trevor_markdown(text) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/sir_trevor_rails/helpers/view_helper.rb', line 21 def sir_trevor_markdown(text) rndr = CustomMarkdownFormatter.new(hard_wrap: true, filter_html: true, autolink: true, no_intraemphasis: true, fenced_code: true) markdown = Redcarpet::Markdown.new(rndr) markdown.render(text).html_safe end |
#without_p_wrap(html) ⇒ Object
30 31 32 |
# File 'lib/sir_trevor_rails/helpers/view_helper.rb', line 30 def without_p_wrap(html) Regexp.new('^<p>(.*)<\/p>$').match(html)[1].html_safe rescue html end |