Class: Redcarpet

Inherits:
Object
  • Object
show all
Defined in:
lib/redcarpet.rb,
ext/redcarpet/redcarpet.c

Overview

Upskirt is an implementation of John Gruber’s Markdown markup language. Upskirt is safe, fast and production ready.

Redcarpet is Upskirt with a touch of Ruby. It is mostly based on Ryan Tomayko’s RDiscount, and inspired by Rick Astley wearing a kilt.

Redcarpet is a drop-in replacement for BlueCloth, RedCloth and RDiscount.

Usage

Redcarpet implements the basic protocol popularized by RedCloth and adopted by BlueCloth:

require 'redcarpet'
markdown = Redcarpet.new("Hello World!")
puts markdown.to_html

Replacing BlueCloth

Inject Redcarpet into your BlueCloth-using code by replacing your bluecloth require statements with the following:

begin
  require 'redcarpet'
  BlueCloth = Redcarpet
rescue LoadError
  require 'bluecloth'
end

Direct Known Subclasses

RedcarpetCompat

Constant Summary collapse

VERSION =
'1.14.2'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, *extensions) ⇒ Redcarpet

Returns a new instance of Redcarpet.



85
86
87
88
# File 'lib/redcarpet.rb', line 85

def initialize(text, *extensions)
  @text  = text
  extensions.each { |e| send("#{e}=", true) }
end

Instance Attribute Details

Enable the Autolinking extension



62
63
64
# File 'lib/redcarpet.rb', line 62

def autolink
  @autolink
end

#fenced_codeObject

Enable PHP-Markdown fenced code extension



71
72
73
# File 'lib/redcarpet.rb', line 71

def fenced_code
  @fenced_code
end

#filter_htmlObject

Do not output any raw HTML included in the source text.



41
42
43
# File 'lib/redcarpet.rb', line 41

def filter_html
  @filter_html
end

#filter_stylesObject

Do not output <style> tags included in the source text.



38
39
40
# File 'lib/redcarpet.rb', line 38

def filter_styles
  @filter_styles
end

#generate_tocObject

Add TOC anchors to every header



59
60
61
# File 'lib/redcarpet.rb', line 59

def generate_toc
  @generate_toc
end

#gh_blockcodeObject

Generate safer HTML for code blocks (no custom CSS classes)



53
54
55
# File 'lib/redcarpet.rb', line 53

def gh_blockcode
  @gh_blockcode
end

#hard_wrapObject

Treat newlines in paragraphs as real line breaks, GitHub style



50
51
52
# File 'lib/redcarpet.rb', line 50

def hard_wrap
  @hard_wrap
end

#lax_htmlblockObject

Allow HTML blocks inside of paragraphs without being surrounded by newlines



74
75
76
# File 'lib/redcarpet.rb', line 74

def lax_htmlblock
  @lax_htmlblock
end

#no_imageObject

Do not process ![] and remove <img> tags from the output.



44
45
46
# File 'lib/redcarpet.rb', line 44

def no_image
  @no_image
end

#no_intraemphasisObject

Do not render emphasis_inside_words



77
78
79
# File 'lib/redcarpet.rb', line 77

def no_intraemphasis
  @no_intraemphasis
end

Do not process [] and remove <a> tags from the output.



47
48
49
# File 'lib/redcarpet.rb', line 47

def no_links
  @no_links
end

Don’t make hyperlinks from [][] links that have unknown URL types.



56
57
58
# File 'lib/redcarpet.rb', line 56

def safelink
  @safelink
end

#smartObject

Set true to have smarty-like quote translation performed.



35
36
37
# File 'lib/redcarpet.rb', line 35

def smart
  @smart
end

#space_headerObject

Force a space between header hashes and the header itself



83
84
85
# File 'lib/redcarpet.rb', line 83

def space_header
  @space_header
end

#strikethroughObject

Enable PHP-Markdown ~~strikethrough~~ extension



68
69
70
# File 'lib/redcarpet.rb', line 68

def strikethrough
  @strikethrough
end

#tablesObject

Enable PHP-Markdown tables extension



65
66
67
# File 'lib/redcarpet.rb', line 65

def tables
  @tables
end

#textObject (readonly)

Original Markdown formatted text.



32
33
34
# File 'lib/redcarpet.rb', line 32

def text
  @text
end

#xhtmlObject

Generate XHTML 1.0 compilant self-closing tags (e.g. <br/>)



80
81
82
# File 'lib/redcarpet.rb', line 80

def xhtml
  @xhtml
end

Instance Method Details

#to_html(*args) ⇒ Object



144
145
146
147
148
# File 'ext/redcarpet/redcarpet.c', line 144

static VALUE
rb_redcarpet_to_html(int argc, VALUE *argv, VALUE self)
{
	return rb_redcarpet__render(self, REDCARPET_RENDER_HTML);
}

#toc_content(*args) ⇒ Object



138
139
140
141
142
# File 'ext/redcarpet/redcarpet.c', line 138

static VALUE
rb_redcarpet_toc(int argc, VALUE *argv, VALUE self)
{
	return rb_redcarpet__render(self, REDCARPET_RENDER_TOC);
}