Text::Markdown::Discount
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

164 lines
3.9 KiB

15 years ago
15 years ago
15 years ago
11 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
  1. package Text::Markdown::Discount;
  2. use 5.008000;
  3. use strict;
  4. use warnings;
  5. require Exporter;
  6. our @ISA = qw(Exporter);
  7. # Items to export into callers namespace by default. Note: do not export
  8. # names by default without a very good reason. Use EXPORT_OK instead.
  9. # Do not simply export all your public functions/methods/constants.
  10. # This allows declaration use Text::Markdown::XS ':all';
  11. # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
  12. # will save memory.
  13. our %EXPORT_TAGS = ( 'all' => [ qw(
  14. markdown
  15. ) ] );
  16. our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
  17. our @EXPORT = qw(
  18. );
  19. our $VERSION = '0.08';
  20. require XSLoader;
  21. XSLoader::load('Text::Markdown::Discount', $VERSION);
  22. sub new {
  23. return bless {}, 'Text::Markdown::Discount';
  24. }
  25. sub markdown {
  26. my ($self, $text, $flags, $opts) = @_;
  27. if (not defined $flags) {
  28. $flags = MKD_NOHEADER()|MKD_NOPANTS();
  29. }
  30. if (not defined $opts or ref($opts) ne 'HASH') {
  31. $opts = {};
  32. }
  33. my $with_html5 = $opts->{with_html5} ? 1 : 0;
  34. # Detect functional mode, and create an instance for this run..
  35. unless (ref $self) {
  36. if ( $self ne __PACKAGE__ ) {
  37. my $ob = __PACKAGE__->new();
  38. # $self is text, $text is options
  39. return $ob->markdown($self, $text, $flags, $with_html5);
  40. }
  41. else {
  42. croak('Calling ' . $self . '->markdown (as a class method) is not supported.');
  43. }
  44. }
  45. return _markdown($text, $flags, $with_html5);
  46. }
  47. 1;
  48. __END__
  49. # Below is stub documentation for your module. You'd better edit it!
  50. =head1 NAME
  51. Text::Markdown::Discount - fast function for converting markdown to HTML (requires C compiler)
  52. =head1 SYNOPSIS
  53. use Text::Markdown::Discount;
  54. my $html = markdown($text)
  55. =head1 DESCRIPTION
  56. Text::Markdown::Discount is a perl interface to the C<Discount> library,
  57. a C implementation of John Gruber's C<markdown>.
  58. It is the fastest of the
  59. Perl modules available for converting markdown: see the list in L<"SEE ALSO">.
  60. It passes Gruber's Markdown testsuite.
  61. Given that the performance of Discount, Text::Markdown::Discount processes
  62. markdown formatted text quickly and passes the Markdown test suite at
  63. The interface of the C<markdown()> function in this module
  64. is not compatible with the C<markdown()> function in L<Text::Markdown>.
  65. =head2 EXPORT
  66. I<markdown> is exported by default.
  67. =head1 SEE ALSO
  68. There are other modules on CPAN for converting Markdown:
  69. =over 4
  70. =item *
  71. L<Text::Markdown> is a pure-perl markdown converter.
  72. =item *
  73. L<Markdent> is a toolkit for parsing markdown,
  74. which can also be used to convert markdown to HTML.
  75. =item *
  76. L<Text::Markup> is a converter than can handle a number of input formats, including markdown.
  77. =item *
  78. L<Text::MultiMarkdown> converts MultiMarkdown (a superset of the original markdown format)
  79. to HTML.
  80. =back
  81. Additional markdown resources:
  82. =over 4
  83. =item *
  84. L<Discount|http://www.pell.portland.or.us/~orc/Code/markdown/> -
  85. David Loren Parsons's library for converting markdown, written in C.
  86. =item *
  87. L<Markdown definition|http://daringfireball.net/projects/markdown/> -
  88. John Gruber's original definition of the markdown format.
  89. =item *
  90. L<Markdown testsuite|http://daringfireball.net/projects/downloads/MarkdownTest_1.0.zip> -
  91. John Gruber's testsuite for markdown.
  92. =item *
  93. L<Markdown modules|http://neilb.org/reviews/markdown.html> - a review
  94. of all Perl modules for handling markdown, written by Neil Bowers.
  95. =back
  96. =head1 AUTHOR
  97. Masayoshi Sekimura, E<lt>sekimura@cpan.orgE<gt>
  98. =head1 COPYRIGHT AND LICENSE
  99. Copyright (C) 2009 by Masayoshi Sekimura
  100. This library is free software; you can redistribute it and/or modify
  101. it under the same terms as Perl itself, either Perl version 5.10.0 or,
  102. at your option, any later version of Perl 5 you may have available.
  103. This product includes software developed by
  104. David Loren Parsons <http://www.pell.portland.or.us/~orc>
  105. =cut