Tuesday, March 21, 2017

documentation - Linking to man page sections?


Online man pages in HTML with section anchors?


It would be good to have an online version of the Ubuntu man pages with direct links into subsections. That would allow to point someone to the relevant documentation in many cases - for example in answers of various StackExchange sites.


I will describe how a full solution might look, and in which ways that would be useful.
I do not think a complete solution is available somewhere,so the question is


Which partial solutions exist today?


For example, somehow systematic ways to search into the man pages, instead of linking, would be a partial solution.



The man pages at manpages.ubuntu.com solve most of the problem, but they do not have anchors on the headings or sections.


That means, if I want to point to the section "Parameter Expansion" in
man bash online, I have to use



See "Parameter Expansion" in man bash
[...and use your browser to search for "Parameter Expansion"]



This opens the bash man page at the top, as one long web page.


In the shell, I can say



See man bash | less "+/Parameter Expansion"



which jumps to the right place at startup.



It would be really helpful to have link anchors named like the headings they point to. Anchors named by some kind of index number would still help, but require a manual lookup on the actual web page to use it.


As it is not difficult on HTML level to add anchors to headings, I'm sure such man pages exist;
But is there a collection of the Ubuntu man pages with anchors online somewhere, or at least a good subset?


Example code


The header of section "Parameter Expansion" from
http://manpages.ubuntu.com/bash
which kind-of-redirects to
http://manpages.ubuntu.com/manpages/trusty/en/man1/bash.1.html


       [ ... ]
tildes in assignments to PATH, MAILPATH, and CDPATH, and the shell
assigns the expanded value.
Parameter Expansion
The `$' character introduces parameter expansion, command substitution,
or arithmetic expansion. The parameter name or symbol to be expanded
[ ... ]

To be able to link directly to this section, we need something like:


       [ ... ]
tildes in assignments to PATH, MAILPATH, and CDPATH, and the shell
assigns the expanded value.
Parameter Expansion
The `$' character introduces parameter expansion, command substitution,
or arithmetic expansion. The parameter name or symbol to be expanded
[ ... ]


This adds one tag to the HTML code, and one attribute, the section name without spaces:


Parameter Expansion
Parameter Expansion


Now, we can link to the section like


http://manpages.ubuntu.com/bash#ParameterExpansion
or even
manpages.ubuntu.com/bash#ParameterExpansion


which uses a foot note and is is written like
[manpages.ubuntu.com/bash#ParameterExpansion][6]




Use of other reference documents


In many cases, there are alternative reference documents available, appart from the man page. These often have a good link structure that is used to link from a table of content to the sections, just what we need.
But this does not solve the general problem, as there is no common way to find whether/where such a document existst, and to make use of the link structure.


For the bash example used above, the Bash Reference Manual could be used as an individual solution looked up manually:


Bash Reference Manual section Shell-Parameter-Expansion
written as
[Bash Reference Manual section Shell-Parameter-Expansion](http://www.gnu.org/software/bash/manual/bash.html#Shell-Parameter-Expansion)


Proposed implementation


To propose actually implementing this idea at manpages.ubuntu.com,
I filed a closely related bug/enhancement request on the associated project "ubuntu-manpage-repository":
launchpad #1355271: Use HTML a tags to allow external links to subsections of man pages



Yes, there is, it's http://man.cx/. It aims to have all man pages in one site, also in multiple languages. The anchors are unfortunately not named, but numbered: for example http://man.cx/printf#heading1 will take you to the first heading of the printf man page. Still I think it's better than without anchors ;)


PS. Add the site to your search engines, then you can simply type man printf in your address bar, and it will take you to the correct page, super awesome!


No comments:

Post a Comment

11.10 - Can't boot from USB after installing Ubuntu

I bought a Samsung series 5 notebook and a very strange thing happened: I installed Ubuntu 11.10 from a usb pen drive but when I restarted (...