Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stas/redcapret-socialable
Mention and Hashtag features for redcarpet
https://github.com/stas/redcapret-socialable
Last synced: 13 days ago
JSON representation
Mention and Hashtag features for redcarpet
- Host: GitHub
- URL: https://github.com/stas/redcapret-socialable
- Owner: stas
- License: mit
- Created: 2014-01-09T21:56:08.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2014-01-10T13:59:11.000Z (about 11 years ago)
- Last Synced: 2025-01-09T21:32:42.157Z (16 days ago)
- Language: Ruby
- Homepage: http://gistflow.com/posts/965
- Size: 159 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# @mention and #hashtag for Markdown
This gem provides a HTML renderer for [redcarpet](https://github.com/vmg/redcarpet).
## How to use
```ruby
gem "redcarpet-socialable", github: "releu/redcapret-socialable"
``````ruby
# override the following methods for your case
class MyAwesomeRenderer < Redcarpet::Socialable
def highlight_tag?(name)
Tag.where(name: name.downcase).first_or_create!
enddef highlight_username?(name)
User.where(username: name).exists?
enddef tag_template(name)
%(##{name})
enddef mention_template(name)
%(@#{name})
end
end# use redcarpet's options https://github.com/vmg/redcarpet
renderer = MyAwesomeRenderer.new
# space_after_headers must be true for hashtag feature
markdown = Redcarpet::Markdown.new(renderer, space_after_headers: true)markdown.render "#foo\n@bar" # =>
```### Mixins
There are two modules you can use as mixins to extend an existing renderer
with features from `Redcarpet::Socialable`: `Mentions` and `Hashtags`.These mixins will hook into renderer `#postprocessing` method in order
to process mentions or hashtags.Here's a basic example for mentions:
```ruby
class MentionsRenderer < Redcarpet::Render::HTML
include Redcarpet::Socialable::Mentions
end
````Redcarpet::Socialable::Mentions` mentions you can overwrite include:
* `#mention_template`
* `#mention?` - works as `#highlight_username?` from `Redcarpet::Socialable`
* `#mention_regexp` - Use it to change the regexp to match a mentionAnd a basic example for hashtags:
```ruby
class HashtagsRenderer < Redcarpet::Render::HTML
include Redcarpet::Socialable::Hashtags
end
````Redcarpet::Socialable::Hashtags` mentions you can overwrite include:
* `#hashtag_template` - works as `#tag_template` from `Redcarpet::Socialable`
* `#hashtag?` - works as `#highlight_tag?` from `Redcarpet::Socialable`
* `#hashtag_regexp` - Use it to change the regexp to match a hashtag