Skip Menu |

This queue is for tickets about the Pod-Markdown CPAN distribution.

Report information
The Basics
Id: 75620
Status: resolved
Priority: 0/
Queue: Pod-Markdown

People
Owner: Nobody in particular
Requestors: fschlich [...] zedat.fu-berlin.de
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 1.200000
Fixed in: (no value)



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
On Thu Mar 08 04:31:22 2012, fschlich wrote: Show quoted text
> 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
Mind if I ask what you're using to parse the Markdown? According to http://daringfireball.net/projects/markdown/syntax#precode: -- Regular Markdown syntax is not processed within code blocks. E.g., asterisks are just literal asterisks within a code block. This means it’s also easy to use Markdown to write about Markdown’s own syntax. -- Though I admit that at present I don't know the difference between a verbatim paragraph and a textblock... but is this really necessary in verbatim paragraphs? I'm not inherently opposed, just trying to understand the difference. Thanks. And sorry for the delay... my inbox fills up fast (and I forget).
Sorry, my brain fell asleep... I see your point about escaping these characters in regular text paragraphs... probably should escape some other characters, too... I'll look into it a little deeper, Thanks!
I've added the escaping to command paragraphs as well (like headings), but I think it should not be in verbatim paragraphs. I have also found an issue with text blocks that include inline code that has special chars inside... For example, C<foo * bar> should be `foo * bar` not `foo \* bar`, because the backslash becomes a literal character (which alters the meaning, can't be copy/pasted, etc.) So I'm going to toy with that a bit to see if work around that one. https://github.com/rwstauner/Pod-Markdown/tree/escape-chars
I found a way (using the parent methods in Pod::Parser) to not escape characters inside code sections and released as v1.300000