Class: Hive::Markup

Inherits:
Object
  • Object
show all
Defined in:
ext/hive_markup/hive_markup.c

Class Method Summary collapse

Class Method Details

.render(text) ⇒ Object



675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
# File 'ext/hive_markup/hive_markup.c', line 675

static VALUE rb_hive_markup_render(VALUE self, VALUE text) {
  Check_Type(text, T_STRING);
  
  size_t size;
  size = RSTRING_LEN(text);
  
  buffer *pre_buf = buf_new();
  
  if (!pre_buf) {
    return Qnil;
  }
  
  buffer *out_buf = buf_new();
  
  if (!out_buf) {
    return Qnil;
  }
  
  buf_expand(pre_buf, size);
  buf_expand(out_buf, size);
  
  preprocess_text((const uint8_t *)StringValuePtr(text), size, pre_buf);
  
  parse_text(pre_buf->data, 0, pre_buf->size, out_buf);
  
  text = rb_enc_str_new(
    (const char *)out_buf->data,
    out_buf->size,
    rb_enc_get(text)
  );
  
  buf_free(pre_buf);
  buf_free(out_buf);
  
  return text;
}