9front - general discussion about 9front
 help / color / mirror / Atom feed
* [9front] htmlfmt anchor corner cases
@ 2020-12-20  9:29 umbraticus
  2020-12-20 22:03 ` cinap_lenrek
  0 siblings, 1 reply; 17+ messages in thread
From: umbraticus @ 2020-12-20  9:29 UTC (permalink / raw)
  To: 9front

With the -u flag, htmlfmt doesn't print relative links starting with a
slash correctly:

; echo '<a href=/blah.html>blah</a>' |
	htmlfmt -u http://site.dom/some/deep/path/index.html
blah [http://site.dom/some/deep/path/blah.html]
(should be http://site.dom/blah.html)

It also drops the space after “image” in the following example, since
the relative link starts with puntuation:

; echo '<img src=../blah.jpg>' | htmlfmt -a
[image../blah.jpg]

This messes up my elaborate rc + plumber webshit environment.  To
address this one I just decided to go for {imgpath} instead of [image
imgpath] (also fixes the issue just illustrated by piping this
paragraph through fmt...)  Patch below.

umbraticus

diff -r 1ae20c21a286 sys/src/cmd/htmlfmt/html.c
--- a/sys/src/cmd/htmlfmt/html.c	Sat Dec 19 19:15:02 2020 +0100
+++ b/sys/src/cmd/htmlfmt/html.c	Sun Dec 20 21:56:35 2020 +1300
@@ -170,6 +170,10 @@
 		if(base[strlen(base)-1]!='/' && (href==nil || href[0]!='/'))
 			result = eappend(result, "/", "");
 		free(base);
+		if(href!=nil && href[0]=='/'
+		&& (base = strchr(result, ':')) != nil
+		&& (base = strchr(base+3, '/')) != nil)
+			*base = '\0';
 	}
 	if(href){
 		if(result)
@@ -226,7 +230,7 @@
 			im = (Iimage*)il;
 			if(im->imsrc){
 				href = fullurl(u, im->imsrc);
-				renderbytes(t, "[image %s]", href);
+				renderbytes(t, "{%s}", href);
 				free(href);
 			}
 			break;

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2021-08-29  3:55 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-20  9:29 [9front] htmlfmt anchor corner cases umbraticus
2020-12-20 22:03 ` cinap_lenrek
2020-12-30  3:47   ` umbraticus
2020-12-31  9:42     ` umbraticus
2021-01-01  4:42       ` umbraticus
2021-01-01 10:05         ` Steve Simon
2021-01-01 19:26         ` ori
2021-01-20  2:20         ` ori
2021-01-20  2:49           ` Alex Musolino
2021-01-20  3:17           ` umbraticus
2021-01-24  5:46             ` umbraticus
2021-01-24 23:51               ` ori
2021-01-25 18:42                 ` umbraticus
2021-01-27  2:42               ` ori
2021-08-28 20:22               ` Stuart Morrow
2021-08-29  1:52                 ` umbraticus
2021-08-29  2:08                   ` ori

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).