Class: Discount

Inherits:
Object
  • Object
show all
Defined in:
lib/discount.rb,
ext/discount.c

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, *extensions) ⇒ Discount

Returns a new instance of Discount.



18
19
20
21
22
23
24
25
# File 'lib/discount.rb', line 18

def initialize(text, *extensions)
  @text  = text
  @smart = nil
  @filter_styles = nil
  @filter_html = nil
  @fold_lines = nil
  extensions.each { |e| send("#{e}=", true) }
end

Instance Attribute Details

#filter_htmlObject

BlueCloth compatible output filtering.



12
13
14
# File 'lib/discount.rb', line 12

def filter_html
  @filter_html
end

#filter_stylesObject

BlueCloth compatible output filtering.



12
13
14
# File 'lib/discount.rb', line 12

def filter_styles
  @filter_styles
end

#fold_linesObject

RedCloth compatible line folding – not used for Markdown but included for compatibility.



16
17
18
# File 'lib/discount.rb', line 16

def fold_lines
  @fold_lines
end

#smartObject

Set true to have smarty-like quote translation performed.



9
10
11
# File 'lib/discount.rb', line 9

def smart
  @smart
end

#textObject (readonly)

Original Markdown formatted text.



6
7
8
# File 'lib/discount.rb', line 6

def text
  @text
end

Instance Method Details

#to_html(*args) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'ext/discount.c', line 13

static VALUE
rb_discount_to_html(int argc, VALUE *argv, VALUE self)
{
    /* grab char pointer to markdown input text */
    VALUE text = rb_funcall(self, id_text, 0);
    Check_Type(text, T_STRING);

    /* allocate a ruby string buffer and wrap it in a stream */
    VALUE buf = rb_str_buf_new(4096);
    FILE *stream = rb_str_io_new(buf);

    /* compile flags */
    int flags = MKD_TABSTOP | MKD_NOHEADER;
    if (rb_funcall(self, id_smart, 0) != Qtrue )
        flags = flags | MKD_NOPANTS;

    MMIOT *doc = mkd_string(RSTRING(text)->ptr, RSTRING(text)->len, flags);
    markdown(doc, stream, flags);

    fclose(stream);

    return buf;
}