Parent

Class Index [+]

Quicksearch

BlueCloth

Bluecloth is a Ruby implementation of Markdown, a text-to-HTML conversion tool.

Authors

Contributors

This product includes software developed by David Loren Parsons <www.pell.portland.or.us/~orc>.

Version

 $Id$

License

Copyright © 2004-2010, Michael Granger All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Constants

VERSION

Release Version

DEFAULT_OPTIONS

The defaults for all supported options.

INSPECT_TEXT_LENGTH

The number of characters of the original markdown source to include in the output of #inspect

MKD_NOLINKS

Do not process `[]’ and remove A tags from the output.

MKD_NOIMAGE

Do not process `![]’ and remove IMG tags from the output.

MKD_NOPANTS

Do not do Smartypants-style mangling of quotes, dashes, or ellipses.

MKD_NOHTML

Escape all opening angle brackets in the input text instead of allowing block-level HTML

MKD_STRICT

disable SUPERSCRIPT, RELAXED_EMPHASIS

MKD_TAGTEXT

process text inside an html tag; no , no , no html or [] expansion

MKD_NO_EXT

don’t allow pseudo-protocols

MKD_TOC

do table-of-contents processing

MKD_1_COMPAT

MarkdownTest 1.0 Compatibility Mode

MKD_EMBED

MKD_NOLINKS|MKD_NOIMAGE|MKD_TAGTEXT

MKD_AUTOLINK

Create links for inline URIs

MKD_SAFELINK

Be paranoid about link protocols

MKD_NOHEADER

don’t process header blocks

Attributes

text[R]

The original Markdown text the object was constructed with

 
options[R]

The options hash that describes the options in effect when the object was created

 

Public Class Methods

discount_version → string click to toggle source

Return the version string of the Discount library BlueCloth was built on.

static VALUE
bluecloth_s_discount_version( VALUE klass ) 
flags_from_opthash( opthash={} ) click to toggle source

Convert the specified opthash into a flags bitmask. If it’s already a Fixnum (e.g., if someone passed in an ORed flags argument instead of an opthash), just return it as-is.

    # File lib/bluecloth.rb, line 60
60:     def self::flags_from_opthash( opthash={} )
61:         return opthash if opthash.is_a?( Integer )
62: 
63:         # Support BlueCloth1-style options
64:         if opthash == :filter_html || opthash == [:filter_html]
65:             opthash = { :escape_html => true }
66:         elsif opthash == :filter_styles
67:             opthash = {}
68:         elsif !opthash.is_a?( Hash )
69:             raise ArgumentError, "option %p not supported" % [ opthash ]
70:         end
71: 
72:         flags = 0
73: 
74:         if   opthash[:remove_links]    then flags |= MKD_NOLINKS;  end
75:         if   opthash[:remove_images]   then flags |= MKD_NOIMAGE;  end
76:         if ! opthash[:smartypants]     then flags |= MKD_NOPANTS;  end
77:         if ! opthash[:pseudoprotocols] then flags |= MKD_NO_EXT;   end
78:         if ! opthash[:pandoc_headers]  then flags |= MKD_NOHEADER; end
79:         if   opthash[:header_labels]   then flags |= MKD_TOC;      end
80:         if   opthash[:mdtest_1_compat] then flags |= MKD_1_COMPAT; end
81:         if   opthash[:escape_html]     then flags |= MKD_NOHTML;   end
82:         if   opthash[:strict_mode]     then flags |= MKD_STRICT;   end
83:         if   opthash[:tagtext_mode]    then flags |= MKD_TAGTEXT;  end
84:         if   opthash[:auto_links]      then flags |= MKD_AUTOLINK; end
85:         if   opthash[:safe_links]      then flags |= MKD_SAFELINK; end
86: 
87:         return flags
88:     end
new( string='', options=DEFAULT_OPTIONS ) → object click to toggle source
 

Create a new BlueCloth object that will process the given string. The options argument is a Hash that can be used to control the generated markup, and to enable/disable extensions. The supported options are:

:remove_links

Ignore links in Markdown, and escape A tags in the output. Defaults to false.

:remove_images

Ignore images in Markdown, and escape IMG tags in the output. Defaults to false.

:smartypants

Do Smartypants-style mangling of quotes, dashes, or ellipses. Defaults to true.

