+ if (n->flags & NODE_ID) {
+ switch (n->tok) {
+ case MDOC_Pp:
+ nn = n->next;
+ if (nn == NULL || nn->type != ROFFT_TEXT ||
+ *nn->string == '\0' || *nn->string == ' ')
+ break;
+ /* Use the first few letters for the permalink. */
+ cp = nn->string;
+ while (cp != NULL && cp - nn->string < 5)
+ cp = strchr(cp + 1, ' ');
+ if (cp != NULL && cp[1] != '\0') {
+ /* Split a longer text node. */
+ man->last = nn;
+ man->next = ROFF_NEXT_SIBLING;
+ roff_word_alloc(man, nn->line,
+ nn->pos + (cp - nn->string), cp + 1);
+ man->last->flags = nn->flags;
+ *cp = '\0';
+ }
+ assert(nn->tag == NULL);
+ nn->tag = mandoc_strdup(n->tag);
+ nn->flags |= NODE_HREF;
+ break;
+ case MDOC_Bd:
+ case MDOC_Bl:
+ /* XXX No permalink for now. */
+ break;
+ default:
+ if (n->type == ROFFT_ELEM || n->tok == MDOC_Fo)
+ tag_move_id(n);
+ if (n->tok != MDOC_Tg)
+ n->flags |= NODE_HREF;
+ else if ((n->flags & NODE_ID) == 0) {
+ n->flags |= NODE_NOPRT;
+ free(n->tag);
+ n->tag = NULL;
+ }
+ break;
+ }
+ }
+ for (n = n->child; n != NULL; n = n->next)
+ tag_postprocess(man, n);