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
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)
22483 22484 22485 22486 22487 22488 22489 22490 22491 22492 22493 22494 22495 22496 22497 22498 22499 22500 22501 22502 22503 22504 22505 22506 22507 22508 22509 22510 22511 22512 22513 22514 22515 22516 22517 22518 22519 22520 22521 22522 22523 22524 22525 22526 22527 22528 22529 22530 22531 22532 22533 22534 22535 22536 22537 22538 22539 22540 22541 |
# File 'ext/redcloth_scan/redcloth_scan.c', line 22483
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.
22546 22547 22548 22549 22550 22551 22552 22553 22554 22555 22556 22557 22558 22559 22560 22561 22562 22563 22564 22565 22566 22567 22568 22569 22570 22571 22572 22573 22574 22575 22576 22577 22578 22579 22580 22581 22582 22583 22584 22585 22586 22587 22588 22589 22590 22591 22592 22593 22594 22595 22596 22597 22598 22599 22600 |
# File 'ext/redcloth_scan/redcloth_scan.c', line 22546
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
22605 22606 22607 |
# File 'ext/redcloth_scan/redcloth_scan.c', line 22605 static VALUE redcloth_to(self, formatter) VALUE self, formatter; |
#to_html(*rules) ⇒ Object
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
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 |