Skip to content

Instantly share code, notes, and snippets.

@banister
Created June 26, 2012 09:28
Show Gist options
  • Save banister/2994644 to your computer and use it in GitHub Desktop.
Save banister/2994644 to your computer and use it in GitHub Desktop.
[6] (pry) main / Redcarpet: 1> cd Markdown
[7] (pry) main / Redcarpet / Redcarpet::Markdown: 2> ls -M
Redcarpet::Markdown#methods: render renderer
[8] (pry) main / Redcarpet / Redcarpet::Markdown: 2> $ render
Scanning and caching *.c files...
From: /Users/john/.rvm/gems/ruby-1.9.3-p194/gems/redcarpet-2.1.1/ext/redcarpet/rc_markdown.c (C Method):
Number of lines: 44
Owner: Redcarpet::Markdown
Visibility: public
static VALUE rb_redcarpet_md_render(VALUE self, VALUE text)
{
VALUE rb_rndr;
struct buf *output_buf;
struct sd_markdown *markdown;
Check_Type(text, T_STRING);
rb_rndr = rb_iv_get(self, "@renderer");
Data_Get_Struct(self, struct sd_markdown, markdown);
if (rb_respond_to(rb_rndr, rb_intern("preprocess")))
text = rb_funcall(rb_rndr, rb_intern("preprocess"), 1, text);
if (NIL_P(text))
return Qnil;
#ifdef HAVE_RUBY_ENCODING_H
{
struct rb_redcarpet_rndr *renderer;
Data_Get_Struct(rb_rndr, struct rb_redcarpet_rndr, renderer);
renderer->options.active_enc = rb_enc_get(text);
}
#endif
/* initialize buffers */
output_buf = bufnew(128);
/* render the magic */
sd_markdown_render(
output_buf,
RSTRING_PTR(text),
RSTRING_LEN(text),
markdown);
/* build the Ruby string */
text = redcarpet_str_new(output_buf->data, output_buf->size, rb_enc_get(text));
bufrelease(output_buf);
[9] (pry) main / Redcarpet / Redcarpet::Markdown: 2>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment