Text::Markdown(3)

✨ NAME ✨

okay bestie, welcome to the Text::Markdown(3) page β€” yes, that's the manual name, and it's User Contributed Perl Documentation energy from the jump. πŸ’… Text::Markdown is the module that converts Markdown syntax to (X)HTML β€” that's the whole NAME-section moment, periodt. ✨


🌈 SYNOPSIS 🌈

okay so here's the group-chat rundown of how you call it, no cap:

use Text::Markdown 'markdown';
my $html = markdown($text);

use Text::Markdown 'markdown';
my $html = markdown( $text, {
    empty_element_suffix => '>',
    tab_width => 2,
} );

use Text::Markdown;
my $m = Text::Markdown->new;
my $html = $m->markdown($text);

use Text::Markdown;
my $m = Text::MultiMarkdown->new(
    empty_element_suffix => '>',
    tab_width => 2,
);
my $html = $m->markdown( $text );

πŸ’– DESCRIPTION πŸ’–

Markdown is a text-to-HTML filter β€” it translates an easy-to-read / easy-to-write structured text format into HTML. Markdown's text format is most similar to that of plain text email, and it supports features such as headers, emphasis, code blocks, blockquotes, and links. 🫢

Markdown's syntax is designed not as a generic markup language, but specifically to serve as a front-end to (X)HTML. You can use span-level HTML tags anywhere in a Markdown document, and you can use block level HTML tags (like <div> and <table> as well). ✨


πŸ¦‹ SYNTAX πŸ¦‹

This module implements the 'original' Markdown markdown syntax from:

http://daringfireball.net/projects/markdown/

Note that Text::Markdown ensures that the output always ends with one newline. The fact that multiple newlines are collapsed into one makes sense, because this is the behavior of HTML towards whitespace. The fact that there's always a newline at the end makes sense again, given that the output will always be nested in a block-level element (as opposed to an inline element). That block element can be a <p> (most often), or a <table>. πŸŽ€

Markdown is not interpreted in HTML block-level elements, in order for chunks of pasted HTML (e.g. JavaScript widgets, web counters) to not be magically (mis)interpreted. For selective processing of Markdown in some, but not other, HTML block elements, add a markdown attribute to the block element and set its value to 1, "on" or "yes":

<div markdown="1" class="navbar">
* Home
* About
* Contact
<div>

The extra markdown attribute will be stripped when generating the output. 🧚


πŸŽ€ OPTIONS πŸŽ€

Text::Markdown supports a number of options to its processor which control the behaviour of the output document. πŸ‘‘

These options can be supplied to the constructor, or in a hash within individual calls to the markdown method. See the SYNOPSIS for examples of both styles. πŸ’–

The options for the processor are:

  • empty_element_suffix β€” This option controls the end of empty element tags:
'/>' for XHTML (default)
'>' for HTML
  • tab_width β€” Controls indent width in the generated markup. Defaults to 4.
  • trust_list_start_value β€” If true, ordered lists will use the first number as the starting point for numbering. This will let you pick up where you left off by writing:
1. foo
2. bar

some paragraph

3. baz
6. quux

(Note that in the above, quux will be numbered 4.)


πŸ’… METHODS πŸ’…

new

A simple constructor β€” see the SYNTAX and OPTIONS sections for more information. πŸ› οΈ

markdown

The main function as far as the outside world is concerned. See the SYNOPSIS for details on use. 🌟

urls

Returns a reference to a hash with the key being the markdown reference and the value being the URL. πŸ”—

Useful for building scripts which preprocess a list of links before the main content. See t/05options.t for an example of this hashref being passed back into the markdown method to create links. πŸ’«


🌸 OTHER IMPLEMENTATIONS 🌸

Markdown has been re-implemented in a number of languages, and with a number of additions. Those that I have found are listed below:


πŸ› BUGS πŸ›

To file bug reports or feature requests please send email to:

bug-Text-Markdown@rt.cpan.org

Please include with your report: (1) the example input; (2) the output you expected; (3) the output Markdown actually produced. πŸ™ˆ


⭐ VERSION HISTORY ⭐

See the Changes file for detailed release notes for this version. πŸ—‚οΈ


πŸ‘‘ AUTHOR πŸ‘‘


πŸ“ THIS DISTRIBUTION πŸ“

Please note that this distribution is a fork of John Gruber's original Markdown project, and it is not in any way blessed by him. 😭

Whilst this code aims to be compatible with the original Markdown.pl (and incorporates and passes the Markdown test suite) whilst fixing a number of bugs in the original β€” there may be differences between the behaviour of this module and Markdown.pl. If you find any differences where you believe Text::Markdown behaves contrary to the Markdown spec, please report them as bugs. πŸ›

Text::Markdown does not extend the markdown dialect in any way from that which is documented at daringfireball. If you want additional features, you should look at Text::MultiMarkdown. πŸ’…


🧚 SOURCE CODE 🧚

You can find the source code repository for Text::Markdown and Text::MultiMarkdown on GitHub at <http://github.com/bobtfish/text-markdown>. 🫢


okay legal bestie moment β€” here's the whole copyright + license tea, word for word where it matters. β˜•

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name "Markdown" nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

This software is provided by the copyright holders and contributors "as is" and any express or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In no event shall the copyright owner or contributors be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage.

mwah πŸ’‹ β€” this page is from perl v5.42.0, dated 2022-08-19, for Text::Markdown(3). That's the footer tea, and we're done. πŸ’–

πŸ“¦ where this page comes from