class RedCloth::TextileDoc
A Textile document that can be converted to other formats. See the README for Textile syntax.
Attributes
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. (‘{color: 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!’)
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. (‘{color: 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!’)
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. (‘{color: 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!’)
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. (‘{color: 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!’)
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.
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>!"
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.
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. (‘{color: 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!’)
Public Class Methods
Source
# File lib/redcloth/textile_doc.rb 67 def initialize( string, restrictions = [] ) 68 restrictions.each { |r| method("#{r}=").call( true ) } 69 super( string ) 70 end
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>"
Public Instance Methods
Source
static VALUE redcloth_html_esc(int argc, VALUE* argv, VALUE self)
Converts special characters into HTML entities.
Source
static VALUE redcloth_latex_esc(VALUE self, VALUE str) { VALUE new_str = STR_NEW2(""); if (str == Qnil) return new_str; StringValue(str); if (RSTRING_LEN(str) == 0) return new_str; char *ts = RSTRING_PTR(str), *te = RSTRING_PTR(str) + RSTRING_LEN(str); char *t = ts, *t2 = ts; const char *ch = NULL; if (te <= ts) return Qnil; while (t2 < te) { ch = NULL; switch (*t2) { case '{': ch = "#123"; break; case '}': ch = "#125"; break; case '\\': ch = "#92"; break; case '#': ch = "#35"; break; case '$': ch = "#36"; break; case '%': ch = "#37"; break; case '&': ch = "amp"; break; case '_': ch = "#95"; break; case '^': ch = "circ"; break; case '~': ch = "tilde"; break; case '<': ch = "lt"; break; case '>': ch = "gt"; break; case '\n': ch = "#10"; break; } if (ch != NULL) { if (t2 > t) rb_str_cat(new_str, t, t2-t); VALUE opts = rb_hash_new(); rb_hash_aset(opts, ID2SYM(rb_intern("text")), STR_NEW2(ch)); rb_str_concat(new_str, rb_funcall(self, rb_intern("entity"), 1, opts)); t = t2 + 1; } t2++; } if (t2 > t) rb_str_cat(new_str, t, t2-t); return new_str; }
Converts special characters into LaTeX entities.
Source
static VALUE redcloth_to(self, formatter) VALUE self, formatter; { rb_funcall(self, rb_intern("delete!"), 1, STR_NEW2("\r")); VALUE working_copy = rb_obj_clone(self); rb_extend_object(working_copy, formatter); if (rb_funcall(working_copy, rb_intern("lite_mode"), 0) == Qtrue) { return redcloth_inline2(working_copy, self, rb_hash_new()); } else { return redcloth_transform2(working_copy, self); } }
Transforms a Textile document with formatter
Source
# File lib/redcloth/textile_doc.rb 78 def to_html( *rules ) 79 apply_rules(rules) 80 81 to(RedCloth::Formatters::HTML) 82 end
Generates HTML from the Textile contents.
RedCloth.new( "And then? She *fell*!" ).to_html #=>"<p>And then? She <strong>fell</strong>!</p>"
Source
# File lib/redcloth/textile_doc.rb 90 def to_latex( *rules ) 91 apply_rules(rules) 92 93 to(RedCloth::Formatters::LATEX) 94 end
Generates LaTeX from the Textile contents.
RedCloth.new( "And then? She *fell*!" ).to_latex #=> "And then? She \\textbf{fell}!\n\n"
Private Instance Methods
Source
# File lib/redcloth/textile_doc.rb 97 def apply_rules(rules) 98 rules.each do |r| 99 method(r).call(self) if self.respond_to?(r) 100 end 101 end