+/*
+ * Print an element with an optional "id=" attribute.
+ * If there is an "id=" attribute, also add a permalink:
+ * outside if it's a phrasing element, or inside otherwise.
+ */
+struct tag *
+print_otag_id(struct html *h, enum htmltag elemtype, const char *cattr,
+ struct roff_node *n)
+{
+ struct tag *ret, *t;
+ const char *id;
+
+ ret = NULL;
+ id = NULL;
+ if (n->flags & NODE_ID)
+ id = html_make_id(n, 1);
+ if (id != NULL && htmltags[elemtype].flags & HTML_INPHRASE)
+ ret = print_otag(h, TAG_A, "chR", "permalink", id);
+ t = print_otag(h, elemtype, "ci", cattr, id);
+ if (ret == NULL) {
+ ret = t;
+ if (id != NULL)
+ print_otag(h, TAG_A, "chR", "permalink", id);
+ }
+ return ret;
+}
+