Class: RedCloth::TextileDoc

Class | RedCloth::TextileDoc
In: | lib/redcloth/textile_doc.rb ext/redcloth_scan/redcloth_scan.c lib/redcloth/textile_doc.rb
Parent: | String

A Textile document that can be converted to other formats. See the README for Textile syntax.

### Methods

html_esc latex_esc new new to to_html to_html to_latex to_latex

### Classes and Modules

Class RedCloth::TextileDoc::ParseError

### Attributes

filter_classes | [RW] | 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!’)
filter_classes | [RW] | 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!’)
filter_html | [RW] | 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!’)
filter_html | [RW] | 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!’)
filter_ids | [RW] | 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!’)
filter_ids | [RW] | 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!’)
filter_styles | [RW] | 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!’)
filter_styles | [RW] | 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!’)
hard_breaks | [RW] | 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.
hard_breaks | [RW] | 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.
lite_mode | [RW] | 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>!"
lite_mode | [RW] | 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>!"
no_span_caps | [RW] | 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.
no_span_caps | [RW] | 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.
sanitize_html | [RW] | 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!’)
sanitize_html | [RW] | 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

new( string, restrictions = [] )

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>"

[Source]

        # File lib/redcloth/textile_doc.rb, line 67
    67:     def initialize( string, restrictions = [] )
    68:       restrictions.each { |r| method("#{r}=").call( true ) }
    69:       super( string )
    70:     end

new( string, restrictions = [] )

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>"

[Source]

        # File lib/redcloth/textile_doc.rb, line 67
    67:     def initialize( string, restrictions = [] )
    68:       restrictions.each { |r| method("#{r}=").call( true ) }
    69:       super( string )
    70:     end

### Public Instance methods

html_esc(...)

Converts special characters into HTML entities.

[Source]

    /*
     * Converts special characters into HTML entities.
     */
    static VALUE
    redcloth_html_esc(int argc, VALUE* argv, VALUE self) //(self, str, level)
    {
      VALUE str, level;

      rb_scan_args(argc, argv, "11", &str, &level);

      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, *ch = NULL;
      if (te <= ts) return Qnil;

      while (t2 < te) {
        ch = NULL;

        // normal + pre
        switch (*t2)
        {
          case '&':  ch = "amp";    break;
          case '>':  ch = "gt";     break;
          case '<':  ch = "lt";     break;
        }

        // normal (non-pre)
        if (level != SYM_escape_preformatted) {
          switch (*t2)
          {
            case '\n': ch = "br";     break;
            case '"' : ch = "quot";   break;
            case '\'':
              ch = (level == SYM_escape_attributes) ? "apos" : "squot";
              break;
          }
        }

        if (ch != NULL)
        {
          if (t2 > t)
            rb_str_cat(new_str, t, t2-t);
          rb_str_concat(new_str, rb_funcall(self, rb_intern(ch), 1, rb_hash_new()));
          t = t2 + 1;
        }

        t2++;
      }
      if (t2 > t)
        rb_str_cat(new_str, t, t2-t);

      return new_str;
    }

latex_esc(p1)

Converts special characters into LaTeX entities.

[Source]

    /*
     * Converts special characters into LaTeX entities.
     */
    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, *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;
    }

to(p1)

Transforms a Textile document with `formatter`

[Source]

    /*
     * Transforms a Textile document with +formatter+
     */
    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);
      }
    }

to_html( *rules )

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, line 78
    78:     def to_html( *rules )
    79:       apply_rules(rules)
    80:
    81:       to(RedCloth::Formatters::HTML)
    82:     end

to_html( *rules )

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, line 78
    78:     def to_html( *rules )
    79:       apply_rules(rules)
    80:
    81:       to(RedCloth::Formatters::HTML)
    82:     end

to_latex( *rules )

Generates LaTeX from the Textile contents.

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

[Source]

        # File lib/redcloth/textile_doc.rb, line 90
    90:     def to_latex( *rules )
    91:       apply_rules(rules)
    92:
    93:       to(RedCloth::Formatters::LATEX)
    94:     end

to_latex( *rules )

Generates LaTeX from the Textile contents.

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

[Source]

        # File lib/redcloth/textile_doc.rb, line 90
    90:     def to_latex( *rules )
    91:       apply_rules(rules)
    92:
    93:       to(RedCloth::Formatters::LATEX)
    94:     end

[Validate]