Hi Branden,
G. Branden Robinson wrote on Tue, Jan 20, 2026 at 11:37:14AM -0600:
> A back-of-the-envelope solution might be to hack up groff man(7)'s `EX`
> and `EE` macros to inject a "<div style="font-family: mono>" into the
> former and "</div>" into the latter.
FWIW:
$ printf ".EX\nHello world!\n.EE\n" | mandoc -T html | grep -C1 pre
<main class="manual-text">
<pre>Hello world!
</pre>
</main>
I expect this will be harder to implement in roff than in mandoc,
but you have argued repeatedly that there are ways how even groff
can use semantic clues from macros to produce decent HTML.
While using <div> is acceptable in HTML 5 when no other HTML element
fits the intended semantic purpose, it should be avoided in cases for
which a more specific HTML element *is* defined. For that reason, <div>
is not the right HTML element to render .EX.
> Caveat: I don't actually know how to spell the CSS for what I'm talking
> about. Don't take the foregoing literally.
$ grep ^pre /usr/share/misc/mandoc.css
pre { font-family: inherit; }
Nothing to see here, please move on...
Using a monospace font is already the default for <pre> (not sure whether
that's specified in the standards or merely what practically all browsers
do - i'm too lazy to look it up right now, and it doesn't make a practical
difference anyway).
In cases where you are not sure browser defaults are reliable, such that
you want to use explicit CSS to request a font, do something like this:
$ printf '.Li Hello world!\n' | mandoc -mdoc -Thtml | grep -C1 Hello
<main class="manual-text">
<code class="Li">Hello world!</code>
</main>
$ grep -FA2 .Li /usr/share/misc/mandoc.css
.Li { font-style: normal;
font-weight: normal;
font-family: monospace; }
Two aspects are crucial here:
1. Do *not* use the "sytle=" attribute. It is deprecated in HTML 5
and defeats the central purpose of HTML and CSS, which is
separating content (text inside HTML elements), semantics
(HTML elements and attributes) and presentation (CSS).
2. Use the "class=" attribute to define which elements your CSS
will apply to, such that you do not clobber der defaults
(for example, in this case, for all <code> elements)
in the whole document.
3. Using an external stylesheet is the cleanest way to achieve the
desired separation. If for some reason, that is not an option,
as a rather ugly workaround, use the <style> element -
but *not* the "sytle=" attribute.
Yours,
Ingo
> `EX` and `EE` already have special machinery for dealing with the "dvi"
> and "lbp" output devices, so all one needs to do is follow that control
> structure model for "html".
>
> https://cgit.git.savannah.gnu.org/cgit/groff.git/tree/tmac/an.tmac?h=1.24.0.rc1#n1117