-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implement images in POD #128
base: master
Are you sure you want to change the base?
Conversation
The patch allows pod formatters to recognize new image targets, and include these images in the output. The new image target is described as YAML, such as: =begin image src:image.png title: I<Fig.1> =end image or simply =for image src:image.png Both older parsers and the formatters that are not aware of the new functionality will retain full backward compatibility. There are added extra provisions for them, to render POD instead of images: =for image-text src:image.png I<text fallback> =for image-cut See more: - lib/Pod/Simple/Images.pod - syntax extensions - lib/Pod/Simple/HTML.pm - image-aware HTML formatters - lib/Pod/Simple/XHTML.pm - lib/Pod/Simple/YAML.pm - YAML 1.2 parser
As much as I welcome adding more features to POD, I can't help but being sceptical about images (side note: IMHO tables would be more important). A couple of questions/comments:
Thank you for the work you are investing into this! |
@marekro Hi Marek, #1 I've addressed in Images.pod:
which I mean should be a guideline what to do when one want images in the same directory. F ex the XHTML formatter is not responsible for installing images together with html files, but Makefile.PL is; it should it its job. LaTeX though very much can be made responsible, because it can only understand EPS files, and it's usually not a part of Makefile.PL. I would prefer that image installation should only be Makefile.PL's business, however if pod2html and pod2latex would introduce extra options for this, that should be okay I believe. #2: I've considered this but left it unimplemented (see YAML.pm):
So, entirely possible with either |
If the goal for these images to be diagrams, would a text-based diagram description language like Pic be more suited to readability and version-control? See for example Pikchr, which is actively being developed and "is designed to be embedded in fenced code blocks of Markdown or similar mechanisms of other documentation markup languages." Most of the brute-force image substitutes in Pod, such as in the Mojolicious Growing Guide, seem to be diagrams that Pic / Pikchr would be well suited to creating, in a human-readable and editable fashion. |
@lindleyw No the goal is not diagrams, the goal is image files, preferrably in jpeg/png/gif/webp format. |
and what to do if image is not found
Do you think this is now ready to merge; I see you made some recent trivial changes. |
In my opinion using YAML for this is significantly overcomplicating things. Pod renderers should be able to be trivially implemented. A simple text based format would be perfectly sufficient. |
@khwilliamson Yes it is ready. These changes were rather microscopic. @Grinnz I'm not sure I understand your point. If you're talking about a pod renderer, not a pod parser, then it doesn't even know that there is yaml under the hood. The renderer receives a simple perl hash such as |
The parser component having to understand YAML places even more burden in the wrong place, IMO. |
Indeed it does, but if we're going to define a simple text based format instead of yaml, then we're going to define a specification, and a bnf syntax, and what not. Yaml might be an overkill for the task but it saves us equally, if not greater burden to define and standartize such simple text format. Which might not necessarily become simple in the end. |
Defining a text format means we can define it to be only as complex as the task at hand requires. YAML is incredibly complex to support and recommend even when we only need a tiny subset of it. |
I'm not convinced that work and definition of the format for the task at hand if easier and better suited than a well-understood format, albeit more complex. There is no guarantee that this task at hand will require a simple syntax, too, - the img tag is open for extension, if someone wants later multi-resolution support, for example, syntax for Finally, if a pod parser writer consider it hard to parse yaml, which is a fair point, given that cpan's YAML is obsolete, then it's okay simply ignore these sections. Or simply matching |
FWIW the only in-core YAML parser is CPAN::Meta::YAML, which is a very stripped down implementation and only intended to support the very limited syntax of META.yml files. |
@karenetheridge the pull request includes Pod::Parser::YAML which is a rather (but not completely) full implementation, a single file of 19K/857 loc. If it comes in the core then it can be used for anything YAML, and the argument that 'yaml is complex' will be mostly moot |
I'll also point out that this is currently implemented in the PR by bundling yet another pure-perl YAML parser implementation that has to be tested and maintained separately from the ones already on CPAN. I'm not sure how this is less burden than a specific syntax parser. |
Well I see it that way: a yaml parser will require burden of test/maintenance. While a custom other syntax parser will require burden of specification, documentation, and again, test/maintenance. |
I'll put it this way. The entire rest of the pod specification is a simple paragraph based text format which requires minimal understanding and complexity even to manually parse - the most complicated aspect is getting the character encoding right. The use of YAML is very out of step with that design. And yes, it can be ignored by parsers - many specific comment types are - but Pod::Simple is practically speaking the reference parser, and if parsers ignore it then renderers won't be able to use it. |
What configuration needs to be parsed right now? It appears to be whitespace-separated key-value pairs. Why is YAML needed to parse that? I'm against including a full-fledged YAML parser here. "If it comes in the core then it can be used for anything YAML" is not a selling point. |
I don't agree that pod is that simple. @karenetheridge if core doesn't want use YAML it's fine, it's not a selling point for the core. The module is needed to parse image tags. The reason behing YAML is that we need multiline entries, and if we're going to implement something 'simple', as Dan suggests, that 'simple' needs to be discussed, documented, standardized etc which will be a huge pain by itself, and will not be simple after all. I see YAML's selling point is that it is well-understood, well-known, and gives great support for different styles of multiline scalars. |
I haven't looked at the code of Pod::Simple::YAML yet. Try running it against the YAML Test Suite. I just wanted to comment in general that providing a "simple" subset of YAML always has the same problems that YAML::Tiny and others have:
The goal of the most "simple" YAML parsers is to be, well, simpler to implement than a real parser. So, if people write YAML that is accepted by Pod::Simple::YAML, then it might be impossible to read that YAML with a different parser (in perl or other languages). I would advise to call the format something like SimpleYAML, ... and be really clear that it is not a subset of YAML. |
@perlpunk fair point, but I believe this implementation should be (meant to be, at least) a subset, except for that one reservation where space in "key: value" is not required - that was for my own sense of beauty as in |
Also it's an interesting idea to run it against the YAML test suite, but it's not quite it because the module by definition will fail on valid yaml (anchors, f ex), but what's more interesting if it consumes invalid yaml - can it do that? If yes, running through the suite will be the next step. |
To me this seems contradictory with "yaml is well-understood/well-known" (which I disagree with, for the record) - this would imply that this modification would be against well-understood syntax. |
As said, I'm open to remove it. The argument of parsing pod in other languages escaped me, but I absolutely don't want these other languages to write a SimpleYAML that is not yaml. I'd rather sacrifice the space if other languages can plug their standard YAML modules. |
The test suite has a list of tags for each test, like
Not sure what you mean here. It should fail on invalid YAML. |
Yes, invalid YAML tests have an But it should also fail on things which are allowed in YAML 1.2, but not supported in your subset.
is
which is wrong. |
Thank you this very valuable. Aliases I can fix so these will fail. As for |
Also for special types like booleans check this out: https://perlpunk.github.io/yaml-test-schema/schemas.html |
btw what would you say about nulls? I represent these as empty strings, not undefs, to not burden pod formatters with |
It's a question of what you call your parser and what it is documented to do. |
The YAML Test Suite from https://github.com/yaml/yaml-test-suite.git was used as a testbed for the following: 1) the parser converts valid yaml into expected perl structures 2) the parser fails on invalid yaml 3) the parser fails when input contains unimplemented features All three pass now fine, so with the exception of aliases,anchors,tags,and explicit keys, the module finally can call itself a YAML subset parser.
@perlpunk I think I managed to run the parser through the suite, and while I had to skip on lots of tests, the parser got significantly more robust now. I'd very much like to ask you if you could possibly take a look at the current state of things, to see if the module can, actually, be called a yaml parser. Upd: there's xt/yaml-test-suite.t that contains most info about what's left unimplemented |
@khwilliamson Karl, what do you think of the status now? I'd love to have Tina to bless the patch, as I think I addressed every concern, and some more. But there's not much happening.. |
I'm strongly against bringing a YAML decoder into core for this purpose. All the necessary information should be possible to convey in a simpler format. |
To put a finer point on it, I disagree with requiring a YAML parser for any part of the POD spec. |
@karenetheridge What I'm trying to bring here is not a full yaml parser but a rather reduced yaml parser, decidedly not implementing lots of yaml stuff. By cutting those corners yaml in full spec becomes a much more simpler format, not much more complex than any other format that should support image features that will be needed for C<=for image>. So let me repeat the pro points what do we gain by having a reduced YAML:
I really would like to understand why is it you guys against it. Consider this: okay we try to define another sub-language for Pod/Image. What's immediately needs to happen:
Who is going to do that? Are you going to go through all of it? Not me, because when I invested lots of time asking around for opinions, what is best and what is not, your opinion was not in the discussion. I'm not going to throw away all that code and effort and start from scratch because of this. And as a result, we won't have images in the pod. Everyone is happy. What's your conterpoints, or is it against for the sake of against? The reduced YAML parser module is a single file with 1100 lines including comments. How that could be complex if Pod::Simple::BlackBox.pm alone is 2500 lines, and Pod::Simple.pm is 1600 more? (Finally, there actually is already even more simple yaml parser for doing META.yml, in the core) |
Just a note, I'm extremely busy with personal stuff right now, and checking if a module implements a (subset of a) YAML parser is quite some work. I'm not sure when I'll have time to look at it. |
@perlpunk thanks, no problem! |
@khwilliamson Karl, should we, in your opinion, wait for Tina to take a look at the patch? I believe I addressed all her strategical concerns, passing the test suite and failing on improper/unknown yaml. If she or anyone has comments about finer point about syntax supported or unsupported that could be fixed easily. |
Seriously, we don't need a YAML parser to parse a key-value list, it's extreme overkill. Also, I don't think that 1143 line parser can be considered "simple". |
You already defined a brand new language and it's much more complicated than it should be. |
I do quite a bit with Pod and most of my books are written in Pod. I'd handle this all in basic, existing Pod with the translators I've created myself (because you're supposed to create your own translators).
|
@briandfoy that would work for a book as a single target media that is capable of graphics. However when you want to display something on a man page or plain text render or old pod parser that is not enough, unfortunately; there needs to be some sort of a fallback. |
@xenu "it's much more complicated than it should be." -- care to define how complicated it should be? |
I use it to output to several different formats at once, including some that are not capable of graphics. There is no single target. Since I can already add what targets I accept and how I handle them, there's nothing more I need from Pod::Simple to do what you are trying to do. I handle it all one level up. |
@briandfoy I don't really understand how would you generate a fallback text on a non-graphic media. F.ex. if I want image.png on html/latex and "this is some text" instead on a man page/text, how would it look in your syntax? |
The patch allows pod formatters to recognize new image targets,
and include these images in the output. The new image target is
described as YAML, such as:
or simply
Both older parsers and the formatters that are not aware of the new
functionality will retain full backward compatibility. There are added
extra provisions for them, to render POD instead of images:
See more: