String::Tagged::Markdown - parse and emit text with Markdown inline formatting
String::Tagged::Markdown
use String::Tagged::Markdown; my $st = String::Tagged::Markdown->parse_markdown( $markdown ); # Conforms to the String::Tagged::Formatting API String::Tagged::Terminal->new_from_formatting( $st->as_formatting )->say_to_terminal;
This subclass of String::Tagged handles text that contains inline markers to give formatting hints, in the style used by Markdown. For example, text wrapped in double-asterisks indicates it should be bold (as **bold**), or single-asterisks to indicate italics (as *italics*).
**bold**
*italics*
This module does not provide a full Markdown parser, but it does handle enough of the simple inline markers that it could be used to handle Markdown-style formatting hints of small paragraphs of text.
This module provides the following tags.
Boolean values indicating bold, italics, strike-through or fixed-width.
String value indicating a link. The value itself is the link target.
$st = String::Tagged::InlineFormatted->parse_markdown( $str )
Parses a text string containing Markdown-like formatting as described above.
Recognises the following kinds of inline text markers:
**bold** *italic* ~~strike~~ `fixed` [link](target) backslashes escape any special characters as \*
In addition, within `fixed` width spans, the other formatting markers are not recognised and are interpreted literally. To include literal backticks inside a `fixed` width span, use multiple backticks and a space to surround the sequence. Any sequence of fewer backticks within the sequence is interpreted literally. A single space on each side immediately within the outer backticks will be stripped, if present.
`fixed`
`` fixed width with `literal backticks` inside it ``
HTML entities - such as &, – or Ӓ are decoded, but only when not inside `fixed` spans.
&
–
Ӓ
$st = String::Tagged::Markdown->new_from_formatting( $fmt, %args )
Returns a new instance by convertig String::Tagged::Formatting standard tags.
The bold, italic and strike tags are preserved. monospace is renamed to fixed.
bold
italic
strike
monospace
fixed
Supports the following extra named arguments:
Optionally provides additional tag conversion callbacks, as defined by "clone" in String::Tagged.
$str = $st->build_markdown
Returns a plain text string containing Markdown-like inline formatting markers to format the tags in the given instance. Uses the notation given in the "parse_markdown" method above.
Non-ASCII Unicode characters are not generally emitted as HTML entities; though & and are generated for convenience.
$fmt = $st->as_formatting( %args )
Returns a new String::Tagged instance tagged with String::Tagged::Formatting standard tags.
String::Tagged
The bold, italic and strike tags are preserved, fixed is renamed to monospace. The link tag is currently not represented at all.
link
Fine-grained control of what HTML entities are generated on output.
Paul Evans <leonerd@leonerd.org.uk>
To install String::Tagged::Markdown, copy and paste the appropriate command in to your terminal.
cpanm
cpanm String::Tagged::Markdown
CPAN shell
perl -MCPAN -e shell install String::Tagged::Markdown
For more information on module installation, please visit the detailed CPAN module installation guide.