Convert troff man pages to semantic HTML.
This is used for rendering pages on ManKier.
Macro conversion:
.TH
→<title>, <h1>
: title heading macros become HTML title elements and the highest level of HTML section heading..SH, .SS
→<section>, <h2>, <h3>
: section heading macros become HTML section elements with HTML section headings..PP
→<p>
: paragraph macros become HTML paragraphs..TP, .TQ
→<dl>, <dt>, <dd>
: sequences of tagged paragraph macros become HTML definition lists..IP \(bu
→<ul>
: indented paragraph macros used for lists become HTML unordered lists.TS, .TE
→<table>
: tables handled by the tbl preprocessor for troff become HTML tables..UR, .UE
→<a href="">
: hyperlink URI macros become HTML URL anchors..MT, .ME
→<a href="">
: hyperlink email macros become HTML URL anchors with amailto:
scheme
See in the examples
folder:
.TH EXAMPLE "1" "June 2024" "manner" "Example Man Page"
.SH NAME
example \- sample man page
.SH SYNOPSIS
.B example
[\fI\,OPTION\/\fR]...
.SH DESCRIPTION
.\" This is a comment
.PP
Not a real command or man page!
.TP
\fB\-a\fR, \fB\-\-all\fR
a sample option
.TP
\fB\-b\fR, \fB\-\-ball\fR
another sample option
.PP
.TS
tab(@);
l l.
T{
Column 1
T}@T{
Column 2
T}
_
T{
row1
T}@T{
This is some tabular date
T}
T{
this is the second row
T}@T{
translated to an HTML <table>
T}
.TE
.SH SEE ALSO
.IP \(bu
First thing to see:
.UR https://example.com/something
Some Project
.UE .
.IP \(bu
Second thing to see.
.SH AUTHORS
This was written by
.MT [email protected]
Author 1
.ME
and
.MT [email protected]
Author 2
.ME .
After running:
./manner.php example.1 > example.html
... the output is compact, but reformatting with Prettier to show the structure of the output gives:
<!doctype html>
<meta charset="utf-8" />
<meta
name="man-page-info"
data-extra1="June 2024"
data-extra2="manner"
data-extra3="Example Man Page"
/>
<title>EXAMPLE</title>
<body>
<h1>EXAMPLE</h1>
<section>
<h2>NAME</h2>
<p>example - sample man page</p>
</section>
<section>
<h2>SYNOPSIS</h2>
<p><strong>example</strong> [<em>OPTION</em>]...</p>
</section>
<section>
<h2>DESCRIPTION</h2>
<p>Not a real command or man page!</p>
<dl>
<dt><strong>-a</strong>, <strong>--all</strong></dt>
<dd><p>a sample option</p></dd>
<dt><strong>-b</strong>, <strong>--ball</strong></dt>
<dd><p>another sample option</p></dd>
</dl>
<table>
<tr class="border-bottom">
<td>Column 1</td>
<td>Column 2</td>
</tr>
<tr>
<td>row1</td>
<td>This is some tabular date</td>
</tr>
<tr>
<td>this is the second row</td>
<td>translated to an HTML <table></td>
</tr>
</table>
</section>
<section>
<h2>SEE ALSO</h2>
<ul>
<li class="p">
First thing to see:
<a href="https://example.com/something">Some Project</a>.
</li>
<li class="p">Second thing to see.</li>
</ul>
</section>
<section>
<h2>AUTHORS</h2>
<p>
This was written by <a href="mailto:[email protected]">Author 1</a> and
<a href="mailto:[email protected]">Author 2</a>.
</p>
</section>
</body>
- PHP >= 8.2
- A few man pages contain
.EQ
macros, for these theeqn
command is required. - A few man pages contain
.PS
macros, for these thepic2plot
andinkscape
commands are required.