[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [groff_www] Macro for codeblocks?
From: |
Ingo Schwarze |
Subject: |
Re: [groff_www] Macro for codeblocks? |
Date: |
Sun, 5 Sep 2021 12:25:22 +0200 |
User-agent: |
Mutt/1.12.2 (2019-09-21) |
Hello,
NRK wrote on Sun, Sep 05, 2021 at 07:10:12AM +0600:
> Recently I've thought about using groff for writing static website.
You mean, like
https://mandoc.bsd.lv/mdoc/
http://schwarze.bsd.lv/
?
> One problem I've ran into is doing codeblocks. What I'm trying to do is
> this:
>
> .HTML <pre><code>
> fun() {
> echo "hello" > /dev/null 2>&1;
> }
> .HTML </code></pre>
>
> However this doesn't preserve the indendation and newlines are not
> properly preserved either. The output I'm trying to achieve is _exactly_
> the following:
>
> <pre><code>
> fun() {
> echo "hello" > /dev/null 2>&1;
> }
> </code></pre>
>
> It should escape anything that needs escaping but preserve indendation
> and newlines properly.
$ cat tmp.mdoc
.Dd $Mdocdate$
.Dt TEST 1
.Os
.Sh NAME
.Nm test
.Nd descr
.Sh DESCRIPTION
.Bd -literal
fun() {
echo "hello" > /dev/null 2>&1;
}
.Ed
$ mandoc -T html tmp.mdoc
[...]
<div class="Bd Li">
<pre>fun() {
echo "hello" > /dev/null 2>&1;
}</pre>
</div>
[...]
Admittedly, <div class="Bd Li"> is not *exactly* <code>, but the default
CSS presents it in a similar way. The reason mandoc does not use <code>
here is that not every literal block necessarily contains code; i admit
it's not completely consistent because .Dl and .Ql do emit <code>.
Oh, you want to use groff, not mandoc. No, that is not possible,
because groff discards all the semantic information (information
about which high-level macros were used) before entering the HTML
output module, and that information is needed to pick appropriate
HTML elements.
Groff can do many things, but it is *not* designed to be a website
generator.
Yours,
Ingo