From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 9817 invoked from network); 1 Jan 2021 19:29:18 -0000 Received: from ewsd.inri.net (107.191.116.128) by inbox.vuxu.org with ESMTPUTF8; 1 Jan 2021 19:29:18 -0000 Received: from mimir.eigenstate.org ([206.124.132.107]) by ewsd; Fri Jan 1 14:26:37 -0500 2021 Received: from abbatoir.fios-router.home (pool-74-101-2-6.nycmny.fios.verizon.net [74.101.2.6]) by mimir.eigenstate.org (OpenSMTPD) with ESMTPSA id 6420b43d (TLSv1.2:ECDHE-RSA-AES256-SHA:256:NO) for <9front@9front.org>; Fri, 1 Jan 2021 11:26:28 -0800 (PST) Message-ID: <1D8FAB9003F85874A5FF46B50AC9CB99@eigenstate.org> To: 9front@9front.org Date: Fri, 01 Jan 2021 11:26:26 -0800 From: ori@eigenstate.org In-Reply-To: <49C417FFDD07DEE4E8B3A10933EE93B5@prosimetrum.com> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: open-source out-scaling rich-client hypervisor-aware locator Subject: Re: [9front] htmlfmt anchor corner cases Reply-To: 9front@9front.org Precedence: bulk Quoth umbraticus@prosimetrum.com: > Updated patch below (nimg should be global so > subelements don't cause duplicate image > footnotes). Quite enjoying these changes; > footnote mode much easier to read and work with. Yes, I like it quite a bit. And the number of '-'s in the diff is a nice bonus too: % diffstat /mail/fs/mbox/47572/body +++ 120 --- 172 A couple of comments: > + /* just a basic check... */ > + for(r = url; isalpha(*r); r++) > + ; > + if(r == baseurl || r[0] != ':' || r[1] != '/' || r[2] != '/' || r[3] == 0){ runestrncmp? directly indexing here without a length check makes me nervous, and runestrncmp is more compact. > - memset(rs, 0, sizeof rs); > - if(regexec(urlprog, url, rs, nelem(rs)) == 0) > - return nil; > - base = estrdup(url); > - slash = strrchr(base, '/'); > - if(slash!=nil && slash>=&base[rs[0].ep-rs[0].sp]) > - *slash = '\0'; > + for(r = path; isalpha(*r); r++) > + ; > + if(base == nil || r[0] == '#' || r > path && r[0] == ':' && r[1] == '/' && r[2] == '/' && r[3]) > + renderbytes(t, "%c%S%c", lc, path, rc); > + else if(path[0] == '/') > + renderbytes(t, "%c%S%S%c", lc, path[1] == '/' ? proto : root, path, rc); same as above > void > @@ -195,7 +184,6 @@ > Anchor *a; > Table *tab; > Tablecell *cell; > - char *href; > > inword = 0; > col = 0; > @@ -221,17 +209,18 @@ > renderbytes(t, "=======\n"); > break; > case Iimagetag: > - if(!aflag) > + if(links == NONE) > break; > im = (Iimage*)il; > if(im->imsrc){ > - href = fullurl(u, im->imsrc); > - renderbytes(t, "[image %s]", href); > - free(href); > + if(links & FOOTNOTES) You're using these as flags, but they don't act like flags as far as I can tell? I'd just use '==' here. > void > +afootnotes(URLwin *u, Bytes *t){ > + Anchor *x, *y, *z; > + > + x = u->docinfo->anchors; > + if(x == nil) > + return; > + renderbytes(t, "\n\nlinks:\n"); > + > + /* list needs reversing */ > + for(z = nil; x->next != nil; x = y){ > + y = x->next; > + x->next = z; > + z = x; > + } > + for(x->next = z; x != nil; x = x->next){ > + renderbytes(t, "[%d]", x->index); > + renderurl(t, x->href, ' ', '\n'); > + }; > +} Not a big deal, but why not just insert in the right order in libhtml? eg: di->anchors = newanchor(++is->nanchors, name, href, target, di->anchors); could become: newanchor(di, ++is->nanchors, name, href, target); which would do: if(di->tail != nil) di->tail->next = a; di->tail = a; Would probably simplify things if we can assume that anchors are in the right order. > ARGBEGIN{ > case 'a': > - aflag++; > + links |= INLINE; > break; > case 'c': > defcharset = EARGF(usage()); > break; > + case 'f': > + links |= FOOTNOTES; > + break; Same comment about flags. > case 'l': case 'w': > err = EARGF(usage()); > width = atoi(err); > @@ -65,8 +68,12 @@ > usage();