Re: [feature] Add =image to perl pod #18169

2020-10-08 Thread Joaquín Ferrero
Example of images in pod documents:

Spreadsheet::WriteExcel::Examples 
https://metacpan.org/pod/Spreadsheet::WriteExcel::Examples


=begin html

http://homepage.eircom.net/~jmcnamara/perl/images/a_simple.jpg"; 
width="640" height="420" alt="Output from a_simple.pl" />

=end html


Re: [feature] Add =image to perl pod #18169

2020-10-06 Thread Dmitry Karasik
I’m not sure that I understand your argument and it feel a bit of a straw man - 
I’m targeting specifically html, latex, and pdf as the graphic backends, and 
have in mind markdown and xml as easily supported too. The proposal is that 
title and image are always shown together, or always ignored together. For html 
and others, P<> doesn’t need to be wrapped in =begin, that’s the whole point of 
it to not care about specific format, and only care for man pages when there is 
a gracious fallback. 

/dk

> On 1 Oct 2020, at 12.42, Patrice Dumas  wrote:
> 
> On Thu, Oct 01, 2020 at 11:35:45AM +0200, Dmitry Karasik wrote:
>> Hello,
>> 
>> I've proposed addition of images to pod, as discussed at [1], and would like 
>> to
>> ask for some more discussion here as well The idea is rather simple, to
>> introduce a P<> tag in two forms, P and P, that would
>> get converted to image in graphic formats, and ignored otherwise.
>> 
>> The image URI would be related either to the pod file location (without 
>> leading
>> /) or to the distro root (with leading /), that would allow referencing both
>> locally installed images as well as web views on github and metacpan.
>> 
>> Image title would get converted into  in html, if present.
>> 
>> In case a graceful fallback is needed by an author, the following trick 
>> could be
>> used:
> 
> I am not sure that it is good enough.  There is not only html and text
> as output format, the proposal seems a bit too format specific to me.  
> One option is to use the "title" in formats that cannot render the 
> image (text, man, for example).  The downside is that if one want to 
> have the title in html as alt/figcaption, but not rendered in the text
> case, one would need to use a specific format block for html too
> and would require format blocks for all the formats.
> 
> In that case there could be simply, if it is ok to have title as
> figcaption in html and title used in pllace of the image in text
> 
> P
> 
> But if one want to do a specific formatting for text, for example, it
> could be the following, with the downside that the other formats, even
> those which would be able to handle P will have to 
> have something explicitly specified:
> 
> =begin :html
> 
> P
> 
> =end :html
> 
> =begin text
> 
> y  **
> |  ** 
> |**
> |--> x
> 
> =end text
> 
> 
>> 
>> P
>> 
>> =begin text
>> 
>> ^ y  **
>> |  ** 
>> |**
>> |--> x
>> 
>> I'm thinking about working on a patch however I don't want to find myself in 
>> a
>> situation where it would be rejected or premature because the very topic is
>> undecided yet. 
>> 
>> Let's discuss this.
>> 
>> [1] https://github.com/Perl/perl5/issues/18169
>> 
>> 
>> -- 
>> Sincerely,
>>Dmitry Karasik


Re: [feature] Add =image to perl pod #18169

2020-10-05 Thread Dmitry Karasik
> 
> Hm, using =begin/=end as an extension mechanism is an interesting idea.
> It's unfortunate that limitations in the existing mechanism mean that a
> formatter still has to understand the extension to show the fallback text,
> but that may not be a significant problem.

Agree

> I think there is some merit to making your YAML-inspired syntax just be
> YAML if you go down that route so that parsers can reuse a YAML parser,
> although I understand why the complexity of YAML isn't appealing, and that
> also has weird implications for Perl core since introducing a YAML module
> into Perl core is going to be unappealing, but POD parsing currently lives
> in core.

I actually like to go full YAML to make that easier to implement and adopt.
Indeed it is a tactical question what to do with the YAML parser, but I think
the following trick can be done:

- Since Pod::Parser doesn't know that =image or whatever else is YAML, it
doesn't need to require it. I would be nice though, to have a hash passed down
to a formatter, but that requires YAML in the core, so let's don't look that
way just yet.

- XHML or other backends don't need YAML.pm and friends either because it
knows that it can only understand top-level data, no arrays or subhashes or
anything. So a rudimentary parsing is enough.

