Skip Menu |

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

Report information
The Basics
Id: 57776
Status: open
Priority: 0/
Queue: Pod-Markdown

People
Owner: Nobody in particular
Requestors: JHTHORSEN [...] cpan.org
Cc: ether [...] cpan.org
AdminCc:

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



Subject: links in generated markdown
This is partially a wish and partially a bug. 1) Pod::Markdown does not parse internal links: L</foo> 2) Pod::Markdown does not parse links with text: L<text|foo> 3) It has some weird formatting for external links I think the attached patch can fix both of the issues. Note: The reason why i use <a name="..."> instead of <h1 id="..."> is that it seems like github is stripping of the "id" part of the markup.
Subject: links.patch
--- Markdown.pm 2010-03-27 15:40:50.000000000 +0100 +++ Markdown.jhthorsen 2010-05-23 10:14:49.000000000 +0200 @@ -90,7 +90,7 @@ my $level = $1; # the headers never are indented - $parser->_save(sprintf '%s %s', '#' x $level, $paragraph); + $parser->_save(sprintf '<h%i><a name="pod_%s">%s</a></h%i>', $level, $paragraph, $paragraph, $level); if ($level == 1) { if ($paragraph =~ m{NAME}xmsi) { $data->{searching} = 'title'; @@ -178,12 +178,18 @@ sub _resolv_link { my ($cmd, $arg, $pod_seq) = @_; - if ($arg =~ m{^http|ftp}xms) { + my $text = $arg =~ s"^(.+?)\|"" ? $1 : ''; - # direct link to a URL - return sprintf '<%s>', $arg; - } elsif ($arg =~ m{^(\w+(::\w+)*)$}) { - return "[$1](http://search.cpan.org/perldoc?$1)"; + if ($arg =~ m{^http|ftp}xms) { # direct link to a URL + $text ||= $arg; + return sprintf '[%s](%s)', $text, $arg; + } elsif ($arg =~ m{^/(.*)$}) { + $text ||= $1; + $text = $1; + return "[$text](\#pod_$1)"; + } elsif ($arg =~ m{^(\w+(?:::\w+)*)$}) { + $text ||= $1; + return "[$text](http://search.cpan.org/perldoc?$1)"; } else { return sprintf '%s<%s>', $cmd, $arg; }
Hi, Thanks for using this module; I agree its link handling is not very good. But your patch would make this module produce HTML (<h1>, <a>) - it is intended to convert Pod to Markdown. I've set the status of this ticket to 'rejected'; if you find a better way of doing this please send me another patch. But I don't think fragments are allowed in markdown - according to http://daringfireball.net/projects/markdown/syntax. Best regards, Marcel
Subject: Re: [rt.cpan.org #57776] links in generated markdown
Date: Sun, 23 May 2010 21:36:10 +0200
To: bug-Pod-Markdown [...] rt.cpan.org
From: Jan Henning Thorsen <jhthorsen [...] cpan.org>
But that's the beauty of Markdown: It allows you to combine html and markdown. Will you reconsider? At least take the L<text|link> bit of the patch..? On Sun, May 23, 2010 at 8:39 PM, Marcel Gruenauer == hanekomu via RT <bug-Pod-Markdown@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=57776 > > > Hi, > > Thanks for using this module; I agree its link handling is not very good. > > But your patch would make this module produce HTML (<h1>, <a>) - it is intended to convert > Pod to Markdown. > > I've set the status of this ticket to 'rejected'; if you find a better way of doing this please send > me another patch. But I don't think fragments are allowed in markdown - according to > http://daringfireball.net/projects/markdown/syntax. > > Best regards, > > Marcel >
From: fschlich [...] zedat.fu-berlin.de
On Sun May 23 14:39:57 2010, MARCEL wrote: Show quoted text
> Hi, > > Thanks for using this module; I agree its link handling is not very > good. > > But your patch would make this module produce HTML (<h1>, <a>) - it is > intended to convert > Pod to Markdown.
I agree that producing <h1> tags is probably inappropriate, as Markdown has its own ways to mark up headers. But Markdown does not have a way to define internal anchors to link to, and adding an HTML tag like <a name="pod_mysection"> before the markdown section header may just be the right thing to do. Show quoted text
> I've set the status of this ticket to 'rejected'; if you find a better > way of doing this please send > me another patch. But I don't think fragments are allowed in markdown > - according to > http://daringfireball.net/projects/markdown/syntax.
This is not correct. At least currently (October 2012) this document says: "The idea for Markdown is to make it easy to read, write, and edit prose. HTML is a publishing format; Markdown is a writing format. Thus, Markdown’s formatting syntax only addresses issues that can be conveyed in plain text. For any markup that is not covered by Markdown’s syntax, you simply use HTML itself. There’s no need to preface it or delimit it to indicate that you’re switching from Markdown to HTML; you just use the tags." So I think it's perfectly ok to use HTML to define internal link targets. Florian
From: fschlich [...] zedat.fu-berlin.de
On Sat Oct 27 19:19:43 2012, fschlich wrote: Show quoted text
> So I think it's perfectly ok to use HTML to define internal link > targets.
note, too, that Markdown flavors such as github or pandoc (http://johnmacfarlane.net/pandoc/demo/example9/pandocs- markdown.html#header-identifiers-in-html-latex-and-context) automatically produce lowercase anchors for all headers in a document when converting to HTML, so it may be sufficient to merely lowercase the target URL in case of an internal link: $text = $1; $url = lc($1); return "[$text](\#$url)";
Subject: section links in generated markdown
I believe the link parsing is now correct and the remaining issue is how to embed links to page fragments. I'm not crazy about the idea of muddying up the markdown with html tags but I'd be willing to make it an option in the constructor for those who wanted it. As for section anchors this is actually a problem that varies depending on the site which will be parsing and displaying the markdown (or the sites to which external links will be pointing). For example, github's header id attributes do not quite match the rules specified in the panoc link you provided... it appears to replace all non-word characters with a single dash and trim it (whereas pandoc has a few more rules to make it more complicated). I'm guessing other sites have their own rules. This extends beyond internal links... If the pod (being converted) contains links to specific sections in other modules the section/hash/anchor needs to be mangled according to the rules of the site it's pointing to. For example: http://search.cpan.org/perldoc?Moose#The_MooseX::_namespace versus https://metacpan.org/module/Moose#The-MooseX::-namespace * sco uses underscores * metacpan uses dashes * github replaces all-non-word chars * pandoc allows some punctuation So in order to get it right it seems to me that Pod::Markdown needs to be told what website will be it's destination, both for internal links and for external ones (and then needs custom code for each site). Currently the sites for man and perl module links are not customizable but I had hoped one day they would be. Regardless, section links to sco are currently broken because Pod::Markdown does not yet know the rules for mangling the section for sco. So the only solution I see that would be "correct" would be custom rules based on the destination sites (which would have to be specified in the constructor). Anyone have any better ideas?
On 2012-10-29 07:15:51, RWSTAUNER wrote: Show quoted text
> So in order to get it right it seems to me that Pod::Markdown needs to > be told what website will be it's destination, both for internal links > and for external ones (and then needs custom code for each site).
Show quoted text
> So the only solution I see that would be "correct" would be custom rules > based on the destination sites (which would have to be specified in the > constructor).
This logic should live in one of the higher-level modules, I would think, not this one. It's been discussed before that there should be variant implementations (subclasses?) that generate links to s.c.o, metacpan etc. e.g. see https://github.com/theory/pod-simple/pull/36
On Fri Nov 22 11:36:32 2013, ETHER wrote: Show quoted text
> On 2012-10-29 07:15:51, RWSTAUNER wrote: > >
> > So in order to get it right it seems to me that Pod::Markdown needs > > to > > be told what website will be it's destination, both for internal > > links > > and for external ones (and then needs custom code for each site).
>
> > So the only solution I see that would be "correct" would be custom > > rules > > based on the destination sites (which would have to be specified in > > the > > constructor).
> > This logic should live in one of the higher-level modules, I would > think, not this one. It's been discussed before that there should be > variant implementations (subclasses?) that generate links to s.c.o, > metacpan etc. > > e.g. see https://github.com/theory/pod-simple/pull/36
Yeah, it got a bit hairy (1.4/1.5)... there's probably a better place for it. I'm open to suggestions. I'm almost done converting this dist to use Pod::Simple instead of Pod::Parser, so you can expect a 2.000 release soon.