[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mandoc-tech
Subject:    Bizarre .Nm-breaking-.Bd's-<pre> in -Thtml behaviour analysis + not a patch
From:       наб <nabijaczleweli () nabijaczleweli ! xyz>
Date:       2021-10-15 23:16:10
Message-ID: 20211015231610.6zluzvlm2sovcurz () babtop ! nabijaczleweli ! xyz
[Download RAW message or body]

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,
наб

["signature.asc" (application/pgp-signature)]
--
 To unsubscribe send an email to tech+unsubscribe@mandoc.bsd.lv


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic