Subject: | Escaping * and _ in verbatim and textblocks |
Hi,
the Debian package of Pod-Markdown carries the attached patch, which adds
escaping to * and _ in verbatim and textblocks. Could you have a look at
these changes and apply them as appropriate?
Florian
Subject: | 0001-Escape-characters-that-can-have-a-special-meaning-in.patch |
Description: Escape characters that can have a special meaning in markdown
Escaping * and _ in verbatim and textblocks as they have special
meanings in markdown as emphasis
From: =?UTF-8?q?Carl=20F=C3=BCrstenberg?= <azatoth@gmail.com>
---
lib/Pod/Markdown.pm | 9 +++++++++
t/misc.t | 11 ++++++++++-
2 files changed, 19 insertions(+), 1 deletions(-)
--- a/lib/Pod/Markdown.pm
+++ b/lib/Pod/Markdown.pm
@@ -91,9 +91,17 @@
sub _clean_text {
my $text = $_[1];
my @trimmed = grep { $_; } split(/\n/, $text);
+
return wantarray ? @trimmed : join("\n", @trimmed);
}
+sub _escape {
+ my $text = $_[1];
+ # escape stars and stripes as they are interpret in markdown as emphasis
+ $text =~ s/(\_|\*)/\\$1/g;
+ return $text;
+}
+
sub command {
my ($parser, $command, $paragraph, $line_num) = @_;
my $data = $parser->_private;
@@ -154,6 +162,7 @@
sub verbatim {
my ($parser, $paragraph) = @_;
+ $paragraph = $parser->_escape($paragraph);
# NOTE: perlpodspec says parsers should expand tabs by default
# NOTE: Apparently Pod::Parser does not. should we?
@@ -182,6 +191,7 @@
sub textblock {
my ($parser, $paragraph, $line_num) = @_;
my $data = $parser->_private;
+ $paragraph = $parser->_escape($paragraph);
# interpolate the paragraph for embebed sequences
$paragraph = $parser->interpolate($paragraph, $line_num);
--- a/t/misc.t
+++ b/t/misc.t
@@ -17,7 +17,7 @@
# SYNOPSIS
- \$ pod2markdown < POD_File > Markdown_File
+ \$ pod2markdown < POD\\_File > Markdown\\_File
# DESCRIPTION
@@ -64,6 +64,11 @@
# Links
[Formatting `C`odes](${pod_prefix}Links#L<...>)
+
+# Special characters
+
+ foo\\_bar is the result of 4 \\* 4
+
EOMARKDOWN
1 while chomp $markdown;
@@ -138,3 +143,7 @@
=head1 Links
L<<< FormattZ<>ing C<C>odes|Links/"LE<lt>...E<gt>" >>>
+
+=head1 Special characters
+
+ foo_bar is the result of 4 * 4