:pseudoprotocols

Support Discount’s pseudo-protocol links. Defaults to false.

:pandoc_headers

Support the extraction of Pandoc headers, which can be fetched as a Hash via the #header method. Defaults to false.

:header_labels

Generate ID attributes for all headers. Defaults to false.

:escape_html

Escape all HTML in the input string. Defaults to false.

:strict_mode

Disables Discount’s relaxed emphasis (ignores underscores in the middle of words) and superscript notation. Defaults to true.

static VALUE 
bluecloth_initialize( int argc, VALUE *argv, VALUE self ) 
opthash_from_flags( flags=0 ) click to toggle source

Returns a Hash that reflects the settings from the specified flags Integer.

     # File lib/bluecloth.rb, line 92
 92:     def self::opthash_from_flags( flags=0 )
 93:         flags = flags.to_i
 94: 
 95:         opthash = {}
 96:         if  ( flags & MKD_NOLINKS  ).nonzero? then opthash[:remove_links]    = true; end
 97:         if  ( flags & MKD_NOIMAGE  ).nonzero? then opthash[:remove_images]   = true; end
 98:         if !( flags & MKD_NOPANTS  ).nonzero? then opthash[:smartypants]     = true; end
 99:         if !( flags & MKD_NO_EXT   ).nonzero? then opthash[:pseudoprotocols] = true; end
100:         if !( flags & MKD_NOHEADER ).nonzero? then opthash[:pandoc_headers]  = true; end
101:         if  ( flags & MKD_TOC      ).nonzero? then opthash[:header_labels]   = true; end
102:         if  ( flags & MKD_1_COMPAT ).nonzero? then opthash[:mdtest_1_compat] = true; end
103:         if  ( flags & MKD_NOHTML   ).nonzero? then opthash[:escape_html]     = true; end
104:         if  ( flags & MKD_STRICT   ).nonzero? then opthash[:strict_mode]     = true; end
105:         if  ( flags & MKD_TAGTEXT  ).nonzero? then opthash[:tagtext_mode]    = true; end
106:         if  ( flags & MKD_AUTOLINK ).nonzero? then opthash[:auto_links]      = true; end
107:         if  ( flags & MKD_SAFELINK ).nonzero? then opthash[:safe_links]      = true; end
108: 
109:         return opthash
110:     end

Public Instance Methods

filter_html() click to toggle source

Backward-compatible method: return true if the object’s :escape_html option was set.

     # File lib/bluecloth.rb, line 132
132:     def filter_html
133:         return self.options[:escape_html]
134:     end
filter_html=( arg ) click to toggle source

Backward-compatible method: raises an appropriate error notifying the user that BlueCloth2 doesn’t support this option.

     # File lib/bluecloth.rb, line 139
139:     def filter_html=( arg )
140:         raise NotImplementedError,
141:             "Sorry, this version of BlueCloth no longer supports toggling of HTML filtering" +
142:             "via #filter_html=. You now must create the BlueCloth object with the :escape_html" +
143:             "option set to true instead."
144:     end
header → hash click to toggle source

Return the hash of Pandoc-style headers from the parsed document. If there were no headers, or the BlueCloth object was not constructed with the :pandoc_headers option enabled, an empty Hash is returned.

   markdown = "%title My Essay\n%author Me\n%date Today\n\nSome stuff..."
   bc = BlueCloth.new( markdown, :pandoc_headers => true )
   # => 
   bc.header
   # => 
static VALUE
bluecloth_header( VALUE self ) 
Also aliased as: pandoc_header
inspect() click to toggle source

Return a human-readable representation of the object suitable for debugging.

     # File lib/bluecloth.rb, line 118
118:     def inspect
119:         return "#<%s:0x%x text: %p; options: %p>" % [
120:             self.class.name,
121:             self.object_id / 2,
122:             self.text.length > INSPECT_TEXT_LENGTH ?
123:                 self.text[ 0, INSPECT_TEXT_LENGTH - 5] + '[...]' :
124:                 self.text,
125:             self.options,
126:         ]
127:     end
pandoc_header() click to toggle source
Alias for: header
to_html → string click to toggle source

Transform the document into HTML.

static VALUE
bluecloth_to_html( VALUE self ) 

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.