-
Notifications
You must be signed in to change notification settings - Fork 236
Description
It would be nice to be able to provide hints for syntax highlighting a given code block.
For example, executables often have a SYNOPSIS section that doesn't have Perl code in it like a library does, but instead has example command line invocations or a specification of the options and arguments the script accepts. That shouldn't be highlighted as though it were Perl code - it probably shouldn't by highlighted at all.
Similarly, some modules have ASCII art in code blocks to illustrate a data structure, for example. That shouldn't be highlighted either.
And some modules might (heaven forbid) include code blocks in a language other than Perl. It might be nice to provide a hint that "this block is actually Python".
Presumably this would use a =for
but I leave it up to others to decide whether this is something that should be metacpan-specific (which might give us =for metacpan txt
), or something more generally to do with syntax highlighting (which might give us =for syntax_highlighting txt
).
Activity
benkasminbullock commentedon Jun 20, 2012
From the Perl documentation:
There's nothing in verbatim paragraphs which has to be Perl code, so it shouldn't really be formatted as Perl code. The bug is really that metacpan or its underlying modules makes the assumption that "verbatim paragraph = Perl code" and colours it up as such.
tobyink commentedon Apr 10, 2013
For what it's worth, in the latest release of TOBYINK::Pod::HTML I use:
The reason for using a key-value pair is that it allows other hints to be passed to the highlighter too. For example:
ranguard commentedon Dec 23, 2013
Moved to wish list: https://github.com/CPAN-API/cpan-api/wiki/Wishlist
oalders commentedon Mar 16, 2014
After a conversation with @rjbs, I'm re-opening this. Might be a good task for a student. @rwstauner do you have any advice for how to implement this?
rwstauner commentedon Mar 19, 2014
At the moment I don't have a better suggestion than @tobyink's:
The
=for
block acts as a marker to say "from this point forward code blocks have the following attributes" and is otherwise empty. Then the verbatim block is regular (it is not attached to the=for
), but when looking to classify the block in html you use the most recently specified hints.It's not ideal, but I'm not aware of anything better that Pod provides so while it may not be "elegant" it is fairly clever.
The only other thing I can think of is to add a marker to the verbatim blocks (like
Pod::Elemental::Transformer::VimHTML
) but obviously that mucks up the block and will actually be seen by things whereas the=for
marker will be ignored by processors that choose not to use it.rjbs commentedon Mar 20, 2014
The
=for
paragraph is what I suggested in conversation at QAH, and I agree with all your points above.mauke commentedon Sep 10, 2017
FWIW, some of my modules have started using
=for highlighter language=...
directives. See e.g. https://metacpan.org/pod/URL::Search and https://metacpan.org/pod/Return::MultiLevel.I use it mainly for rendering a nice README.md for github, but it would be cool if metacpan DTRT, too.
haarg commentedon Sep 11, 2017
I think that the front end code will handle this already. The API will need to start using something like Pod::Simple::XHTML::WithHighlightConfig. I should make some changes to that module before integrating it though.