Git Product home page Git Product logo

bb-ruby's Introduction

BBRuby

Description:

BBRuby is a BBCode implementation for Ruby. It will convert strings with BBCode markup to their HTML equivalent.

Installation:

gem install bb-ruby

Usage:

require 'bb-ruby'

BBRuby has been included directly into the String class for use on any string object:

text = "[b]Here is some bold text[/b] followed by some [u]underlined text[/u]"
output = text.bbcode_to_html
text.bbcode_to_html!

BBRuby will auto-escape HTML tags. To prevent this just pass false as the second param:

output = text.bbcode_to_html({}, false)

Only allow certain tags:

output = text.bbcode_to_html({}, true, :enable, :image, :bold, :quote)

Disable certain tags:

output = text.bbcode_to_html({}, true, :disable, :image, :bold, :quote)

Alternative Direct usage:

output = BBRuby.to_html(bbcode_markup)

Define your own translation, in order to be more flexible:

my_blockquote = {
  'Quote' => [
    /\[quote(:.*)?=(.*?)\](.*?)\[\/quote\1?\]/mi,
    '<div class="quote"><p><cite>\2</cite></p><blockquote>\3</blockquote></div>',
    'Quote with citation',
    '[quote=mike]please quote me[/quote]',
    :quote
  ],
}

text.bbcode_to_html(my_blockquote)

Define Proc as replacement:

module BBRuby
  @@tags = @@tags.merge({
      'File' => [
        /\[file(:.*)?=(.*?)\](.*?)\[\/file\1?\]/mi,
        lambda{ |e| "<div class="file"><p><cite>#{e[3]}</cite></p><blockquote>#{file_read_method(e[2])}</blockquote></div>"},
        'File content with citation',
        '[file=script.rb]Script Caption[/file]',
        :file
      ],
    })
end

You can also use the simple_format method of ActionPack by using the *_with_formatting methods:

output = text.bbcode_to_html_with_formatting
output = text.bbcode_to_html_with_formatting!

TAGS PROCESSED:

The following is the list of BBCode tags processed by BBRuby and their associated symbol for enabling/disabling them

[b]               :bold
[i]               :italics
[u]               :underline
[s]               :strikeout
[del]             :delete
[ins]             :insert
[code]            :code
[size]            :size
[color]           :color
[ol]              :orderedlist
[ul]              :unorderedlist
[li]              :listitem
[*]               :listitem
[list]            :listitem
[list=1]          :listitem
[list=a]          :listitem
[dl]              :definelist
[dt]              :defineterm
[dd]              :definition
[quote]           :quote
[quote=source]    :quote
[url=link]        :link
[url]             :link
[img size=]       :image
[img align=]      :image
[img=]            :image
[img]             :image
[youtube]         :video
[gvideo]          :video
[vimeo]           :video
[email]           :email
[align]           :align
[left]            :left
[center]          :center
[right]           :right
[br]              :br

bb-ruby's People

Contributors

cpjolicoeur avatar digaev avatar kulgar avatar leonid-shevtsov avatar makkrnic avatar marcandre avatar nozpheratu avatar samccone avatar thomasba avatar zeiv avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.