Patch-Source: https://cvsweb.bsd.lv/mandoc/tag.c.diff?r1=1.36&r2=1.37
---
===================================================================
RCS file: /cvs/mandoc/tag.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -p -r1.36 -r1.37
--- mandoc/tag.c	2020/04/19 16:36:16	1.36
+++ mandoc/tag.c	2022/04/26 11:38:38	1.37
@@ -1,6 +1,7 @@
-/* $Id: tag.c,v 1.36 2020/04/19 16:36:16 schwarze Exp $ */
+/* $Id: tag.c,v 1.37 2022/04/26 11:38:38 schwarze Exp $ */
 /*
- * Copyright (c) 2015,2016,2018,2019,2020 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2015, 2016, 2018, 2019, 2020, 2022
+ *               Ingo Schwarze <schwarze@openbsd.org>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -80,7 +81,7 @@ tag_free(void)
 
 /*
  * Set a node where a term is defined,
- * unless it is already defined at a lower priority.
+ * unless the term is already defined at a lower priority.
  */
 void
 tag_put(const char *s, int prio, struct roff_node *n)
@@ -93,6 +94,18 @@ tag_put(const char *s, int prio, struct roff_node *n)
 
 	assert(prio <= TAG_FALLBACK);
 
+	/*
+	 * If the node is already tagged, the existing tag is
+	 * explicit and we are now about to add an implicit tag.
+	 * Don't do that; just skip implicit tagging if the author
+	 * specified an explicit tag.
+	 */
+
+	if (n->flags & NODE_ID)
+		return;
+
+	/* Determine the implicit tag. */
+
 	if (s == NULL) {
 		if (n->child == NULL || n->child->type != ROFFT_TEXT)
 			return;
@@ -150,7 +163,7 @@ tag_put(const char *s, int prio, struct roff_node *n)
 	 */
 
 	else if (entry->prio < prio)
-			return;
+		return;
 
 	/*
 	 * If the existing entry is worse, clear it.