I don't think YAML, or YAML::PP will ever make it to the core due to the
modules' sheer size, - JSON::PP is a single file. But a minimal Pod::YAML is
quite feasible; and if it will be spec-complete, or at least complete enough to
skip the subarrays and subhashes, then the step 1 can be extended to the
benefit of all backends.

-- 
Sincerely,
Dmitry Karasik


Re: [feature] Add =image to perl pod #18169

2020-10-05 Thread Dmitry Karasik
On Sun, Oct 04, 2020 at 04:15:23PM -0400, Shawn H Corey wrote:
> On 2020-10-04 4:01 p.m., Dmitry Karasik wrote:
> > Indeed, either don't use ":" in "something", or use the full syntax, or we 
> > may
> > extend the syntax so that "\:" and "\\" expand to the unquoted symbols.
> 
> Use the POD escape sequence instead: E<0x3A> and E<0x20>
> 
> Also think about this:
> 
> =for image src:C:\Somewhere On My Disk\image.png

This one should be off limits: the discussion on the github led to a consensus 
that
local and remote URIs are actually okay to be merged into single "src:". One 
can,
if really wanted, write some sort of escape, but all bets are off.

Also, I think the pod escape sequences not necessarily should be applicable 
here.
If, as Russ suggests in another thread, use a full YAML vs YAML-like, which I 
like a lot,
then YAML escaping should be done then, whatever the YAML standard dictates.

Also, I was wrong about multiline =for, it pretty much exists. So one can do 
just this:

=for image
src:foo.png
text: text


-- 
Sincerely,
Dmitry Karasik


Re: [feature] Add =image to perl pod #18169

2020-10-04 Thread Shawn H Corey

On 2020-10-04 4:01 p.m., Dmitry Karasik wrote:

Indeed, either don't use ":" in "something", or use the full syntax, or we may
extend the syntax so that "\:" and "\\" expand to the unquoted symbols.


Use the POD escape sequence instead: E<0x3A> and E<0x20>

Also think about this:

=for image src:C:\Somewhere On My Disk\image.png



Re: [feature] Add =image to perl pod #18169

2020-10-04 Thread Russ Allbery
Dmitry Karasik  writes:

> 1) Full syntax (somewhat YAML-inspired)

> =begin image

> src: file.png
> title: Figure.1
> comment:
>   This is a multi-line
>   comment. Must start end end with newline.
>   Prefix spaces are skipped.

> resolution: 120
> whatever: value

> text:
>   This is fallback text
>   shown where graphics is unavailable
>   but the formatter is smart and knows
>   the =image tag.

> =end image

Hm, using =begin/=end as an extension mechanism is an interesting idea.
It's unfortunate that limitations in the existing mechanism mean that a
formatter still has to understand the extension to show the fallback text,
but that may not be a significant problem.

I have mixed feelings about introducing new syntax into POD to avoid using
command paragraphs.  I'm also a bit worried about adding a new ad hoc
configuration language rather than using some existing one with a
specification and existing parsers.  There are a lot of details and edge
cases in parsing rules, and a new ad hoc syntax either needs a detailed
specification (which is sort of annoying for everyone) or runs the risk
that different parsers will interpret it differently.  The merit in using
command paragraphs is that Pod::Simple and friends already know how to
parse them.

Unfortunately, the only other non-ad-hoc syntax that has a parser in Perl
core that I know of is JSON, and I certainly wouldn't want to use JSON
here.

I think there is some merit to making your YAML-inspired syntax just be
YAML if you go down that route so that parsers can reuse a YAML parser,
although I understand why the complexity of YAML isn't appealing, and that
also has weird implications for Perl core since introducing a YAML module
into Perl core is going to be unappealing, but POD parsing currently lives
in core.

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~|| 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


Re: [feature] Add =image to perl pod #18169

2020-10-04 Thread Dmitry Karasik
On Sun, Oct 04, 2020 at 03:29:04PM -0400, Shawn H Corey wrote:
> On 2020-10-04 3:23 p.m., Patrice Dumas wrote:
> > Are spaces ignored between :?  Should there be a separator to simplify
> > parsing, like

Spaces are ignored, yes.

> > =for image src:file.png, text:something
> Yes, there will be problems with separators since the separator can 
> appear in the "something".
> =for image src:file.png text:do no use colons ":" in your text.

Indeed, either don't use ":" in "something", or use the full syntax, or we may
extend the syntax so that "\:" and "\\" expand to the unquoted symbols. 

-- 
Sincerely,
Dmitry Karasik


Re: [feature] Add =image to perl pod #18169

2020-10-04 Thread Shawn H Corey

On 2020-10-04 3:23 p.m., Patrice Dumas wrote:

Are spaces ignored between :?  Should there be a separator to simplify
parsing, like

=for image src:file.png, text:something


Yes, there will be problems with separators since the separator can 
appear in the "something".


=for image src:file.png text:do no use colons ":" in your text.



Re: [feature] Add =image to perl pod #18169

2020-10-04 Thread Patrice Dumas
On Sun, Oct 04, 2020 at 05:11:35PM +0200, Dmitry Karasik wrote:
> Hello
> 
> Thank you all for review, it is clear that some things I wasn't focused at
> don't fall in as gracefully as I wanted. So it seems that P<> neither serves
> any good as an inline image anchor, nor versatile enough to specity
> accompanying text, and will require further additions to pod that would break
> backward compatibility. 
> 
> Having all of that in mind, I reworked the proposal, and here it's next 
> iteration:
> 
> 1) Full syntax (somewhat YAML-inspired)
> 
> =begin image
> 
> src: file.png
> title: Figure.1
> comment:
>   This is a multi-line
>   comment. Must start end end with newline.
>   Prefix spaces are skipped.
> 
> resolution: 120
> whatever: value
> 
> text:
>   This is fallback text
>   shown where graphics is unavailable
>   but the formatter is smart and knows
>   the =image tag.
> 
> =end image
> 
> 2) Short syntax that should cover 90% of use-cases
> 
> =for image src:file.png

Are spaces ignored between :?  Should there be a separator to simplify
parsing, like

=for image src:file.png, text:something

> 
> I think that covers it all now. What do you think?

It handles well my remarks.  It is quite complicated for pod, but I'll
let true poders (podlers?) comment further.

-- 
Pat


Re: [feature] Add =image to perl pod #18169

2020-10-04 Thread Dmitry Karasik
On Sun, Oct 04, 2020 at 11:23:18AM -0400, Shawn H Corey wrote:
> On 2020-10-04 11:11 a.m., Dmitry Karasik wrote:
> > =for image src:file.png
> 
> =for image src:file.png [fallback text]
> 
> There should be an option for fallback text.

There is, "text:". Or in this case,

=for image src:file.png text:fallback

but it will be limited to single line due to the =for restrictions

-- 
Sincerely,
Dmitry Karasik


Re: [feature] Add =image to perl pod #18169

2020-10-04 Thread Shawn H Corey

On 2020-10-04 11:11 a.m., Dmitry Karasik wrote:

=for image src:file.png


=for image src:file.png [fallback text]

There should be an option for fallback text.



Re: [feature] Add =image to perl pod #18169

2020-10-01 Thread Dmitry Karasik
> 
> I think you may be assuming there would be some special handling of P<> in
> a paragraph by itself as distinct from P<> in a paragraph with surrounding
> text, but if so I think that would be the first place in POD where a
> formatting code is handled differently based on its surrounding context.

Yes, that's correct. 

> I'm not sure that's a good precedent to set.

Do think that DWIM magic is too strong here?

> complexity that makes implementation a bit harder.  Plus, the author may
> have intended to have a paragraph consisting only of an emoji and would be
> quite surprised if that emoji turned into a figure!

That can be fixed by adding a Z<>, but you have a point.

> My preference is therefore for some method of markup that would make it
> explicit whether the image is intended to be inline or set off in a
> figure, because these are going to require different handling in a lot of
> output formats.

Nothing wrong with that, but that makes the syntax overburdened and less 
elegant.
If comes to this, I would rather skip that different handling altogether, 
sacrificing
either figure or inline image, for the sake of keeping P<> syntax 
straighforward.

> (Also, and I realize this was only an example, but I would not use images
> to show mathematical formulas.  For HTML output, MathJax would produce
> much better results.  That's a different topic of discussion, though, and
> I'm not volunteering to implement eqn support in Pod::Man)

I had only formulas examples in mind, so if that's the case, I'm willing to 
give up the inline support.

-- 
Sincerely,
Dmitry Karasik


Re: [feature] Add =image to perl pod #18169

2020-10-01 Thread Russ Allbery
Dmitry Karasik  writes:

> Correct! But isn't it beautiful? One can write it both ways P x_square.png>, and full-scale

> P< Figure 1, description | fig1.png >

I don't have a strong opinion because I don't maintain any graphical POD
formatters and thus will only be working with the alternative text, but I
think this is ambiguous.  It's not at all clear what, say, an HTML
formatter should do with those two examples.

I think you may be assuming there would be some special handling of P<> in
a paragraph by itself as distinct from P<> in a paragraph with surrounding
text, but if so I think that would be the first place in POD where a
formatting code is handled differently based on its surrounding context.
I'm not sure that's a good precedent to set.  It's the sort of hidden
complexity that makes implementation a bit harder.  Plus, the author may
have intended to have a paragraph consisting only of an emoji and would be
quite surprised if that emoji turned into a figure!

My preference is therefore for some method of markup that would make it
explicit whether the image is intended to be inline or set off in a
figure, because these are going to require different handling in a lot of
output formats.

(Also, and I realize this was only an example, but I would not use images
to show mathematical formulas.  For HTML output, MathJax would produce
much better results.  That's a different topic of discussion, though, and
I'm not volunteering to implement eqn support in Pod::Man)

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~|| 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


Re: [feature] Add =image to perl pod #18169

2020-10-01 Thread Dmitry Karasik


> I proposed an alternative with title that could be used in text output
> or in any output that cannot render the image.  The advantage of my
> proposal is that this would truly be independent of the format.  Whereas
> what you propose is actually format specific as one has to handle
> text/man in a specific way.  The disadvantage of my proposal is that
> when you really want to do something specific for text and not use the
> title, then it is more complicated.

Okay, I see. I answered to Russ about this, tl;dr: introduce =for can(text)
and =for can(graphic) for this

-- 
Sincerely,
Dmitry Karasik


Re: [feature] Add =image to perl pod #18169

2020-10-01 Thread Dmitry Karasik
> Using a formatting code for this seems a bit more complicated than might
> be necessary, since now the formatter needs to know whether the image
> truly should be inline (an emoji), whether it should float, whether it
> should be set off as a figure, etc.  Formatting codes imply that this is
> an emoji that should be totally inline with the text, which is certainly
> something people may want to do but which I suspect is not the common
> case.

Correct! But isn't it beautiful? One can write it both ways P,
and full-scale

P< Figure 1, description | fig1.png >

However it's not clear how to treat the title best. I'll address that below.

> > =begin text
> 
> > ^ y  **
> > |  ** 
> > |**
> > |--> x
> 
> This doesn't work with *roff output.

Indeed it doesn't, so here are options when one wants to address non-graphic 
formatter.

Option 1, the old way, write =for text, =for nroff explicitly. That's ugly.

Option 2, expantion of =for,=begin, and =end syntax, where one would be able to 
write
=for text,nroff. Still somewhat inelegant.

Option 3, extend the P<|> syntax with P<&> and P<^>, so that P 
will 
show either text or picture, P will show title only on graphic 
media,
and P would show both on graphic media but text on text/man only.

Option 4, cut the extra possibilities and vote for what the most useful 
translation of
P<|> would be.

> It's a bit tricky to wedge support for formats that don't support images
> into the POD syntax.  We could make up a keyword for =begin/=for that
> means "doesn't support images" and add support for that, but that means
> the whole image block will disappear for older formatters.

Or indeed as you propose, extend =for with roles/capabilities, so that for
example =for can(text) can answer to text and nroff, while =for can(graphic)
would do so for html,pdf etc.  With this, all discussions whether to include
text together with the image or not becomes irrelevant. The back-compat is 
important
but if there's no way to avoid breaking it, well, so be it?

Practically I don't see a big problem, because if the feature will be widely
adopted, major sites like github and metacpan would be getting feature requests
to support that, which covers about 95% of graphical pod usage.

> I wonder if it would make sense to do something like:
> 
> =image graph.png
> 
>   ^ y  **
>   |  ** 
>   |**
>   |--> x
> 
> =endimage

That's along the lines of my original proposal, which has a upside
that older formatter would immediately emit warnings, prompting for upgrade.
And a downside that it opens pandora's box for setting =image width="10em"
and what not, which I don't really want to encourage.


-- 
Sincerely,
Dmitry Karasik


Re: [feature] Add =image to perl pod #18169

2020-10-01 Thread Russ Allbery
Dmitry Karasik  writes:

> I've proposed addition of images to pod, as discussed at [1], and would
> like to ask for some more discussion here as well The idea is rather
> simple, to introduce a P<> tag in two forms, P and
> P, that would get converted to image in graphic formats,
> and ignored otherwise.

Using a formatting code for this seems a bit more complicated than might
be necessary, since now the formatter needs to know whether the image
truly should be inline (an emoji), whether it should float, whether it
should be set off as a figure, etc.  Formatting codes imply that this is
an emoji that should be totally inline with the text, which is certainly
something people may want to do but which I suspect is not the common
case.

I suspect what people care the most about is figures, which would argue
for the proposal that you have in the title (=image) instead of P<>.

> In case a graceful fallback is needed by an author, the following trick
> could be used:

> P

> =begin text

> ^ y  **
> |  ** 
> |**
> |--> x

This doesn't work with *roff output.

It's a bit tricky to wedge support for formats that don't support images
into the POD syntax.  We could make up a keyword for =begin/=for that
means "doesn't support images" and add support for that, but that means
the whole image block will disappear for older formatters.

I wonder if it would make sense to do something like:

=image graph.png

  ^ y  **
  |  ** 
  |**
  |--> x

=endimage

This a bit ugly, but it means that a formatter that ignores unknown
command paragraphs will display the fallback, which is probably the
backwards compatibility behavior you want.

Not sure how best to handle the title.  The cleanest way from the
perspective of a POD formatter is probably to add =imagetitle as well
(valid only inside an =image/=endimage pair) rather than trying to parse
the argument to =image.

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~|| 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


Re: [feature] Add =image to perl pod #18169

2020-10-01 Thread Patrice Dumas
On Thu, Oct 01, 2020 at 01:44:38PM +0200, Dmitry Karasik wrote:
> The proposal is that title and image are always shown together, or always 
> ignored together. For html and others, P<> doesn’t need to be wrapped in 
> =begin, that’s the whole point of it to not care about specific format, and 
> only care for man pages when there is a gracious fallback. 

I proposed an alternative with title that could be used in text output
or in any output that cannot render the image.  The advantage of my
proposal is that this would truly be independent of the format.  Whereas
what you propose is actually format specific as one has to handle
text/man in a specific way.  The disadvantage of my proposal is that
when you really want to do something specific for text and not use the
title, then it is more complicated.

-- 
Pat


Re: [feature] Add =image to perl pod #18169

2020-10-01 Thread Patrice Dumas
On Thu, Oct 01, 2020 at 11:35:45AM +0200, Dmitry Karasik wrote:
> Hello,
> 
> I've proposed addition of images to pod, as discussed at [1], and would like 
> to
> ask for some more discussion here as well The idea is rather simple, to
> introduce a P<> tag in two forms, P and P, that would
> get converted to image in graphic formats, and ignored otherwise.
> 
> The image URI would be related either to the pod file location (without 
> leading
> /) or to the distro root (with leading /), that would allow referencing both
> locally installed images as well as web views on github and metacpan.
> 
> Image title would get converted into  in html, if present.
> 
> In case a graceful fallback is needed by an author, the following trick could 
> be
> used:

I am not sure that it is good enough.  There is not only html and text
as output format, the proposal seems a bit too format specific to me.  
One option is to use the "title" in formats that cannot render the 
image (text, man, for example).  The downside is that if one want to 
have the title in html as alt/figcaption, but not rendered in the text
case, one would need to use a specific format block for html too
and would require format blocks for all the formats.

In that case there could be simply, if it is ok to have title as
figcaption in html and title used in pllace of the image in text

P

But if one want to do a specific formatting for text, for example, it
could be the following, with the downside that the other formats, even
those which would be able to handle P will have to 
have something explicitly specified:

=begin :html

P

=end :html

=begin text

y  **
|  ** 
|**
|--> x

=end text


> 
> P
> 
> =begin text
> 
> ^ y  **
> |  ** 
> |**
> |--> x
> 
> I'm thinking about working on a patch however I don't want to find myself in a
> situation where it would be rejected or premature because the very topic is
> undecided yet. 
> 
> Let's discuss this.
> 
> [1] https://github.com/Perl/perl5/issues/18169
> 
> 
> -- 
> Sincerely,
>   Dmitry Karasik