Class: RedCloth::TextileDoc

Inherits:
String
  • Object
show all
Defined in:
lib/redcloth/textile_doc.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string, restrictions = []) ⇒ TextileDoc

Returns a new RedCloth object, based on string, observing any restrictions specified.

r = RedCloth.new( "h1. A *bold* man" )
  #=> "h1. A *bold* man"
r.to_html
  #=>"<h1>A <b>bold</b> man</h1>"

67
68
69
70
# File 'lib/redcloth/textile_doc.rb', line 67

def initialize( string, restrictions = [] )
  restrictions.each { |r| method("#{r}=").call( true ) }
  super( string )
end

Instance Attribute Details

#filter_classesObject

Accessors for setting security restrictions.

This is a nice thing if you're using RedCloth for formatting in public places (e.g. Wikis) where you don't want users to abuse HTML for bad things.

If :filter_html is set, HTML which wasn't created by the Textile processor will be escaped. Alternatively, if :sanitize_html is set, HTML can pass through the Textile processor but unauthorized tags and attributes will be removed.

If :filter_styles is set, it will also disable the style markup specifier. ('red')

If :filter_classes is set, it will also disable class attributes. ('!(classname)image!')

If :filter_ids is set, it will also disable id attributes. ('!(classname#id)image!')


25
26
27
# File 'lib/redcloth/textile_doc.rb', line 25

def filter_classes
  @filter_classes
end

#filter_htmlObject

Accessors for setting security restrictions.

This is a nice thing if you're using RedCloth for formatting in public places (e.g. Wikis) where you don't want users to abuse HTML for bad things.

If :filter_html is set, HTML which wasn't created by the Textile processor will be escaped. Alternatively, if :sanitize_html is set, HTML can pass through the Textile processor but unauthorized tags and attributes will be removed.

If :filter_styles is set, it will also disable the style markup specifier. ('red')

If :filter_classes is set, it will also disable class attributes. ('!(classname)image!')

If :filter_ids is set, it will also disable id attributes. ('!(classname#id)image!')


25
26
27
# File 'lib/redcloth/textile_doc.rb', line 25

def filter_html
  @filter_html
end

#filter_idsObject

Accessors for setting security restrictions.

This is a nice thing if you're using RedCloth for formatting in public places (e.g. Wikis) where you don't want users to abuse HTML for bad things.

If :filter_html is set, HTML which wasn't created by the Textile processor will be escaped. Alternatively, if :sanitize_html is set, HTML can pass through the Textile processor but unauthorized tags and attributes will be removed.

If :filter_styles is set, it will also disable the style markup specifier. ('red')

If :filter_classes is set, it will also disable class attributes. ('!(classname)image!')

If :filter_ids is set, it will also disable id attributes. ('!(classname#id)image!')


25
26
27
# File 'lib/redcloth/textile_doc.rb', line 25

def filter_ids
  @filter_ids
end

#filter_stylesObject

Accessors for setting security restrictions.

This is a nice thing if you're using RedCloth for formatting in public places (e.g. Wikis) where you don't want users to abuse HTML for bad things.

If :filter_html is set, HTML which wasn't created by the Textile processor will be escaped. Alternatively, if :sanitize_html is set, HTML can pass through the Textile processor but unauthorized tags and attributes will be removed.

If :filter_styles is set, it will also disable the style markup specifier. ('red')

If :filter_classes is set, it will also disable class attributes. ('!(classname)image!')

If :filter_ids is set, it will also disable id attributes. ('!(classname#id)image!')


25
26
27
# File 'lib/redcloth/textile_doc.rb', line 25

def filter_styles
  @filter_styles
end

#hard_breaksObject

Deprecated accessor for toggling hard breaks.

Traditional RedCloth converted single newlines to HTML break tags, but later versions required :hard_breaks be set to enable this behavior. :hard_breaks is once again the default.


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

def hard_breaks
  @hard_breaks
end

#lite_modeObject

Accessor for toggling lite mode.

In lite mode, block-level rules are ignored. This means that tables, paragraphs, lists, and such aren't available. Only the inline markup for bold, italics, entities and so on.

r = RedCloth.new( "And then? She *fell*!", [:lite_mode] )
r.to_html
#=> "And then? She <strong>fell</strong>!"

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

def lite_mode
  @lite_mode
end

#no_span_capsObject

Accessor for toggling span caps.

Textile places `span' tags around capitalized words by default, but this wreaks havoc on Wikis. If :no_span_caps is set, this will be suppressed.


57
58
59
# File 'lib/redcloth/textile_doc.rb', line 57

def no_span_caps
  @no_span_caps
end

#sanitize_htmlObject

Accessors for setting security restrictions.

This is a nice thing if you're using RedCloth for formatting in public places (e.g. Wikis) where you don't want users to abuse HTML for bad things.

If :filter_html is set, HTML which wasn't created by the Textile processor will be escaped. Alternatively, if :sanitize_html is set, HTML can pass through the Textile processor but unauthorized tags and attributes will be removed.

If :filter_styles is set, it will also disable the style markup specifier. ('red')

If :filter_classes is set, it will also disable class attributes. ('!(classname)image!')

If :filter_ids is set, it will also disable id attributes. ('!(classname#id)image!')


25
26
27
# File 'lib/redcloth/textile_doc.rb', line 25

def sanitize_html
  @sanitize_html
end

Instance Method Details

#to_html(*rules) ⇒ Object

Generates HTML from the Textile contents.

RedCloth.new( "And then? She *fell*!" ).to_html
  #=>"<p>And then? She <strong>fell</strong>!</p>"

78
79
80
81
82
# File 'lib/redcloth/textile_doc.rb', line 78

def to_html( *rules )
  apply_rules(rules)
  
  to(RedCloth::Formatters::HTML)
end

#to_latex(*rules) ⇒ Object

Generates LaTeX from the Textile contents.

RedCloth.new( "And then? She *fell*!" ).to_latex
  #=> "And then? She \\textbf{fell}!\n\n"

90
91
92
93
94
# File 'lib/redcloth/textile_doc.rb', line 90

def to_latex( *rules )
  apply_rules(rules)
  
  to(RedCloth::Formatters::LATEX)
end