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.

178 lines
4.3 KiB

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
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.11';
  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) = @_;
  27. # Detect functional mode, and create an instance for this run..
  28. unless (ref $self) {
  29. if ( $self ne __PACKAGE__ ) {
  30. my $ob = __PACKAGE__->new();
  31. # $self is text, $text is options
  32. return $ob->markdown($self, $text, $flags);
  33. }
  34. else {
  35. croak('Calling ' . $self . '->markdown (as a class method) is not supported.');
  36. }
  37. }
  38. if (not defined $flags) {
  39. $flags = MKD_NOHEADER()|MKD_NOPANTS();
  40. }
  41. return _markdown($text, $flags);
  42. }
  43. 1;
  44. __END__
  45. # Below is stub documentation for your module. You'd better edit it!
  46. =head1 NAME
  47. Text::Markdown::Discount - fast function for converting markdown to HTML (requires C compiler)
  48. =head1 SYNOPSIS
  49. use Text::Markdown::Discount;
  50. my $html = markdown($text)
  51. =head1 DESCRIPTION
  52. Text::Markdown::Discount is a perl interface to the C<Discount> library,
  53. a C implementation of John Gruber's C<markdown>.
  54. It is the fastest of the
  55. Perl modules available for converting markdown: see the list in L<"SEE ALSO">.
  56. It passes Gruber's Markdown testsuite.
  57. Given that the performance of Discount, Text::Markdown::Discount processes
  58. markdown formatted text quickly and passes the Markdown test suite at
  59. The interface of the C<markdown()> function in this module
  60. is not compatible with the C<markdown()> function in L<Text::Markdown>.
  61. =head2 EXPORT
  62. I<markdown> is exported by default.
  63. =head2 FUNCTION
  64. =over
  65. =item C<Text::Markdown::Discount::with_html5_tags()>
  66. This function enables html5 block-level elements support.
  67. C<< Text::Markdown::Discount::markdown() >> will handle these html5 tags as
  68. block elements: aside, footer, header, hgroup, nav, section, article.
  69. B<NOTE>: There is no way to disable/re-enable this feature in one process right now.
  70. use Text::Markdown::Discount;
  71. Text::Markdown::Discount::with_html5_tags();
  72. my $html = markdown('<article>content</article>');
  73. #
  74. # In $html, <article> tag won't be wrapped with <p> tag
  75. =back
  76. =head1 SEE ALSO
  77. There are other modules on CPAN for converting Markdown:
  78. =over 4
  79. =item *
  80. L<Text::Markdown> is a pure-perl markdown converter.
  81. =item *
  82. L<Markdent> is a toolkit for parsing markdown,
  83. which can also be used to convert markdown to HTML.
  84. =item *
  85. L<Text::Markup> is a converter than can handle a number of input formats, including markdown.
  86. =item *
  87. L<Text::MultiMarkdown> converts MultiMarkdown (a superset of the original markdown format)
  88. to HTML.
  89. =back
  90. Additional markdown resources:
  91. =over 4
  92. =item *
  93. L<Discount|http://www.pell.portland.or.us/~orc/Code/markdown/> -
  94. David Loren Parsons's library for converting markdown, written in C.
  95. =item *
  96. L<Markdown definition|http://daringfireball.net/projects/markdown/> -
  97. John Gruber's original definition of the markdown format.
  98. =item *
  99. L<Markdown testsuite|http://daringfireball.net/projects/downloads/MarkdownTest_1.0.zip> -
  100. John Gruber's testsuite for markdown.
  101. =item *
  102. L<Markdown modules|http://neilb.org/reviews/markdown.html> - a review
  103. of all Perl modules for handling markdown, written by Neil Bowers.
  104. =back
  105. =head1 AUTHOR
  106. Masayoshi Sekimura, E<lt>sekimura@cpan.orgE<gt>
  107. =head1 COPYRIGHT AND LICENSE
  108. Copyright (C) 2013 by Masayoshi Sekimura
  109. This library is free software; you can redistribute it and/or modify
  110. it under the same terms as Perl itself, either Perl version 5.10.0 or,
  111. at your option, any later version of Perl 5 you may have available.
  112. This product includes software developed by
  113. David Loren Parsons <http://www.pell.portland.or.us/~orc>
  114. =cut