tech@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: наб <nabijaczleweli@nabijaczleweli.xyz>
To: tech@mandoc.bsd.lv
Subject: Bizarre .Nm-breaking-.Bd's-<pre> in -Thtml behaviour analysis + not a patch
Date: Sat, 16 Oct 2021 01:16:10 +0200	[thread overview]
Message-ID: <20211015231610.6zluzvlm2sovcurz@babtop.nabijaczleweli.xyz> (raw)
In-Reply-To: <20211012194230.aoxlusoaktmokwuc@tarta.nabijaczleweli.xyz>

[-- Attachment #1: Type: text/plain, Size: 4381 bytes --]

Ha, got it!

On Tue, Oct 12, 2021 at 09:42:30PM +0200, наб wrote:
> This one's weird, since I've written dozens of this sort of table before
> and it's always worked, but this is somehow broken. A minimal example is
> -- >8 --
> .Sh NAME
> .Nm a
> .
> .Sh EXAMPLES
> .Bd -literal
> .Nm
> b
> .Ed
> -- >8 --

If you apply this:
-- >8 --
Index: mdoc_html.c
===================================================================
RCS file: /cvs/mandoc/mdoc_html.c,v
retrieving revision 1.342
diff -u -r1.342 mdoc_html.c
--- mdoc_html.c	30 Mar 2021 19:26:20 -0000	1.342
+++ mdoc_html.c	15 Oct 2021 22:58:35 -0000
@@ -335,6 +335,8 @@
 {
 
 	while (n != NULL) {
+if(!strcmp(n->string ?: "", "a"))
+	fprintf(stderr, "a: %d\n", n->flags);
 		print_mdoc_node(meta, n, h);
 		n = n->next;
 	}
-- >8 --

Then the original test file gives this:
-- >8 --
nabijaczleweli@babtop:/tmp/mandoc$ stdbuf -o0  ./mandoc -Thtml -Ofragment /tmp/a.1 -mdoc
<table class="head">
  <tr>
    <td class="head-ltitle">UNTITLED</td>
    <td class="head-vol">LOCAL</td>
    <td class="head-rtitle">UNTITLED</td>
  </tr>
</table>
<div class="manual-text">
<section class="Sh">
<h1 class="Sh" id="NAME"><a class="permalink" href="#NAME">NAME</a></h1>
<p class="Pp"><code class="Nm">a: 3
a</code></p>
</section>
<section class="Sh">
<h1 class="Sh" id="EXAMPLES"><a class="permalink" href="#EXAMPLES">EXAMPLES</a></h1>
<div class="Bd Li">
<pre><code class="Nm">a: 515
</code></pre>
a
b</div>
</section>
</div>
<table class="foot">
  <tr>
    <td class="foot-date"></td>
    <td class="foot-os"></td>
  </tr>
</table>
-- >8 --

But one with an explicit ".Nm a" instead,
which yields correct output, gives this:
-- >8 --
nabijaczleweli@babtop:/tmp/mandoc$ stdbuf -o0  ./mandoc -Thtml -Ofragment /tmp/a2.1 -mdoc
<table class="head">
  <tr>
    <td class="head-ltitle">UNTITLED</td>
    <td class="head-vol">LOCAL</td>
    <td class="head-rtitle">UNTITLED</td>
  </tr>
</table>
<div class="manual-text">
<section class="Sh">
<h1 class="Sh" id="NAME"><a class="permalink" href="#NAME">NAME</a></h1>
<p class="Pp"><code class="Nm">a: 3
a</code></p>
</section>
<section class="Sh">
<h1 class="Sh" id="EXAMPLES"><a class="permalink" href="#EXAMPLES">EXAMPLES</a></h1>
<div class="Bd Li">
<pre><code class="Nm">a: 259
a</code>
b</pre>
</div>
</section>
</div>
<table class="foot">
  <tr>
    <td class="foot-date"></td>
    <td class="foot-os"></td>
  </tr>
</table>
-- >8 --

A glance at the flags gives us
	259 = 0b0100000011 = NODE_NOFILL|NODE_VALID|NODE_ENDED
	515 = 0b1000000011 = NODE_NOSRC |NODE_VALID|NODE_ENDED

This explodes in print_mdoc_node(), which does
-- >8 --
static void print_mdoc_node(MDOC_ARGS) {
    if (n->type == ROFFT_COMMENT || n->flags & NODE_NOPRT)
        return;

    if ((n->flags & NODE_NOFILL) == 0)
        html_fillmode(h, ROFF_fi);
    else if (html_fillmode(h, ROFF_nf) == ROFF_nf &&
        n->tok != ROFF_fi && n->flags & NODE_LINE)
        print_endline(h);

    ...
-- >8 --

Explicit Nm takes the latter branch, implicit the former,
and setting fillmode to fi outputs the dreaded "</code></pre>".

Needless to say, the fix is to set NODE_NOFILL on implicit Nms,
like it's done on explicit Nms:
-- >8 --
nabijaczleweli@babtop:/tmp/mandoc$ stdbuf -o0  ./mandoc -Thtml -Ofragment /tmp/a.1 -mdoc
<table class="head">
  <tr>
    <td class="head-ltitle">UNTITLED</td>
    <td class="head-vol">LOCAL</td>
    <td class="head-rtitle">UNTITLED</td>
  </tr>
</table>
<div class="manual-text">
<section class="Sh">
<h1 class="Sh" id="NAME"><a class="permalink" href="#NAME">NAME</a></h1>
<p class="Pp"><code class="Nm">a: 3
a</code></p>
</section>
<section class="Sh">
<h1 class="Sh" id="EXAMPLES"><a class="permalink" href="#EXAMPLES">EXAMPLES</a></h1>
<div class="Bd Li">
<pre><code class="Nm">a: 771
a</code>
b</pre>
</div>
</section>
</div>
<table class="foot">
  <tr>
    <td class="foot-date"></td>
    <td class="foot-os"></td>
  </tr>
</table>
-- >8 --

Where
	771 = 0b1100000011 = NODE_NOSRC|NODE_NOFILL|NODE_VALID|NODE_ENDED

Since ISTR you being somehow morally opposed to taking my patches,
my friendly advice is that I've found the code that sets this flag
to be at the tail-end of post_nm(), instead.

Best,
наб

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

      reply	other threads:[~2021-10-15 23:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-12 19:42 Bizarre .Nm-breaking-.Bd's-<pre> in -Thtml behaviour? наб
2021-10-15 23:16 ` наб [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211015231610.6zluzvlm2sovcurz@babtop.nabijaczleweli.xyz \
    --to=nabijaczleweli@nabijaczleweli.xyz \
    --cc=tech@mandoc.bsd.lv \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).