Skip to content
Browse files

Added to_latex and to_groff_mm methods to PEGMarkdown class.

Documented in README.markdown.
Bumped version to 1.1 in Rakefile.
  • Loading branch information...
1 parent 16858b5 commit 26578d3ed070f12d2986ee4b229073770ade21b6 @jgm committed Aug 8, 2008
Showing with 56 additions and 1 deletion.
  1. +7 −0 README.markdown
  2. +1 −1 Rakefile
  3. +48 −0 ext/markdown.c
View
7 README.markdown
@@ -16,6 +16,13 @@ Synopsis
>> puts Markdown.new('_Hello World!_', :smart, :filter_html).to_html
<p><em>Hello World!</em></p>
+ >> puts Markdown.new('_Hello World!_').to_latex
+ \emph{Hello World!}
+
+ >> puts Markdown.new('_Hello World!_').to_groff_mm
+ .P
+ \fIHello world!\fR
+
>> PEGMarkdown.new('Hello! World!')
Installation / Hacking
View
2 Rakefile
@@ -5,7 +5,7 @@ require 'rake/gempackagetask'
task :default => :test
DLEXT = Config::CONFIG['DLEXT']
-VERS = '1.0'
+VERS = '1.1'
spec =
Gem::Specification.new do |s|
View
48 ext/markdown.c
@@ -29,10 +29,58 @@ rb_markdown_to_html(int argc, VALUE *argv, VALUE self)
return result;
}
+static VALUE
+rb_markdown_to_latex(int argc, VALUE *argv, VALUE self)
+{
+ /* grab char pointer to markdown input text */
+ VALUE text = rb_funcall(self, rb_intern("text"), 0);
+ Check_Type(text, T_STRING);
+ char * ptext = StringValuePtr(text);
+
+ /* flip extension bits - note that defaults are different than
+ * for HTML */
+ int extensions = EXT_SMART | EXT_NOTES | EXT_FILTER_HTML | EXT_FILTER_STYLES;
+ if ( rb_funcall(self, rb_intern("smart"), 0) == Qfalse )
+ extensions = extensions & ~ EXT_SMART ;
+ if ( rb_funcall(self, rb_intern("notes"), 0) == Qfalse )
+ extensions = extensions & ~ EXT_NOTES ;
+
+ char *latex = markdown_to_string(ptext, extensions, LATEX_FORMAT);
+ VALUE result = rb_str_new2(latex);
+ free(latex);
+
+ return result;
+}
+
+static VALUE
+rb_markdown_to_groff_mm(int argc, VALUE *argv, VALUE self)
+{
+ /* grab char pointer to markdown input text */
+ VALUE text = rb_funcall(self, rb_intern("text"), 0);
+ Check_Type(text, T_STRING);
+ char * ptext = StringValuePtr(text);
+
+ /* flip extension bits - note that defaults are different than
+ * for HTML */
+ int extensions = EXT_SMART | EXT_NOTES | EXT_FILTER_HTML | EXT_FILTER_STYLES;
+ if ( rb_funcall(self, rb_intern("smart"), 0) == Qfalse )
+ extensions = extensions & ~ EXT_SMART ;
+ if ( rb_funcall(self, rb_intern("notes"), 0) == Qfalse )
+ extensions = extensions & ~ EXT_NOTES ;
+
+ char *groff = markdown_to_string(ptext, extensions, GROFF_MM_FORMAT);
+ VALUE result = rb_str_new2(groff);
+ free(groff);
+
+ return result;
+}
+
void Init_peg_markdown()
{
rb_cMarkdown = rb_define_class("PEGMarkdown", rb_cObject);
rb_define_method(rb_cMarkdown, "to_html", rb_markdown_to_html, -1);
+ rb_define_method(rb_cMarkdown, "to_latex", rb_markdown_to_latex, -1);
+ rb_define_method(rb_cMarkdown, "to_groff_mm", rb_markdown_to_groff_mm, -1);
}
// vim: ts=4 sw=4

0 comments on commit 26578d3

Please sign in to comment.
Something went wrong with that request. Please try again.