Bluecloth is a Ruby implementation of Markdown, a text-to-HTML conversion tool.
Michael Granger
Martin Chase
Florian Gross
This product includes software developed by David Loren Parsons <www.pell.portland.or.us/~orc>.
$Id$
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:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of the author/s, nor the names of the project’s contributors may be used to endorse or promote products derived from this software without specific prior written permission.
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.
Release Version
The defaults for all supported options.
The number of characters of the original markdown source to include in the output of #inspect
Do not process `[]’ and remove A tags from the output.
Do not process `![]’ and remove IMG tags from the output.
Do not do Smartypants-style mangling of quotes, dashes, or ellipses.
Escape all opening angle brackets in the input text instead of allowing block-level HTML
disable SUPERSCRIPT, RELAXED_EMPHASIS
process text inside an html tag; no , no
don’t allow pseudo-protocols
do table-of-contents processing
MarkdownTest 1.0 Compatibility Mode
Create links for inline URIs
Be paranoid about link protocols
don’t process header blocks
Return the version string of the Discount library BlueCloth was built on.
static VALUE bluecloth_s_discount_version( VALUE klass )
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
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:
Ignore links in Markdown, and escape A tags in the output. Defaults to false.
Ignore images in Markdown, and escape IMG tags in the output. Defaults to false.
Do Smartypants-style mangling of quotes, dashes, or ellipses. Defaults to true.
Support Discount’s pseudo-protocol links. Defaults to false.
Support the extraction of Pandoc headers, which can be fetched as a Hash via the #header method. Defaults to false.
Generate ID attributes for all headers. Defaults to false.
Escape all HTML in the input string. Defaults to false.
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 )
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
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
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
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 )
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
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.