سؤال

I need the following features:

  1. hard-wrap text
  2. auto link (make urls into clickable links)
  3. @name should turn into links to user/show action (I should be able to write this helper method)
  4. prevent code injection

As far as I've learned, redcarpet doesn't seem to work properly, and I found redcloth to be the choice. But it seems a little outdated, and it doesn't provide filter_html or autolink options. I could install gems sanitize and autolink to use with redcloth but I believe there would be a better way.

Can anyone give me suggestions?

هل كانت مفيدة؟

المحلول

I'd recommend checking out the html-pipeline gem. It has filters for doing a lot of what you want and includes:

  • MentionFilter - replace @user mentions with links
  • AutolinkFilter - auto_linking urls in HTML
  • CamoFilter - replace http image urls with camo-fied https versions
  • EmailReplyFilter - util filter for working with emails
  • EmojiFilter - everyone loves emoji!
  • HttpsFilter - HTML Filter for replacing http github urls with https versions.
  • ImageMaxWidthFilter - link to full size image for large images
  • MarkdownFilter - convert markdown to html
  • PlainTextInputFilter - html escape text and wrap the result in a div
  • SanitizationFilter - whitelist sanitize user markup
  • SyntaxHighlightFilter - code syntax highlighter with linguist
  • TextileFilter - convert textile to html
  • TableOfContentsFilter - anchor headings with name attributes
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top