version 1.247, 2018/12/16 00:17:02 |
version 1.252, 2019/01/18 14:36:21 |
|
|
/* $Id$ */ |
/* $Id$ */ |
/* |
/* |
* Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2011-2015, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org> |
* Copyright (c) 2011-2015, 2017-2019 Ingo Schwarze <schwarze@openbsd.org> |
* |
* |
* Permission to use, copy, modify, and distribute this software for any |
* Permission to use, copy, modify, and distribute this software for any |
* purpose with or without fee is hereby granted, provided that the above |
* purpose with or without fee is hereby granted, provided that the above |
Line 78 static const struct htmldata htmltags[TAG_MAX] = { |
|
Line 78 static const struct htmldata htmltags[TAG_MAX] = { |
|
{"dl", HTML_NLALL | HTML_INDENT}, |
{"dl", HTML_NLALL | HTML_INDENT}, |
{"dt", HTML_NLAROUND}, |
{"dt", HTML_NLAROUND}, |
{"dd", HTML_NLAROUND | HTML_INDENT}, |
{"dd", HTML_NLAROUND | HTML_INDENT}, |
|
{"p", HTML_NLAROUND | HTML_INDENT}, |
{"pre", HTML_NLALL | HTML_NOINDENT}, |
{"pre", HTML_NLALL | HTML_NOINDENT}, |
{"var", 0}, |
{"var", 0}, |
{"cite", 0}, |
{"cite", 0}, |
Line 265 print_metaf(struct html *h, enum mandoc_esc deco) |
|
Line 266 print_metaf(struct html *h, enum mandoc_esc deco) |
|
} |
} |
} |
} |
|
|
|
void |
|
html_close_paragraph(struct html *h) |
|
{ |
|
struct tag *t; |
|
|
|
for (t = h->tag; t != NULL && t->closed == 0; t = t->next) { |
|
switch(t->tag) { |
|
case TAG_P: |
|
case TAG_PRE: |
|
print_tagq(h, t); |
|
break; |
|
case TAG_A: |
|
print_tagq(h, t); |
|
continue; |
|
default: |
|
continue; |
|
} |
|
break; |
|
} |
|
} |
|
|
|
/* |
|
* ROFF_nf switches to no-fill mode, ROFF_fi to fill mode. |
|
* TOKEN_NONE does not switch. The old mode is returned. |
|
*/ |
|
enum roff_tok |
|
html_fillmode(struct html *h, enum roff_tok want) |
|
{ |
|
struct tag *t; |
|
enum roff_tok had; |
|
|
|
for (t = h->tag; t != NULL; t = t->next) |
|
if (t->tag == TAG_PRE) |
|
break; |
|
|
|
had = t == NULL ? ROFF_fi : ROFF_nf; |
|
|
|
if (want != had) { |
|
switch (want) { |
|
case ROFF_fi: |
|
print_tagq(h, t); |
|
break; |
|
case ROFF_nf: |
|
html_close_paragraph(h); |
|
print_otag(h, TAG_PRE, ""); |
|
break; |
|
case TOKEN_NONE: |
|
break; |
|
default: |
|
abort(); |
|
} |
|
} |
|
return had; |
|
} |
|
|
char * |
char * |
html_make_id(const struct roff_node *n, int unique) |
html_make_id(const struct roff_node *n, int unique) |
{ |
{ |
Line 531 print_otag(struct html *h, enum htmltag tag, const cha |
|
Line 587 print_otag(struct html *h, enum htmltag tag, const cha |
|
t = mandoc_malloc(sizeof(struct tag)); |
t = mandoc_malloc(sizeof(struct tag)); |
t->tag = tag; |
t->tag = tag; |
t->next = h->tag; |
t->next = h->tag; |
|
t->refcnt = 0; |
|
t->closed = 0; |
h->tag = t; |
h->tag = t; |
} else |
} else |
t = NULL; |
t = NULL; |
Line 609 print_otag(struct html *h, enum htmltag tag, const cha |
|
Line 667 print_otag(struct html *h, enum htmltag tag, const cha |
|
print_encode(h, arg1, NULL, 1); |
print_encode(h, arg1, NULL, 1); |
fmt++; |
fmt++; |
break; |
break; |
case 'T': |
|
print_encode(h, arg1, NULL, 1); |
|
print_word(h, "\" title=\""); |
|
print_encode(h, arg1, NULL, 1); |
|
fmt++; |
|
break; |
|
default: |
default: |
print_encode(h, arg1, NULL, 1); |
print_encode(h, arg1, NULL, 1); |
break; |
break; |
Line 669 print_ctag(struct html *h, struct tag *tag) |
|
Line 721 print_ctag(struct html *h, struct tag *tag) |
|
{ |
{ |
int tflags; |
int tflags; |
|
|
/* |
if (tag->closed == 0) { |
* Remember to close out and nullify the current |
tag->closed = 1; |
* meta-font and table, if applicable. |
if (tag == h->metaf) |
*/ |
h->metaf = NULL; |
if (tag == h->metaf) |
if (tag == h->tblt) |
h->metaf = NULL; |
h->tblt = NULL; |
if (tag == h->tblt) |
|
h->tblt = NULL; |
|
|
|
tflags = htmltags[tag->tag].flags; |
tflags = htmltags[tag->tag].flags; |
|
if (tflags & HTML_INDENT) |
if (tflags & HTML_INDENT) |
h->indent--; |
h->indent--; |
if (tflags & HTML_NOINDENT) |
if (tflags & HTML_NOINDENT) |
h->noindent--; |
h->noindent--; |
if (tflags & HTML_NLEND) |
if (tflags & HTML_NLEND) |
print_endline(h); |
print_endline(h); |
print_indent(h); |
print_indent(h); |
print_byte(h, '<'); |
print_byte(h, '<'); |
print_byte(h, '/'); |
print_byte(h, '/'); |
print_word(h, htmltags[tag->tag].name); |
print_word(h, htmltags[tag->tag].name); |
print_byte(h, '>'); |
print_byte(h, '>'); |
if (tflags & HTML_NLAFTER) |
if (tflags & HTML_NLAFTER) |
print_endline(h); |
print_endline(h); |
} |
|
if (tag->refcnt == 0) { |
h->tag = tag->next; |
h->tag = tag->next; |
free(tag); |
free(tag); |
|
} |
} |
} |
|
|
void |
void |
Line 782 print_text(struct html *h, const char *word) |
|
Line 833 print_text(struct html *h, const char *word) |
|
void |
void |
print_tagq(struct html *h, const struct tag *until) |
print_tagq(struct html *h, const struct tag *until) |
{ |
{ |
struct tag *tag; |
struct tag *this, *next; |
|
|
while ((tag = h->tag) != NULL) { |
for (this = h->tag; this != NULL; this = next) { |
print_ctag(h, tag); |
next = this == until ? NULL : this->next; |
if (until && tag == until) |
print_ctag(h, this); |
return; |
|
} |
} |
} |
} |
|
|
|
/* |
|
* Close out all open elements up to but excluding suntil. |
|
* Note that a paragraph just inside stays open together with it |
|
* because paragraphs include subsequent phrasing content. |
|
*/ |
void |
void |
print_stagq(struct html *h, const struct tag *suntil) |
print_stagq(struct html *h, const struct tag *suntil) |
{ |
{ |
struct tag *tag; |
struct tag *this, *next; |
|
|
while ((tag = h->tag) != NULL) { |
for (this = h->tag; this != NULL; this = next) { |
if (suntil && tag == suntil) |
next = this->next; |
return; |
if (this == suntil || (next == suntil && |
print_ctag(h, tag); |
(this->tag == TAG_P || this->tag == TAG_PRE))) |
|
break; |
|
print_ctag(h, this); |
} |
} |
} |
|
|
|
void |
|
print_paragraph(struct html *h) |
|
{ |
|
struct tag *t; |
|
|
|
t = print_otag(h, TAG_DIV, "c", "Pp"); |
|
print_tagq(h, t); |
|
} |
} |
|
|
|
|