Class: RedCloth::TextileDoc
- Inherits:
-
String
- Object
- String
- RedCloth::TextileDoc
- Defined in:
- lib/redcloth/textile_doc.rb,
ext/redcloth_scan/redcloth_scan.c
Defined Under Namespace
Classes: ParseError
Instance Attribute Summary collapse
-
#filter_classes ⇒ Object
Accessors for setting security restrictions.
-
#filter_html ⇒ Object
Accessors for setting security restrictions.
-
#filter_ids ⇒ Object
Accessors for setting security restrictions.
-
#filter_styles ⇒ Object
Accessors for setting security restrictions.
-
#hard_breaks ⇒ Object
Deprecated accessor for toggling hard breaks.
-
#lite_mode ⇒ Object
Accessor for toggling lite mode.
-
#no_span_caps ⇒ Object
Accessor for toggling span caps.
-
#sanitize_html ⇒ Object
Accessors for setting security restrictions.
Instance Method Summary collapse
-
#html_esc ⇒ Object
(self, str, level).
-
#initialize(string, restrictions = []) ⇒ TextileDoc
constructor
Returns a new RedCloth object, based on string, observing any restrictions specified.
-
#latex_esc(str) ⇒ Object
Converts special characters into LaTeX entities.
-
#to ⇒ Object
Transforms a Textile document with
formatter. -
#to_html(*rules) ⇒ Object
Generates HTML from the Textile contents.
-
#to_latex(*rules) ⇒ Object
Generates LaTeX from the Textile contents.
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_classes ⇒ Object
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_html ⇒ Object
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_ids ⇒ Object
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_styles ⇒ Object
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_breaks ⇒ Object
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_mode ⇒ Object
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_caps ⇒ Object
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_html ⇒ Object
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
#html_esc ⇒ Object
(self, str, level)
22867 22868 22869 22870 22871 22872 22873 22874 22875 22876 22877 22878 22879 22880 22881 22882 22883 22884 22885 22886 22887 22888 22889 22890 22891 22892 22893 22894 22895 22896 22897 22898 22899 22900 22901 22902 22903 22904 22905 22906 22907 22908 22909 22910 22911 22912 22913 22914 22915 22916 22917 22918 22919 22920 22921 22922 22923 22924 22925 |
# File 'ext/redcloth_scan/redcloth_scan.c', line 22867 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; const char *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(str) ⇒ Object
Converts special characters into LaTeX entities.
22930 22931 22932 22933 22934 22935 22936 22937 22938 22939 22940 22941 22942 22943 22944 22945 22946 22947 22948 22949 22950 22951 22952 22953 22954 22955 22956 22957 22958 22959 22960 22961 22962 22963 22964 22965 22966 22967 22968 22969 22970 22971 22972 22973 22974 22975 22976 22977 22978 22979 22980 22981 22982 22983 22984 |
# File 'ext/redcloth_scan/redcloth_scan.c', line 22930 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; } |
#to ⇒ Object
Transforms a Textile document with formatter
22989 22990 22991 |
# File 'ext/redcloth_scan/redcloth_scan.c', line 22989 static VALUE redcloth_to(self, formatter) VALUE self, formatter; |
#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 |