Module: MD4C
- Defined in:
- lib/md4c.rb,
lib/md4c/version.rb,
sig/md4c.rbs,
ext/md4c/rb_md4c.c
Overview
-- Copyright (C) 2026 gemmaro
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/. ++
Defined Under Namespace
Modules: EqualByContent Classes: Anchor, CodeBlock, CodeText, Entity, Error, HTMLText, HardBreak, Heading, Image, LaTeXMathText, ListItem, NormalText, NullChar, OrderedList, Parser, SoftBreak, StringAttribute, Table, TableData, TableHeader, UnorderedList, WikiLink
Constant Summary collapse
- VERSION =
"0.0.1"
Class Method Summary collapse
Class Method Details
.markdown_to_html ⇒ Object
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 |
# File 'ext/md4c/rb_md4c.c', line 641
static VALUE
rbm_m_markdown_to_html (int argc, VALUE *argv, VALUE self)
{
VALUE input, kwargs;
rb_scan_args (argc, argv, "1:", &input, &kwargs);
char *text = rb_string_value_ptr (&input);
long size = RSTRING_LEN (input);
ID kwargs_ids[] = { PARSER_FLAGS, rb_intern ("verbatim_entities"),
rb_intern ("skip_utf8_bom"), rb_intern ("xhtml") };
VALUE kwargs_vals[sizeof (kwargs_ids) / sizeof (kwargs_ids[0])] = { 0 };
rb_get_kwargs (kwargs, kwargs_ids, 0,
sizeof (kwargs_ids) / sizeof (kwargs_ids[0]), kwargs_vals);
unsigned pflags = rbm_get_parser_flags (kwargs_vals);
unsigned rflags = 0;
if (!RB_UNDEF_P (kwargs_vals[19]) || RB_TEST (kwargs_vals[19]))
rflags |= MD_HTML_FLAG_VERBATIM_ENTITIES;
if (!RB_UNDEF_P (kwargs_vals[20]) || RB_TEST (kwargs_vals[20]))
rflags |= MD_HTML_FLAG_SKIP_UTF8_BOM;
if (!RB_UNDEF_P (kwargs_vals[21]) || RB_TEST (kwargs_vals[21]))
rflags |= MD_HTML_FLAG_XHTML;
struct rbm_markdown_to_html_userdata *userdata
= ruby_xmalloc (sizeof (struct rbm_markdown_to_html_userdata));
*userdata
= (struct rbm_markdown_to_html_userdata){ .block = rb_block_proc () };
if (md_html (text, (MD_SIZE)size, rbm_markdown_to_html_callback, userdata,
pflags, rflags)
!= 0)
{
ruby_xfree (userdata);
rb_raise (rbm_eError, "conversion fails");
}
ruby_xfree (userdata);
return RUBY_Qnil;
}
|