source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mandoc: In "-T html" output, translate ".%R RFC <nuber>" to a hyperlink
@ 2025-01-19 16:40 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2025-01-19 16:40 UTC (permalink / raw)
  To: source

Log Message:
-----------
In "-T html" output, translate ".%R RFC <nuber>"
to a hyperlink to rfc-editor.org.

New feature first requested by tb@ in March 2023, now reminded by sthen@.
Patch tested by and OK tb@.

Modified Files:
--------------
    mandoc:
        mdoc_html.c

Revision Data
-------------
Index: mdoc_html.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mdoc_html.c,v
diff -Lmdoc_html.c -Lmdoc_html.c -u -p -r1.350 -r1.351
--- mdoc_html.c
+++ mdoc_html.c
@@ -1,6 +1,6 @@
 /* $Id$ */
 /*
- * Copyright (c) 2014-2022 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2014-2022, 2025 Ingo Schwarze <schwarze@openbsd.org>
  * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2022 Anna Vyalkova <cyber@sysrq.in>
  *
@@ -1494,10 +1494,13 @@ static int
 mdoc__x_pre(MDOC_ARGS)
 {
 	struct roff_node	*nn;
-	const char		*cattr;
+	const unsigned char	*cp;
+	const char		*cattr, *arg;
+	char			*url;
 	enum htmltag		 t;
 
 	t = TAG_SPAN;
+	arg = n->child->string;
 
 	switch (n->tok) {
 	case MDOC__A:
@@ -1537,13 +1540,25 @@ mdoc__x_pre(MDOC_ARGS)
 		cattr = "RsQ";
 		break;
 	case MDOC__R:
+		if (strncmp(arg, "RFC ", 4) == 0) {
+			cp = arg += 4;
+			while (isdigit(*cp))
+				cp++;
+			if (*cp == '\0') {
+				mandoc_asprintf(&url, "https://www.rfc-"
+				    "editor.org/rfc/rfc%s.html", arg);
+				print_otag(h, TAG_A, "ch", "RsR", url);
+				free(url);
+				return 1;
+			}
+		}
 		cattr = "RsR";
 		break;
 	case MDOC__T:
 		cattr = "RsT";
 		break;
 	case MDOC__U:
-		print_otag(h, TAG_A, "ch", "RsU", n->child->string);
+		print_otag(h, TAG_A, "ch", "RsU", arg);
 		return 1;
 	case MDOC__V:
 		cattr = "RsV";
--
 To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-01-19 16:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-19 16:40 mandoc: In "-T html" output, translate ".%R RFC <nuber>" to a hyperlink schwarze

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