Text::Markdown::PerlExtensions - markdown converter that supports perl-specific extensions
In your markdown:
You might P<use> M<PerlX::Define> in D<Moops> by A<TOBYINK>.
And to convert that:
use Text::Markdown::PerlExtensions qw(markdown); $html = markdown($markdown);
Text::Markdown::PerlExtensions provides a function for converting markdown to HTML. It is a subclass of Text::Markdown that provides three additional features:
Four pod-style formatting codes, used for distribution names, module names, PAUSE author IDs, and Perl's built-in functions. These generate links to the relevant pages on MetaCPAN or perldoc.perl.org.
A mechanism for adding further pod-style formatting codes.
References to RT issues in the format RT#1234 will be hyperlinked to the issue on RT.
I wrote this module to use with my blogging engine. I found that I was constantly writing links to MetaCPAN, and wanted a terser notation.
The following sections describe each of the extensions, one by one.
To refer to a module on CPAN, you use the M formatting code. If you write:
M<Module::Path>
This generates:
<a href="https://metacpan.org/pod/Module::Path" class="module">Module::Path</a>
The link is given a class, so you can style module names.
To refer to a distribution, use the D formatting code. If you write
D<Dancer>
this generates:
<a href="https://metacpan.org/release/Dancer" class="distribution">Dancer</a>
Similarly, to refer to a CPAN author, use the A formatting code. If you write:
A<NEILB>
<a href="https://metacpan.org/author/NEILB" class="cpanAuthor">NEILB</a>
To link to documentation for one of Perl's built-in functions, use the P formatting code:
P<require>
This example would produce:
<a href="http://perldoc.perl.org/functions/require.html" class="function">require</a>
I really wanted to use the F formatting code for this, but that's already taken in the pod spec, used for highlighting file names.
Note: this doesn't check whether the function name given is actually a Perl built-in.
All other syntax is as supported by Text::Markdown. You shouldn't find any clashes between the Pod-like extensions; I haven't found any so far, but please let me know if you experience any problems.
You can add your own pod-style formatting codes. For each code you define a function that takes one text argument and returns the transformed version of that text.
The following shows how you could define I and B formatting codes, for italic and bold respectively:
use Text::Markdown::PerlExtensions qw(markdown add_formatting_code); sub format_italic { my $text = shift; return "<I>$text</I>"; } sub format_bold { my $text = shift; return "<B>$text</B>"; } add_formatting_code('I' => \&format_bold); add_formatting_code('B' => \&format_bold); my $md = 'Highlight with B<bold> and I<italic>.'; my $text = markdown($md);
Text::Markdown - the base class for this module.
Markdown - the original spec for markdown syntax.
https://github.com/neilb/Text-Markdown-PerlExtensions
Neil Bowers <neilb@cpan.org>
This software is copyright (c) 2014 by Neil Bowers <neilb@cpan.org>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Text::Markdown::PerlExtensions, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Text::Markdown::PerlExtensions
CPAN shell
perl -MCPAN -e shell install Text::Markdown::PerlExtensions
For more information on module installation, please visit the detailed CPAN module installation guide.