Convert macOS man Pages to HTML (or a PDF) with mandoc
The man1 (i.e. manual) pages from macOS can get long. The more they grow, the less interest I have in scrolling them in the terminal. To avoid that, I use mandoc to make HTML versions. The command to generate a page looks like this:
Details
-
is the command. -
sets the output type to HTML. -
executes the standardcommand with theflag for thelscommand in this example.The
flag is used to return the file path to the source file for the man page instead of rendering the page itself. In the case ofon my machine, the path is/usr/share/man/man1/ls.1. That's what gets sent towhen the string is evaluated. -
sends the output fromto a file named.
Styling
The output from the command doesn't have any real styling by default. You can include a call to an external stylesheet with:
For example:
Happy Reading
I can get around man pages in the terminal alright. I'm sure there are more ways to move around than I use. Maybe I'll look into those more some day. For now, the HTML has me covered.
-a
Endnotes
I made a simple stylesheet that I use at ~/.config/mandoc/styles.css
. The command I run to use it is:
The stylesheet itself is:
}If you want to open the file after it's created you can add && to the command like:
&& I expect I'll end up making a command line function as a shortcut to this so I can do something like:
and have it make the page with the stylesheet in a standard location and then open the file.
It'll be on commands.alanwsmith.com when it's done.
can also make PDFs. You can output the file using the approach. You can also through it straight to the Preview app with:
| You're supposed to be able to update styles by editing the file:
That file doesn't exist for me and I can't create it. I'm not worried about it enough to figure out why.
Most of the post I saw talking about how to convert man pages into HTML use . It wasn't installed on my machine so I added it with homebrew. I couldn't get it to work properly though. It would cut off sections or throw out weird characters.
This page talks about how a tool called is no longer on macOS which seems to be part of the problem.
Whatever the case, I uninstalled once I found the solution.
Thinking about this, something that would be cool to have is a little local web server where you can just punch in the command you want and have it serve up the docs for you.
References
This is where I finally found the code to get the pages to output correctly.
Footnotes
Built-in manuals for apps and tools on mac and linux machines. They contain information on how to run commands with details on all the different options.
The default way to get at them is
For example, this is how to get the man page for the command:
They're the best place to go to dig into what an app/command can do.