version 1.264, 2020/03/13 15:32:28 |
version 1.268, 2020/04/18 20:40:10 |
Line 344 html_make_id(const struct roff_node *n, int unique) |
|
Line 344 html_make_id(const struct roff_node *n, int unique) |
|
unsigned int slot; |
unsigned int slot; |
int suffix; |
int suffix; |
|
|
if (n->string != NULL) |
if (n->tag != NULL) |
buf = mandoc_strdup(n->string); |
buf = mandoc_strdup(n->tag); |
else { |
else { |
switch (n->tok) { |
switch (n->tok) { |
case MDOC_Sh: |
case MDOC_Sh: |
Line 362 html_make_id(const struct roff_node *n, int unique) |
|
Line 362 html_make_id(const struct roff_node *n, int unique) |
|
return NULL; |
return NULL; |
break; |
break; |
default: |
default: |
if (n->child->type != ROFFT_TEXT) |
if (n->child == NULL || n->child->type != ROFFT_TEXT) |
return NULL; |
return NULL; |
buf = mandoc_strdup(n->child->string); |
buf = mandoc_strdup(n->child->string); |
break; |
break; |
Line 769 print_otag(struct html *h, enum htmltag tag, const cha |
|
Line 769 print_otag(struct html *h, enum htmltag tag, const cha |
|
|
|
/* |
/* |
* Print an element with an optional "id=" attribute. |
* Print an element with an optional "id=" attribute. |
* If there is an "id=" attribute, also add a permalink: |
* If the element has phrasing content and an "id=" attribute, |
* outside if it's a phrasing element, or inside otherwise. |
* also add a permalink: outside if it can be in phrasing context, |
|
* inside otherwise. |
*/ |
*/ |
struct tag * |
struct tag * |
print_otag_id(struct html *h, enum htmltag elemtype, const char *cattr, |
print_otag_id(struct html *h, enum htmltag elemtype, const char *cattr, |
struct roff_node *n) |
struct roff_node *n) |
{ |
{ |
|
struct roff_node *nch; |
struct tag *ret, *t; |
struct tag *ret, *t; |
const char *id; |
char *id, *href; |
|
|
ret = NULL; |
ret = NULL; |
id = NULL; |
id = href = NULL; |
if (n->flags & NODE_ID) |
if (n->flags & NODE_ID) |
id = html_make_id(n, 1); |
id = html_make_id(n, 1); |
if (id != NULL && htmltags[elemtype].flags & HTML_INPHRASE) |
if (n->flags & NODE_HREF) |
ret = print_otag(h, TAG_A, "chR", "permalink", id); |
href = id == NULL ? html_make_id(n, 0) : id; |
|
if (href != NULL && htmltags[elemtype].flags & HTML_INPHRASE) |
|
ret = print_otag(h, TAG_A, "chR", "permalink", href); |
t = print_otag(h, elemtype, "ci", cattr, id); |
t = print_otag(h, elemtype, "ci", cattr, id); |
if (ret == NULL) { |
if (ret == NULL) { |
ret = t; |
ret = t; |
if (id != NULL) |
if (href != NULL && (nch = n->child) != NULL) { |
print_otag(h, TAG_A, "chR", "permalink", id); |
/* man(7) is safe, it tags phrasing content only. */ |
|
if (n->tok > MDOC_MAX || |
|
htmltags[elemtype].flags & HTML_TOPHRASE) |
|
nch = NULL; |
|
else /* For mdoc(7), beware of nested blocks. */ |
|
while (nch != NULL && nch->type == ROFFT_TEXT) |
|
nch = nch->next; |
|
if (nch == NULL) |
|
print_otag(h, TAG_A, "chR", "permalink", href); |
|
} |
} |
} |
|
if (id == NULL) |
|
free(href); |
return ret; |
return ret; |
} |
} |
|
|
Line 863 print_gen_comment(struct html *h, struct roff_node *n) |
|
Line 878 print_gen_comment(struct html *h, struct roff_node *n) |
|
void |
void |
print_text(struct html *h, const char *word) |
print_text(struct html *h, const char *word) |
{ |
{ |
|
print_tagged_text(h, word, NULL); |
|
} |
|
|
|
void |
|
print_tagged_text(struct html *h, const char *word, struct roff_node *n) |
|
{ |
|
struct tag *t; |
|
char *href; |
|
|
/* |
/* |
* Always wrap text in a paragraph unless already contained in |
* Always wrap text in a paragraph unless already contained in |
* some flow container; never put it directly into a section. |
* some flow container; never put it directly into a section. |
Line 883 print_text(struct html *h, const char *word) |
|
Line 907 print_text(struct html *h, const char *word) |
|
} |
} |
|
|
/* |
/* |
* Print the text, optionally surrounded by HTML whitespace, |
* Optionally switch fonts, optionally write a permalink, then |
* optionally manually switching fonts before and after. |
* print the text, optionally surrounded by HTML whitespace. |
*/ |
*/ |
|
|
assert(h->metaf == NULL); |
assert(h->metaf == NULL); |
print_metaf(h); |
print_metaf(h); |
print_indent(h); |
print_indent(h); |
|
|
|
if (n != NULL && (href = html_make_id(n, 0)) != NULL) { |
|
t = print_otag(h, TAG_A, "chR", "permalink", href); |
|
free(href); |
|
} else |
|
t = NULL; |
|
|
if ( ! print_encode(h, word, NULL, 0)) { |
if ( ! print_encode(h, word, NULL, 0)) { |
if ( ! (h->flags & HTML_NONOSPACE)) |
if ( ! (h->flags & HTML_NONOSPACE)) |
h->flags &= ~HTML_NOSPACE; |
h->flags &= ~HTML_NOSPACE; |
Line 900 print_text(struct html *h, const char *word) |
|
Line 931 print_text(struct html *h, const char *word) |
|
if (h->metaf != NULL) { |
if (h->metaf != NULL) { |
print_tagq(h, h->metaf); |
print_tagq(h, h->metaf); |
h->metaf = NULL; |
h->metaf = NULL; |
} |
} else if (t != NULL) |
|
print_tagq(h, t); |
|
|
h->flags &= ~HTML_IGNDELIM; |
h->flags &= ~HTML_IGNDELIM; |
} |
} |