1
0
mirror of https://github.com/rkd77/elinks.git synced 2025-01-03 14:57:44 -05:00

[xhtml] code is compilable, but likely non-functional

This commit is contained in:
Witold Filipczyk 2021-06-20 22:38:17 +02:00
parent e3852637ff
commit ba3af06b40
16 changed files with 1168 additions and 664 deletions

View File

@ -83,6 +83,10 @@ struct html_context {
unsigned int has_link_lines:1; unsigned int has_link_lines:1;
unsigned int was_body:1; /* For META refresh inside <body>. */ unsigned int was_body:1; /* For META refresh inside <body>. */
unsigned int was_body_background:1; /* For <HTML> with style. */ unsigned int was_body_background:1; /* For <HTML> with style. */
unsigned int skip_html:1;
unsigned int skip_select:1;
unsigned int support_css:1;
unsigned int skip_textarea:1;
/* For html/parser.c, html/renderer.c */ /* For html/parser.c, html/renderer.c */
int margin; int margin;
@ -90,6 +94,8 @@ struct html_context {
/* For parser/forms.c: */ /* For parser/forms.c: */
char *startf; char *startf;
int ff;
/* For: /* For:
* html/parser/parse.c * html/parser/parse.c
* html/parser.c * html/parser.c
@ -131,13 +137,13 @@ struct html_context {
#define html_top ((struct html_element *) html_context->stack.next) #define html_top ((struct html_element *) html_context->stack.next)
#define html_bottom ((struct html_element *) html_context->stack.prev) #define html_bottom ((struct html_element *) html_context->stack.prev)
#define format (html_top->attr) #define elformat (html_top->attr)
#define par_format (html_top->parattr) #define par_elformat (html_top->parattr)
#define html_is_preformatted() (format.style.attr & AT_PREFORMATTED) #define html_is_preformatted() (elformat.style.attr & AT_PREFORMATTED)
#define get_html_max_width() \ #define get_html_max_width() \
int_max(par_format.width - (par_format.leftmargin + par_format.rightmargin), 0) int_max(par_elformat.width - (par_elformat.leftmargin + par_elformat.rightmargin), 0)
/* For parser/link.c: */ /* For parser/link.c: */

View File

@ -77,6 +77,19 @@ get_color(struct html_context *html_context, char *a,
return extract_color(html_context, a, attribute, rgb); return extract_color(html_context, a, attribute, rgb);
} }
int
get_color2(struct html_context *html_context, unsigned char *value_value, color_T *rgb)
{
if (!use_document_fg_colors(html_context->options))
return -1;
if (!value_value)
return -1;
return decode_color(value_value, strlen(value_value), rgb);
}
int int
get_bgcolor(struct html_context *html_context, char *a, color_T *rgb) get_bgcolor(struct html_context *html_context, char *a, color_T *rgb)
{ {
@ -244,8 +257,8 @@ html_focusable(struct html_context *html_context, char *a)
int cp; int cp;
int tabindex; int tabindex;
format.accesskey = 0; elformat.accesskey = 0;
format.tabindex = 0x80000000; elformat.tabindex = 0x80000000;
if (!a) return; if (!a) return;
@ -253,22 +266,22 @@ html_focusable(struct html_context *html_context, char *a)
accesskey = get_attr_val(a, "accesskey", cp); accesskey = get_attr_val(a, "accesskey", cp);
if (accesskey) { if (accesskey) {
format.accesskey = accesskey_string_to_unicode(accesskey); elformat.accesskey = accesskey_string_to_unicode(accesskey);
mem_free(accesskey); mem_free(accesskey);
} }
tabindex = get_num(a, "tabindex", cp); tabindex = get_num(a, "tabindex", cp);
if (0 < tabindex && tabindex < 32767) { if (0 < tabindex && tabindex < 32767) {
format.tabindex = (tabindex & 0x7fff) << 16; elformat.tabindex = (tabindex & 0x7fff) << 16;
} }
mem_free_set(&format.onclick, get_attr_val(a, "onclick", cp)); mem_free_set(&elformat.onclick, get_attr_val(a, "onclick", cp));
mem_free_set(&format.ondblclick, get_attr_val(a, "ondblclick", cp)); mem_free_set(&elformat.ondblclick, get_attr_val(a, "ondblclick", cp));
mem_free_set(&format.onmouseover, get_attr_val(a, "onmouseover", cp)); mem_free_set(&elformat.onmouseover, get_attr_val(a, "onmouseover", cp));
mem_free_set(&format.onhover, get_attr_val(a, "onhover", cp)); mem_free_set(&elformat.onhover, get_attr_val(a, "onhover", cp));
mem_free_set(&format.onfocus, get_attr_val(a, "onfocus", cp)); mem_free_set(&elformat.onfocus, get_attr_val(a, "onfocus", cp));
mem_free_set(&format.onmouseout, get_attr_val(a, "onmouseout", cp)); mem_free_set(&elformat.onmouseout, get_attr_val(a, "onmouseout", cp));
mem_free_set(&format.onblur, get_attr_val(a, "onblur", cp)); mem_free_set(&elformat.onblur, get_attr_val(a, "onblur", cp));
} }
void void
@ -692,15 +705,15 @@ init_html_parser_state(struct html_context *html_context,
{ {
html_stack_dup(html_context, type); html_stack_dup(html_context, type);
par_format.align = align; par_elformat.align = align;
if (type <= ELEMENT_IMMORTAL) { if (type <= ELEMENT_IMMORTAL) {
par_format.leftmargin = margin; par_elformat.leftmargin = margin;
par_format.rightmargin = margin; par_elformat.rightmargin = margin;
par_format.width = width; par_elformat.width = width;
par_format.list_level = 0; par_elformat.list_level = 0;
par_format.list_number = 0; par_elformat.list_number = 0;
par_format.dd_margin = 0; par_elformat.dd_margin = 0;
html_top->namelen = 0; html_top->namelen = 0;
} }
@ -783,34 +796,34 @@ init_html_parser(struct uri *uri, struct document_options *options,
if (!e) return NULL; if (!e) return NULL;
add_to_list(html_context->stack, e); add_to_list(html_context->stack, e);
format.style.attr = 0; elformat.style.attr = 0;
format.fontsize = 3; elformat.fontsize = 3;
format.link = format.target = format.image = NULL; elformat.link = elformat.target = elformat.image = NULL;
format.onclick = format.ondblclick = format.onmouseover = format.onhover elformat.onclick = elformat.ondblclick = elformat.onmouseover = elformat.onhover
= format.onfocus = format.onmouseout = format.onblur = NULL; = elformat.onfocus = elformat.onmouseout = elformat.onblur = NULL;
format.select = NULL; elformat.select = NULL;
format.form = NULL; elformat.form = NULL;
format.title = NULL; elformat.title = NULL;
format.style = options->default_style; elformat.style = options->default_style;
format.color.clink = options->default_color.link; elformat.color.clink = options->default_color.link;
format.color.vlink = options->default_color.vlink; elformat.color.vlink = options->default_color.vlink;
#ifdef CONFIG_BOOKMARKS #ifdef CONFIG_BOOKMARKS
format.color.bookmark_link = options->default_color.bookmark_link; elformat.color.bookmark_link = options->default_color.bookmark_link;
#endif #endif
format.color.image_link = options->default_color.image_link; elformat.color.image_link = options->default_color.image_link;
format.color.link_number = options->default_color.link_number; elformat.color.link_number = options->default_color.link_number;
par_format.align = ALIGN_LEFT; par_elformat.align = ALIGN_LEFT;
par_format.leftmargin = options->margin; par_elformat.leftmargin = options->margin;
par_format.rightmargin = options->margin; par_elformat.rightmargin = options->margin;
par_format.width = options->document_width; par_elformat.width = options->document_width;
par_format.list_level = par_format.list_number = 0; par_elformat.list_level = par_elformat.list_number = 0;
par_format.dd_margin = options->margin; par_elformat.dd_margin = options->margin;
par_format.flags = P_DISC; par_elformat.flags = P_DISC;
par_format.color.background = options->default_style.color.background; par_elformat.color.background = options->default_style.color.background;
html_top->invisible = 0; html_top->invisible = 0;
html_top->name = NULL; html_top->name = NULL;

View File

@ -211,6 +211,8 @@ void ln_break(struct html_context *html_context, int n);
int get_color(struct html_context *html_context, char *a, char *c, color_T *rgb); int get_color(struct html_context *html_context, char *a, char *c, color_T *rgb);
int get_color2(struct html_context *html_context, unsigned char *value_value, color_T *rgb);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -183,8 +183,8 @@ no_type_attr:
fc->default_value = stracpy(""); fc->default_value = stracpy("");
html_context->special_f(html_context, SP_CONTROL, fc); html_context->special_f(html_context, SP_CONTROL, fc);
format.form = fc; elformat.form = fc;
format.style.attr |= AT_BOLD; elformat.style.attr |= AT_BOLD;
} }
static void static void
@ -194,9 +194,9 @@ html_input_format(struct html_context *html_context, char *a,
put_chrs(html_context, " ", 1); put_chrs(html_context, " ", 1);
html_stack_dup(html_context, ELEMENT_KILLABLE); html_stack_dup(html_context, ELEMENT_KILLABLE);
html_focusable(html_context, a); html_focusable(html_context, a);
format.form = fc; elformat.form = fc;
mem_free_if(format.title); mem_free_if(elformat.title);
format.title = get_attr_val(a, "title", html_context->doc_cp); elformat.title = get_attr_val(a, "title", html_context->doc_cp);
switch (fc->type) { switch (fc->type) {
case FC_TEXT: case FC_TEXT:
case FC_PASSWORD: case FC_PASSWORD:
@ -204,42 +204,42 @@ html_input_format(struct html_context *html_context, char *a,
{ {
int i; int i;
format.style.attr |= AT_BOLD; elformat.style.attr |= AT_BOLD;
for (i = 0; i < fc->size; i++) for (i = 0; i < fc->size; i++)
put_chrs(html_context, "_", 1); put_chrs(html_context, "_", 1);
break; break;
} }
case FC_CHECKBOX: case FC_CHECKBOX:
format.style.attr |= AT_BOLD; elformat.style.attr |= AT_BOLD;
put_chrs(html_context, "[&nbsp;]", 8); put_chrs(html_context, "[&nbsp;]", 8);
break; break;
case FC_RADIO: case FC_RADIO:
format.style.attr |= AT_BOLD; elformat.style.attr |= AT_BOLD;
put_chrs(html_context, "(&nbsp;)", 8); put_chrs(html_context, "(&nbsp;)", 8);
break; break;
case FC_IMAGE: case FC_IMAGE:
{ {
char *al; char *al;
mem_free_set(&format.image, NULL); mem_free_set(&elformat.image, NULL);
al = get_url_val(a, "src", html_context->doc_cp); al = get_url_val(a, "src", html_context->doc_cp);
if (!al) if (!al)
al = get_url_val(a, "dynsrc", al = get_url_val(a, "dynsrc",
html_context->doc_cp); html_context->doc_cp);
if (al) { if (al) {
format.image = join_urls(html_context->base_href, al); elformat.image = join_urls(html_context->base_href, al);
mem_free(al); mem_free(al);
} }
format.style.attr |= AT_BOLD; elformat.style.attr |= AT_BOLD;
put_chrs(html_context, "[&nbsp;", 7); put_chrs(html_context, "[&nbsp;", 7);
format.style.attr |= AT_NO_ENTITIES; elformat.style.attr |= AT_NO_ENTITIES;
if (fc->alt) if (fc->alt)
put_chrs(html_context, fc->alt, strlen(fc->alt)); put_chrs(html_context, fc->alt, strlen(fc->alt));
else if (fc->name) else if (fc->name)
put_chrs(html_context, fc->name, strlen(fc->name)); put_chrs(html_context, fc->name, strlen(fc->name));
else else
put_chrs(html_context, "Submit", 6); put_chrs(html_context, "Submit", 6);
format.style.attr &= ~AT_NO_ENTITIES; elformat.style.attr &= ~AT_NO_ENTITIES;
put_chrs(html_context, "&nbsp;]", 7); put_chrs(html_context, "&nbsp;]", 7);
break; break;
@ -247,12 +247,12 @@ html_input_format(struct html_context *html_context, char *a,
case FC_SUBMIT: case FC_SUBMIT:
case FC_RESET: case FC_RESET:
case FC_BUTTON: case FC_BUTTON:
format.style.attr |= AT_BOLD; elformat.style.attr |= AT_BOLD;
put_chrs(html_context, "[&nbsp;", 7); put_chrs(html_context, "[&nbsp;", 7);
if (fc->default_value) { if (fc->default_value) {
format.style.attr |= AT_NO_ENTITIES; elformat.style.attr |= AT_NO_ENTITIES;
put_chrs(html_context, fc->default_value, strlen(fc->default_value)); put_chrs(html_context, fc->default_value, strlen(fc->default_value));
format.style.attr &= ~AT_NO_ENTITIES; elformat.style.attr &= ~AT_NO_ENTITIES;
} }
put_chrs(html_context, "&nbsp;]", 7); put_chrs(html_context, "&nbsp;]", 7);
break; break;
@ -495,8 +495,8 @@ end_parse:
menu_labels(fc->menu, "", labels); menu_labels(fc->menu, "", labels);
html_stack_dup(html_context, ELEMENT_KILLABLE); html_stack_dup(html_context, ELEMENT_KILLABLE);
format.form = fc; elformat.form = fc;
format.style.attr |= AT_BOLD; elformat.style.attr |= AT_BOLD;
put_chrs(html_context, "[&nbsp;", 7); put_chrs(html_context, "[&nbsp;", 7);
max_width = 0; max_width = 0;
@ -530,8 +530,8 @@ do_html_select_multiple(struct html_context *html_context, char *a,
if (!al) return; if (!al) return;
html_focusable(html_context, a); html_focusable(html_context, a);
html_top->type = ELEMENT_DONT_KILL; html_top->type = ELEMENT_DONT_KILL;
mem_free_set(&format.select, al); mem_free_set(&elformat.select, al);
format.select_disabled = has_attr(a, "disabled", html_context->doc_cp) elformat.select_disabled = has_attr(a, "disabled", html_context->doc_cp)
? FORM_MODE_DISABLED ? FORM_MODE_DISABLED
: FORM_MODE_NORMAL; : FORM_MODE_NORMAL;
} }
@ -554,7 +554,7 @@ html_option(struct html_context *html_context, char *a,
struct el_form_control *fc; struct el_form_control *fc;
char *val; char *val;
if (!format.select) return; if (!elformat.select) return;
val = get_attr_val(a, "value", html_context->doc_cp); val = get_attr_val(a, "value", html_context->doc_cp);
if (!val) { if (!val) {
@ -608,17 +608,17 @@ end_parse:
} }
fc->id = get_attr_val(a, "id", html_context->doc_cp); fc->id = get_attr_val(a, "id", html_context->doc_cp);
fc->name = null_or_stracpy(format.select); fc->name = null_or_stracpy(elformat.select);
fc->default_value = val; fc->default_value = val;
fc->default_state = has_attr(a, "selected", html_context->doc_cp); fc->default_state = has_attr(a, "selected", html_context->doc_cp);
fc->mode = has_attr(a, "disabled", html_context->doc_cp) fc->mode = has_attr(a, "disabled", html_context->doc_cp)
? FORM_MODE_DISABLED ? FORM_MODE_DISABLED
: format.select_disabled; : elformat.select_disabled;
put_chrs(html_context, " ", 1); put_chrs(html_context, " ", 1);
html_stack_dup(html_context, ELEMENT_KILLABLE); html_stack_dup(html_context, ELEMENT_KILLABLE);
format.form = fc; elformat.form = fc;
format.style.attr |= AT_BOLD; elformat.style.attr |= AT_BOLD;
put_chrs(html_context, "[ ]", 3); put_chrs(html_context, "[ ]", 3);
pop_html_element(html_context); pop_html_element(html_context);
put_chrs(html_context, " ", 1); put_chrs(html_context, " ", 1);
@ -717,8 +717,8 @@ pp:
else put_chrs(html_context, " ", 1); else put_chrs(html_context, " ", 1);
html_stack_dup(html_context, ELEMENT_KILLABLE); html_stack_dup(html_context, ELEMENT_KILLABLE);
format.form = fc; elformat.form = fc;
format.style.attr |= AT_BOLD; elformat.style.attr |= AT_BOLD;
for (i = 0; i < rows; i++) { for (i = 0; i < rows; i++) {
int j; int j;

View File

@ -52,28 +52,28 @@ void
html_bold(struct html_context *html_context, char *a, html_bold(struct html_context *html_context, char *a,
char *xxx3, char *xxx4, char **xxx5) char *xxx3, char *xxx4, char **xxx5)
{ {
format.style.attr |= AT_BOLD; elformat.style.attr |= AT_BOLD;
} }
void void
html_italic(struct html_context *html_context, char *a, html_italic(struct html_context *html_context, char *a,
char *xxx3, char *xxx4, char **xxx5) char *xxx3, char *xxx4, char **xxx5)
{ {
format.style.attr |= AT_ITALIC; elformat.style.attr |= AT_ITALIC;
} }
void void
html_underline(struct html_context *html_context, char *a, html_underline(struct html_context *html_context, char *a,
char *xxx3, char *xxx4, char **xxx5) char *xxx3, char *xxx4, char **xxx5)
{ {
format.style.attr |= AT_UNDERLINE; elformat.style.attr |= AT_UNDERLINE;
} }
void void
html_fixed(struct html_context *html_context, char *a, html_fixed(struct html_context *html_context, char *a,
char *xxx3, char *xxx4, char **xxx5) char *xxx3, char *xxx4, char **xxx5)
{ {
format.style.attr |= AT_FIXED; elformat.style.attr |= AT_FIXED;
} }
void void
@ -152,25 +152,25 @@ html_font(struct html_context *html_context, char *a,
s = strtoul(nn, (char **) &end, 10); s = strtoul(nn, (char **) &end, 10);
if (!errno && *nn && !*end) { if (!errno && *nn && !*end) {
if (s > 7) s = 7; if (s > 7) s = 7;
if (!p) format.fontsize = s; if (!p) elformat.fontsize = s;
else format.fontsize += p * s; else elformat.fontsize += p * s;
if (format.fontsize < 1) format.fontsize = 1; if (elformat.fontsize < 1) elformat.fontsize = 1;
else if (format.fontsize > 7) format.fontsize = 7; else if (elformat.fontsize > 7) elformat.fontsize = 7;
} }
mem_free(al); mem_free(al);
} }
get_color(html_context, a, "color", &format.style.color.foreground); get_color(html_context, a, "color", &elformat.style.color.foreground);
} }
void void
html_body(struct html_context *html_context, char *a, html_body(struct html_context *html_context, char *a,
char *xxx3, char *xxx4, char **xxx5) char *xxx3, char *xxx4, char **xxx5)
{ {
get_color(html_context, a, "text", &format.style.color.foreground); get_color(html_context, a, "text", &elformat.style.color.foreground);
get_color(html_context, a, "link", &format.color.clink); get_color(html_context, a, "link", &elformat.color.clink);
get_color(html_context, a, "vlink", &format.color.vlink); get_color(html_context, a, "vlink", &elformat.color.vlink);
if (get_bgcolor(html_context, a, &format.style.color.background) != -1) if (get_bgcolor(html_context, a, &elformat.style.color.background) != -1)
html_context->was_body_background = 1; html_context->was_body_background = 1;
html_context->was_body = 1; /* this will be used by "meta inside body" */ html_context->was_body = 1; /* this will be used by "meta inside body" */
@ -188,17 +188,17 @@ html_apply_canvas_bgcolor(struct html_context *html_context)
&html_context->stack); &html_context->stack);
#endif #endif
if (par_format.color.background != format.style.color.background) { if (par_elformat.color.background != elformat.style.color.background) {
/* Modify the root HTML element - format_html_part() will take /* Modify the root HTML element - format_html_part() will take
* this from there. */ * this from there. */
struct html_element *e = html_bottom; struct html_element *e = html_bottom;
html_context->was_body_background = 1; html_context->was_body_background = 1;
e->parattr.color.background = e->attr.style.color.background = par_format.color.background = format.style.color.background; e->parattr.color.background = e->attr.style.color.background = par_elformat.color.background = elformat.style.color.background;
} }
if (html_context->has_link_lines if (html_context->has_link_lines
&& par_format.color.background != html_context->options->default_style.color.background && par_elformat.color.background != html_context->options->default_style.color.background
&& !search_html_stack(html_context, "BODY")) { && !search_html_stack(html_context, "BODY")) {
html_context->special_f(html_context, SP_COLOR_LINK_LINES); html_context->special_f(html_context, SP_COLOR_LINK_LINES);
} }
@ -417,8 +417,8 @@ html_html(struct html_context *html_context, char *a,
* this from there. */ * this from there. */
struct html_element *e = html_bottom; struct html_element *e = html_bottom;
if (par_format.color.background != format.style.color.background) if (par_elformat.color.background != elformat.style.color.background)
e->parattr.color.background = e->attr.style.color.background = par_format.color.background = format.style.color.background; e->parattr.color.background = e->attr.style.color.background = par_elformat.color.background = elformat.style.color.background;
} }
void void
@ -473,9 +473,9 @@ void
html_center(struct html_context *html_context, char *a, html_center(struct html_context *html_context, char *a,
char *xxx3, char *xxx4, char **xxx5) char *xxx3, char *xxx4, char **xxx5)
{ {
par_format.align = ALIGN_CENTER; par_elformat.align = ALIGN_CENTER;
if (!html_context->table_level) if (!html_context->table_level)
par_format.leftmargin = par_format.rightmargin = 0; par_elformat.leftmargin = par_elformat.rightmargin = 0;
} }
void void
@ -485,13 +485,13 @@ html_linebrk(struct html_context *html_context, char *a,
char *al = get_attr_val(a, "align", html_context->doc_cp); char *al = get_attr_val(a, "align", html_context->doc_cp);
if (al) { if (al) {
if (!c_strcasecmp(al, "left")) par_format.align = ALIGN_LEFT; if (!c_strcasecmp(al, "left")) par_elformat.align = ALIGN_LEFT;
else if (!c_strcasecmp(al, "right")) par_format.align = ALIGN_RIGHT; else if (!c_strcasecmp(al, "right")) par_elformat.align = ALIGN_RIGHT;
else if (!c_strcasecmp(al, "center")) { else if (!c_strcasecmp(al, "center")) {
par_format.align = ALIGN_CENTER; par_elformat.align = ALIGN_CENTER;
if (!html_context->table_level) if (!html_context->table_level)
par_format.leftmargin = par_format.rightmargin = 0; par_elformat.leftmargin = par_elformat.rightmargin = 0;
} else if (!c_strcasecmp(al, "justify")) par_format.align = ALIGN_JUSTIFY; } else if (!c_strcasecmp(al, "justify")) par_elformat.align = ALIGN_JUSTIFY;
mem_free(al); mem_free(al);
} }
} }
@ -511,9 +511,9 @@ void
html_p(struct html_context *html_context, char *a, html_p(struct html_context *html_context, char *a,
char *html, char *eof, char **end) char *html, char *eof, char **end)
{ {
int_lower_bound(&par_format.leftmargin, html_context->margin); int_lower_bound(&par_elformat.leftmargin, html_context->margin);
int_lower_bound(&par_format.rightmargin, html_context->margin); int_lower_bound(&par_elformat.rightmargin, html_context->margin);
/*par_format.align = ALIGN_LEFT;*/ /*par_elformat.align = ALIGN_LEFT;*/
html_linebrk(html_context, a, html, eof, end); html_linebrk(html_context, a, html, eof, end);
} }
@ -521,28 +521,28 @@ void
html_address(struct html_context *html_context, char *a, html_address(struct html_context *html_context, char *a,
char *xxx3, char *xxx4, char **xxx5) char *xxx3, char *xxx4, char **xxx5)
{ {
par_format.leftmargin++; par_elformat.leftmargin++;
par_format.align = ALIGN_LEFT; par_elformat.align = ALIGN_LEFT;
} }
void void
html_blockquote(struct html_context *html_context, char *a, html_blockquote(struct html_context *html_context, char *a,
char *xxx3, char *xxx4, char **xxx5) char *xxx3, char *xxx4, char **xxx5)
{ {
par_format.align = ALIGN_LEFT; par_elformat.align = ALIGN_LEFT;
if (par_format.blockquote_level == 0) { if (par_elformat.blockquote_level == 0) {
par_format.orig_leftmargin = par_format.leftmargin; par_elformat.orig_leftmargin = par_elformat.leftmargin;
par_format.blockquote_level++; par_elformat.blockquote_level++;
} }
par_format.blockquote_level++; par_elformat.blockquote_level++;
} }
void void
html_blockquote_close(struct html_context *html_context, char *a, html_blockquote_close(struct html_context *html_context, char *a,
char *xxx3, char *xxx4, char **xxx5) char *xxx3, char *xxx4, char **xxx5)
{ {
if (par_format.blockquote_level == 2) par_format.blockquote_level--; if (par_elformat.blockquote_level == 2) par_elformat.blockquote_level--;
if (par_format.blockquote_level > 0) par_format.blockquote_level--; if (par_elformat.blockquote_level > 0) par_elformat.blockquote_level--;
} }
void void
@ -550,26 +550,26 @@ html_h(int h, char *a,
enum format_align default_align, struct html_context *html_context, enum format_align default_align, struct html_context *html_context,
char *html, char *eof, char **end) char *html, char *eof, char **end)
{ {
if (!par_format.align) par_format.align = default_align; if (!par_elformat.align) par_elformat.align = default_align;
html_linebrk(html_context, a, html, eof, end); html_linebrk(html_context, a, html, eof, end);
h -= 2; h -= 2;
if (h < 0) h = 0; if (h < 0) h = 0;
switch (par_format.align) { switch (par_elformat.align) {
case ALIGN_LEFT: case ALIGN_LEFT:
par_format.leftmargin = h * 2; par_elformat.leftmargin = h * 2;
par_format.rightmargin = 0; par_elformat.rightmargin = 0;
break; break;
case ALIGN_RIGHT: case ALIGN_RIGHT:
par_format.leftmargin = 0; par_elformat.leftmargin = 0;
par_format.rightmargin = h * 2; par_elformat.rightmargin = h * 2;
break; break;
case ALIGN_CENTER: case ALIGN_CENTER:
par_format.leftmargin = par_format.rightmargin = 0; par_elformat.leftmargin = par_elformat.rightmargin = 0;
break; break;
case ALIGN_JUSTIFY: case ALIGN_JUSTIFY:
par_format.leftmargin = par_format.rightmargin = h * 2; par_elformat.leftmargin = par_elformat.rightmargin = h * 2;
break; break;
} }
} }
@ -578,7 +578,7 @@ void
html_h1(struct html_context *html_context, char *a, html_h1(struct html_context *html_context, char *a,
char *html, char *eof, char **end) char *html, char *eof, char **end)
{ {
format.style.attr |= AT_BOLD; elformat.style.attr |= AT_BOLD;
html_h(1, a, ALIGN_CENTER, html_context, html, eof, end); html_h(1, a, ALIGN_CENTER, html_context, html, eof, end);
} }
@ -621,9 +621,9 @@ void
html_pre(struct html_context *html_context, char *a, html_pre(struct html_context *html_context, char *a,
char *xxx3, char *xxx4, char **xxx5) char *xxx3, char *xxx4, char **xxx5)
{ {
format.style.attr |= AT_PREFORMATTED; elformat.style.attr |= AT_PREFORMATTED;
par_format.leftmargin = (par_format.leftmargin > 1); par_elformat.leftmargin = (par_elformat.leftmargin > 1);
par_format.rightmargin = 0; par_elformat.rightmargin = 0;
} }
void void
@ -645,22 +645,22 @@ void
html_hr(struct html_context *html_context, char *a, html_hr(struct html_context *html_context, char *a,
char *html, char *eof, char **end) char *html, char *eof, char **end)
{ {
int i/* = par_format.width - 10*/; int i/* = par_elformat.width - 10*/;
char r = BORDER_DHLINE; char r = BORDER_DHLINE;
int q = get_num(a, "size", html_context->doc_cp); int q = get_num(a, "size", html_context->doc_cp);
if (q >= 0 && q < 2) r = BORDER_SHLINE; if (q >= 0 && q < 2) r = BORDER_SHLINE;
html_stack_dup(html_context, ELEMENT_KILLABLE); html_stack_dup(html_context, ELEMENT_KILLABLE);
par_format.align = ALIGN_CENTER; par_elformat.align = ALIGN_CENTER;
mem_free_set(&format.link, NULL); mem_free_set(&elformat.link, NULL);
format.form = NULL; elformat.form = NULL;
html_linebrk(html_context, a, html, eof, end); html_linebrk(html_context, a, html, eof, end);
if (par_format.align == ALIGN_JUSTIFY) par_format.align = ALIGN_CENTER; if (par_elformat.align == ALIGN_JUSTIFY) par_elformat.align = ALIGN_CENTER;
par_format.leftmargin = par_format.rightmargin = html_context->margin; par_elformat.leftmargin = par_elformat.rightmargin = html_context->margin;
i = get_width(a, "width", 1, html_context); i = get_width(a, "width", 1, html_context);
if (i == -1) i = get_html_max_width(); if (i == -1) i = get_html_max_width();
format.style.attr = AT_GRAPHICS; elformat.style.attr = AT_GRAPHICS;
html_context->special_f(html_context, SP_NOWRAP, 1); html_context->special_f(html_context, SP_NOWRAP, 1);
while (i-- > 0) { while (i-- > 0) {
put_chrs(html_context, &r, 1); put_chrs(html_context, &r, 1);
@ -682,10 +682,10 @@ html_table(struct html_context *html_context, char *attr,
return; return;
} }
par_format.leftmargin = par_format.rightmargin = html_context->margin; par_elformat.leftmargin = par_elformat.rightmargin = html_context->margin;
par_format.align = ALIGN_LEFT; par_elformat.align = ALIGN_LEFT;
html_linebrk(html_context, attr, html, eof, end); html_linebrk(html_context, attr, html, eof, end);
format.style.attr = 0; elformat.style.attr = 0;
} }
void void
@ -708,7 +708,7 @@ html_th(struct html_context *html_context, char *a,
/*html_linebrk(html_context, a, html, eof, end);*/ /*html_linebrk(html_context, a, html, eof, end);*/
kill_html_stack_until(html_context, 1, kill_html_stack_until(html_context, 1,
"TD", "TH", "", "TR", "TABLE", NULL); "TD", "TH", "", "TR", "TABLE", NULL);
format.style.attr |= AT_BOLD; elformat.style.attr |= AT_BOLD;
put_chrs(html_context, " ", 1); put_chrs(html_context, " ", 1);
} }
@ -719,7 +719,7 @@ html_td(struct html_context *html_context, char *a,
/*html_linebrk(html_context, a, html, eof, end);*/ /*html_linebrk(html_context, a, html, eof, end);*/
kill_html_stack_until(html_context, 1, kill_html_stack_until(html_context, 1,
"TD", "TH", "", "TR", "TABLE", NULL); "TD", "TH", "", "TR", "TABLE", NULL);
format.style.attr &= ~AT_BOLD; elformat.style.attr &= ~AT_BOLD;
put_chrs(html_context, " ", 1); put_chrs(html_context, " ", 1);
} }
@ -754,25 +754,25 @@ html_ul(struct html_context *html_context, char *a,
char *al; char *al;
/* dump_html_stack(html_context); */ /* dump_html_stack(html_context); */
par_format.list_level++; par_elformat.list_level++;
par_format.list_number = 0; par_elformat.list_number = 0;
par_format.flags = P_DISC; par_elformat.flags = P_DISC;
al = get_attr_val(a, "type", html_context->doc_cp); al = get_attr_val(a, "type", html_context->doc_cp);
if (al) { if (al) {
if (!c_strcasecmp(al, "disc")) if (!c_strcasecmp(al, "disc"))
par_format.flags = P_DISC; par_elformat.flags = P_DISC;
else if (!c_strcasecmp(al, "circle")) else if (!c_strcasecmp(al, "circle"))
par_format.flags = P_O; par_elformat.flags = P_O;
else if (!c_strcasecmp(al, "square")) else if (!c_strcasecmp(al, "square"))
par_format.flags = P_SQUARE; par_elformat.flags = P_SQUARE;
mem_free(al); mem_free(al);
} }
par_format.leftmargin += 2 + (par_format.list_level > 1); par_elformat.leftmargin += 2 + (par_elformat.list_level > 1);
if (!html_context->table_level) if (!html_context->table_level)
int_upper_bound(&par_format.leftmargin, par_format.width / 2); int_upper_bound(&par_elformat.leftmargin, par_elformat.width / 2);
par_format.align = ALIGN_LEFT; par_elformat.align = ALIGN_LEFT;
html_top->type = ELEMENT_DONT_KILL; html_top->type = ELEMENT_DONT_KILL;
} }
@ -783,31 +783,31 @@ html_ol(struct html_context *html_context, char *a,
char *al; char *al;
int st; int st;
par_format.list_level++; par_elformat.list_level++;
st = get_num(a, "start", html_context->doc_cp); st = get_num(a, "start", html_context->doc_cp);
if (st == -1) st = 1; if (st == -1) st = 1;
par_format.list_number = st; par_elformat.list_number = st;
par_format.flags = P_NUMBER; par_elformat.flags = P_NUMBER;
al = get_attr_val(a, "type", html_context->doc_cp); al = get_attr_val(a, "type", html_context->doc_cp);
if (al) { if (al) {
if (*al && !al[1]) { if (*al && !al[1]) {
if (*al == '1') par_format.flags = P_NUMBER; if (*al == '1') par_elformat.flags = P_NUMBER;
else if (*al == 'a') par_format.flags = P_alpha; else if (*al == 'a') par_elformat.flags = P_alpha;
else if (*al == 'A') par_format.flags = P_ALPHA; else if (*al == 'A') par_elformat.flags = P_ALPHA;
else if (*al == 'r') par_format.flags = P_roman; else if (*al == 'r') par_elformat.flags = P_roman;
else if (*al == 'R') par_format.flags = P_ROMAN; else if (*al == 'R') par_elformat.flags = P_ROMAN;
else if (*al == 'i') par_format.flags = P_roman; else if (*al == 'i') par_elformat.flags = P_roman;
else if (*al == 'I') par_format.flags = P_ROMAN; else if (*al == 'I') par_elformat.flags = P_ROMAN;
} }
mem_free(al); mem_free(al);
} }
par_format.leftmargin += (par_format.list_level > 1); par_elformat.leftmargin += (par_elformat.list_level > 1);
if (!html_context->table_level) if (!html_context->table_level)
int_upper_bound(&par_format.leftmargin, par_format.width / 2); int_upper_bound(&par_elformat.leftmargin, par_elformat.width / 2);
par_format.align = ALIGN_LEFT; par_elformat.align = ALIGN_LEFT;
html_top->type = ELEMENT_DONT_KILL; html_top->type = ELEMENT_DONT_KILL;
} }
@ -866,7 +866,7 @@ void
html_li(struct html_context *html_context, char *a, html_li(struct html_context *html_context, char *a,
char *xxx3, char *xxx4, char **xxx5) char *xxx3, char *xxx4, char **xxx5)
{ {
int t = par_format.flags & P_LISTMASK; int t = par_elformat.flags & P_LISTMASK;
/* When handling the code <li><li> @was_li will be 1 and it means we /* When handling the code <li><li> @was_li will be 1 and it means we
* have to insert a line break since no list item content has done it * have to insert a line break since no list item content has done it
@ -880,7 +880,7 @@ html_li(struct html_context *html_context, char *a,
"", "UL", "OL", NULL);*/ "", "UL", "OL", NULL);*/
if (t == P_NO_BULLET) { if (t == P_NO_BULLET) {
/* Print nothing. */ /* Print nothing. */
} else if (!par_format.list_number) { } else if (!par_elformat.list_number) {
if (t == P_O) /* Print U+25E6 WHITE BULLET. */ if (t == P_O) /* Print U+25E6 WHITE BULLET. */
put_chrs(html_context, "&#9702;", 7); put_chrs(html_context, "&#9702;", 7);
else if (t == P_SQUARE) /* Print U+25AA BLACK SMALL SQUARE. */ else if (t == P_SQUARE) /* Print U+25AA BLACK SMALL SQUARE. */
@ -888,33 +888,33 @@ html_li(struct html_context *html_context, char *a,
else /* Print U+2022 BULLET. */ else /* Print U+2022 BULLET. */
put_chrs(html_context, "&#8226;", 7); put_chrs(html_context, "&#8226;", 7);
put_chrs(html_context, "&nbsp;", 6); put_chrs(html_context, "&nbsp;", 6);
par_format.leftmargin += 2; par_elformat.leftmargin += 2;
par_format.align = ALIGN_LEFT; par_elformat.align = ALIGN_LEFT;
} else { } else {
unsigned char c = 0; unsigned char c = 0;
int nlen; int nlen;
int t = par_format.flags & P_LISTMASK; int t = par_elformat.flags & P_LISTMASK;
int s = get_num(a, "value", html_context->doc_cp); int s = get_num(a, "value", html_context->doc_cp);
struct string n; struct string n;
if (!init_string(&n)) return; if (!init_string(&n)) return;
if (s != -1) par_format.list_number = s; if (s != -1) par_elformat.list_number = s;
if (t == P_ALPHA || t == P_alpha) { if (t == P_ALPHA || t == P_alpha) {
unsigned char n0; unsigned char n0;
put_chrs(html_context, "&nbsp;", 6); put_chrs(html_context, "&nbsp;", 6);
c = 1; c = 1;
n0 = par_format.list_number n0 = par_elformat.list_number
? (par_format.list_number - 1) % 26 ? (par_elformat.list_number - 1) % 26
+ (t == P_ALPHA ? 'A' : 'a') + (t == P_ALPHA ? 'A' : 'a')
: 0; : 0;
if (n0) add_char_to_string(&n, n0); if (n0) add_char_to_string(&n, n0);
} else if (t == P_ROMAN || t == P_roman) { } else if (t == P_ROMAN || t == P_roman) {
roman(&n, par_format.list_number); roman(&n, par_elformat.list_number);
if (t == P_ROMAN) { if (t == P_ROMAN) {
char *x; char *x;
@ -923,20 +923,20 @@ html_li(struct html_context *html_context, char *a,
} else { } else {
char n0[64]; char n0[64];
if (par_format.list_number < 10) { if (par_elformat.list_number < 10) {
put_chrs(html_context, "&nbsp;", 6); put_chrs(html_context, "&nbsp;", 6);
c = 1; c = 1;
} }
ulongcat(n0, NULL, par_format.list_number, (sizeof(n) - 1), 0); ulongcat(n0, NULL, par_elformat.list_number, (sizeof(n) - 1), 0);
add_to_string(&n, n0); add_to_string(&n, n0);
} }
nlen = n.length; nlen = n.length;
put_chrs(html_context, n.source, nlen); put_chrs(html_context, n.source, nlen);
put_chrs(html_context, ".&nbsp;", 7); put_chrs(html_context, ".&nbsp;", 7);
par_format.leftmargin += nlen + c + 2; par_elformat.leftmargin += nlen + c + 2;
par_format.align = ALIGN_LEFT; par_elformat.align = ALIGN_LEFT;
done_string(&n); done_string(&n);
{ {
@ -944,10 +944,10 @@ html_li(struct html_context *html_context, char *a,
element = search_html_stack(html_context, "ol"); element = search_html_stack(html_context, "ol");
if (element) if (element)
element->parattr.list_number = par_format.list_number + 1; element->parattr.list_number = par_elformat.list_number + 1;
} }
par_format.list_number = 0; par_elformat.list_number = 0;
} }
html_context->putsp = HTML_SPACE_SUPPRESS; html_context->putsp = HTML_SPACE_SUPPRESS;
@ -959,16 +959,16 @@ void
html_dl(struct html_context *html_context, char *a, html_dl(struct html_context *html_context, char *a,
char *xxx3, char *xxx4, char **xxx5) char *xxx3, char *xxx4, char **xxx5)
{ {
par_format.flags &= ~P_COMPACT; par_elformat.flags &= ~P_COMPACT;
if (has_attr(a, "compact", html_context->doc_cp)) if (has_attr(a, "compact", html_context->doc_cp))
par_format.flags |= P_COMPACT; par_elformat.flags |= P_COMPACT;
if (par_format.list_level) par_format.leftmargin += 5; if (par_elformat.list_level) par_elformat.leftmargin += 5;
par_format.list_level++; par_elformat.list_level++;
par_format.list_number = 0; par_elformat.list_number = 0;
par_format.align = ALIGN_LEFT; par_elformat.align = ALIGN_LEFT;
par_format.dd_margin = par_format.leftmargin; par_elformat.dd_margin = par_elformat.leftmargin;
html_top->type = ELEMENT_DONT_KILL; html_top->type = ELEMENT_DONT_KILL;
if (!(par_format.flags & P_COMPACT)) { if (!(par_elformat.flags & P_COMPACT)) {
ln_break(html_context, 2); ln_break(html_context, 2);
html_top->linebreak = 2; html_top->linebreak = 2;
} }
@ -979,9 +979,9 @@ html_dt(struct html_context *html_context, char *a,
char *xxx3, char *xxx4, char **xxx5) char *xxx3, char *xxx4, char **xxx5)
{ {
kill_html_stack_until(html_context, 0, "", "DL", NULL); kill_html_stack_until(html_context, 0, "", "DL", NULL);
par_format.align = ALIGN_LEFT; par_elformat.align = ALIGN_LEFT;
par_format.leftmargin = par_format.dd_margin; par_elformat.leftmargin = par_elformat.dd_margin;
if (!(par_format.flags & P_COMPACT) if (!(par_elformat.flags & P_COMPACT)
&& !has_attr(a, "compact", html_context->doc_cp)) && !has_attr(a, "compact", html_context->doc_cp))
ln_break(html_context, 2); ln_break(html_context, 2);
} }
@ -992,13 +992,13 @@ html_dd(struct html_context *html_context, char *a,
{ {
kill_html_stack_until(html_context, 0, "", "DL", NULL); kill_html_stack_until(html_context, 0, "", "DL", NULL);
par_format.leftmargin = par_format.dd_margin + 3; par_elformat.leftmargin = par_elformat.dd_margin + 3;
if (!html_context->table_level) { if (!html_context->table_level) {
par_format.leftmargin += 5; par_elformat.leftmargin += 5;
int_upper_bound(&par_format.leftmargin, par_format.width / 2); int_upper_bound(&par_elformat.leftmargin, par_elformat.width / 2);
} }
par_format.align = ALIGN_LEFT; par_elformat.align = ALIGN_LEFT;
} }

View File

@ -51,7 +51,7 @@ html_a(struct html_context *html_context, char *a,
if (href) { if (href) {
char *target; char *target;
mem_free_set(&format.link, mem_free_set(&elformat.link,
join_urls(html_context->base_href, join_urls(html_context->base_href,
trim_chars(href, ' ', 0))); trim_chars(href, ' ', 0)));
@ -59,33 +59,33 @@ html_a(struct html_context *html_context, char *a,
target = get_target(html_context->options, a); target = get_target(html_context->options, a);
if (target) { if (target) {
mem_free_set(&format.target, target); mem_free_set(&elformat.target, target);
} else { } else {
mem_free_set(&format.target, stracpy(html_context->base_target)); mem_free_set(&elformat.target, stracpy(html_context->base_target));
} }
if (0) { if (0) {
; /* Shut up compiler */ ; /* Shut up compiler */
#ifdef CONFIG_GLOBHIST #ifdef CONFIG_GLOBHIST
} else if (get_global_history_item(format.link)) { } else if (get_global_history_item(elformat.link)) {
format.style.color.foreground = format.color.vlink; elformat.style.color.foreground = elformat.color.vlink;
html_top->pseudo_class &= ~ELEMENT_LINK; html_top->pseudo_class &= ~ELEMENT_LINK;
html_top->pseudo_class |= ELEMENT_VISITED; html_top->pseudo_class |= ELEMENT_VISITED;
#endif #endif
#ifdef CONFIG_BOOKMARKS #ifdef CONFIG_BOOKMARKS
} else if (get_bookmark(format.link)) { } else if (get_bookmark(elformat.link)) {
format.style.color.foreground = format.color.bookmark_link; elformat.style.color.foreground = elformat.color.bookmark_link;
html_top->pseudo_class &= ~ELEMENT_VISITED; html_top->pseudo_class &= ~ELEMENT_VISITED;
/* XXX: Really set ELEMENT_LINK? --pasky */ /* XXX: Really set ELEMENT_LINK? --pasky */
html_top->pseudo_class |= ELEMENT_LINK; html_top->pseudo_class |= ELEMENT_LINK;
#endif #endif
} else { } else {
format.style.color.foreground = format.color.clink; elformat.style.color.foreground = elformat.color.clink;
html_top->pseudo_class &= ~ELEMENT_VISITED; html_top->pseudo_class &= ~ELEMENT_VISITED;
html_top->pseudo_class |= ELEMENT_LINK; html_top->pseudo_class |= ELEMENT_LINK;
} }
mem_free_set(&format.title, mem_free_set(&elformat.title,
get_attr_val(a, "title", html_context->doc_cp)); get_attr_val(a, "title", html_context->doc_cp));
html_focusable(html_context, a); html_focusable(html_context, a);
@ -201,13 +201,13 @@ put_image_label(char *a, char *label,
* extension to the standard. After all, it makes sense. */ * extension to the standard. After all, it makes sense. */
html_focusable(html_context, a); html_focusable(html_context, a);
saved_foreground = format.style.color.foreground; saved_foreground = elformat.style.color.foreground;
saved_attr = format.style.attr; saved_attr = elformat.style.attr;
format.style.color.foreground = format.color.image_link; elformat.style.color.foreground = elformat.color.image_link;
format.style.attr |= AT_NO_ENTITIES; elformat.style.attr |= AT_NO_ENTITIES;
put_chrs(html_context, label, strlen(label)); put_chrs(html_context, label, strlen(label));
format.style.color.foreground = saved_foreground; elformat.style.color.foreground = saved_foreground;
format.style.attr = saved_attr; elformat.style.attr = saved_attr;
} }
static void static void
@ -242,13 +242,13 @@ html_img_do(char *a, char *object_src,
if (!map_url) return; if (!map_url) return;
html_stack_dup(html_context, ELEMENT_KILLABLE); html_stack_dup(html_context, ELEMENT_KILLABLE);
mem_free_set(&format.link, map_url); mem_free_set(&elformat.link, map_url);
format.form = NULL; elformat.form = NULL;
format.style.attr |= AT_BOLD; elformat.style.attr |= AT_BOLD;
usemap = 1; usemap = 1;
} }
ismap = format.link ismap = elformat.link
&& has_attr(a, "ismap", html_context->doc_cp) && has_attr(a, "ismap", html_context->doc_cp)
&& !usemap; && !usemap;
@ -274,7 +274,7 @@ html_img_do(char *a, char *object_src,
/* Do we want to display images with no alt/title and with no /* Do we want to display images with no alt/title and with no
* link on them ? * link on them ?
* If not, just exit now. */ * If not, just exit now. */
if (!options->images && !format.link) { if (!options->images && !elformat.link) {
mem_free_if(src); mem_free_if(src);
if (usemap) pop_html_element(html_context); if (usemap) pop_html_element(html_context);
return; return;
@ -304,8 +304,8 @@ html_img_do(char *a, char *object_src,
mem_free_set(&label, stracpy("IMG")); mem_free_set(&label, stracpy("IMG"));
} }
mem_free_set(&format.image, NULL); mem_free_set(&elformat.image, NULL);
mem_free_set(&format.title, NULL); mem_free_set(&elformat.title, NULL);
if (label) { if (label) {
int img_link_tag = options->image_link.tagging; int img_link_tag = options->image_link.tagging;
@ -323,25 +323,25 @@ html_img_do(char *a, char *object_src,
} else { } else {
if (src) { if (src) {
format.image = join_urls(html_context->base_href, src); elformat.image = join_urls(html_context->base_href, src);
} }
format.title = get_attr_val(a, "title", html_context->doc_cp); elformat.title = get_attr_val(a, "title", html_context->doc_cp);
if (ismap) { if (ismap) {
char *new_link; char *new_link;
html_stack_dup(html_context, ELEMENT_KILLABLE); html_stack_dup(html_context, ELEMENT_KILLABLE);
new_link = straconcat(format.link, "?0,0", (char *) NULL); new_link = straconcat(elformat.link, "?0,0", (char *) NULL);
if (new_link) if (new_link)
mem_free_set(&format.link, new_link); mem_free_set(&elformat.link, new_link);
} }
put_image_label(a, label, html_context); put_image_label(a, label, html_context);
if (ismap) pop_html_element(html_context); if (ismap) pop_html_element(html_context);
mem_free_set(&format.image, NULL); mem_free_set(&elformat.image, NULL);
mem_free_set(&format.title, NULL); mem_free_set(&elformat.title, NULL);
} }
mem_free(label); mem_free(label);
@ -399,18 +399,18 @@ put_link_line(char *prefix, char *linkname,
html_context->has_link_lines = 1; html_context->has_link_lines = 1;
html_stack_dup(html_context, ELEMENT_KILLABLE); html_stack_dup(html_context, ELEMENT_KILLABLE);
ln_break(html_context, 1); ln_break(html_context, 1);
mem_free_set(&format.link, NULL); mem_free_set(&elformat.link, NULL);
mem_free_set(&format.target, NULL); mem_free_set(&elformat.target, NULL);
mem_free_set(&format.title, NULL); mem_free_set(&elformat.title, NULL);
format.form = NULL; elformat.form = NULL;
put_chrs(html_context, prefix, strlen(prefix)); put_chrs(html_context, prefix, strlen(prefix));
format.link = join_urls(html_context->base_href, link); elformat.link = join_urls(html_context->base_href, link);
format.target = stracpy(target); elformat.target = stracpy(target);
format.style.color.foreground = format.color.clink; elformat.style.color.foreground = elformat.color.clink;
/* linkname typically comes from get_attr_val, which /* linkname typically comes from get_attr_val, which
* has already expanded character entity references. * has already expanded character entity references.
* Tell put_chrs not to expand them again. */ * Tell put_chrs not to expand them again. */
format.style.attr |= AT_NO_ENTITIES; elformat.style.attr |= AT_NO_ENTITIES;
put_chrs(html_context, linkname, strlen(linkname)); put_chrs(html_context, linkname, strlen(linkname));
ln_break(html_context, 1); ln_break(html_context, 1);
pop_html_element(html_context); pop_html_element(html_context);

View File

@ -255,6 +255,28 @@ get_num(char *a, char *name, int cp)
char *al = get_attr_val(a, name, cp); char *al = get_attr_val(a, name, cp);
int result = -1; int result = -1;
if (al) {
result = get_num2(al);
// char *end;
// long num;
// errno = 0;
// num = strtol(al, (char **) &end, 10);
// if (!errno && *al && !*end && num >= 0 && num <= INT_MAX)
// result = (int) num;
mem_free(al);
}
return result;
}
int
get_num2(char *al)
{
int result = -1;
if (al) { if (al) {
char *end; char *end;
long num; long num;
@ -263,8 +285,6 @@ get_num(char *a, char *name, int cp)
num = strtol(al, (char **) &end, 10); num = strtol(al, (char **) &end, 10);
if (!errno && *al && !*end && num >= 0 && num <= INT_MAX) if (!errno && *al && !*end && num >= 0 && num <= INT_MAX)
result = (int) num; result = (int) num;
mem_free(al);
} }
return result; return result;
@ -279,6 +299,15 @@ get_width(char *a, char *name, int limited,
struct html_context *html_context) struct html_context *html_context)
{ {
char *value = get_attr_val(a, name, html_context->doc_cp); char *value = get_attr_val(a, name, html_context->doc_cp);
int ret = get_width2(value, limited, html_context);
mem_free_if(value);
return ret;
}
int
get_width2(char *value, int limited, struct html_context *html_context)
{
char *str = value; char *str = value;
char *end; char *end;
int percentage = 0; int percentage = 0;
@ -295,14 +324,14 @@ get_width(char *a, char *name, int limited,
/* Go back, and skip spaces after width if any. */ /* Go back, and skip spaces after width if any. */
while (len && isspace(str[len - 1])) len--; while (len && isspace(str[len - 1])) len--;
if (!len) { mem_free(value); return -1; } /* Nothing to parse. */ if (!len) { return -1; } /* Nothing to parse. */
/* Is this a percentage ? */ /* Is this a percentage ? */
if (str[len - 1] == '%') len--, percentage = 1; if (str[len - 1] == '%') len--, percentage = 1;
/* Skip spaces between width number and percentage if any. */ /* Skip spaces between width number and percentage if any. */
while (len && isspace(str[len - 1])) len--; while (len && isspace(str[len - 1])) len--;
if (!len) { mem_free(value); return -1; } /* Nothing to parse. */ if (!len) { return -1; } /* Nothing to parse. */
/* Shorten the string a bit, so strtoul() will work on useful /* Shorten the string a bit, so strtoul() will work on useful
* part of it. */ * part of it. */
@ -317,12 +346,9 @@ get_width(char *a, char *name, int limited,
/* We will accept floats but ceil() them. */ /* We will accept floats but ceil() them. */
if (errno || (*end && *end != '.') || width >= INT_MAX) { if (errno || (*end && *end != '.') || width >= INT_MAX) {
/* Not a valid number. */ /* Not a valid number. */
mem_free(value);
return -1; return -1;
} }
mem_free(value);
#define WIDTH_PIXELS2CHARS(width) ((width) + (HTML_CHAR_WIDTH - 1) / 2) / HTML_CHAR_WIDTH; #define WIDTH_PIXELS2CHARS(width) ((width) + (HTML_CHAR_WIDTH - 1) / 2) / HTML_CHAR_WIDTH;
if (limited) { if (limited) {
@ -356,8 +382,8 @@ get_width(char *a, char *name, int limited,
width = 0; width = 0;
return width; return width;
}
}
char * char *
skip_comment(char *html, char *eof) skip_comment(char *html, char *eof)
@ -580,7 +606,7 @@ static char *process_element(char *name, int namelen, int endingtag,
* This function currently requires a semicolon at the end of any * This function currently requires a semicolon at the end of any
* entity reference, and does not support U+2028 LINE SEPARATOR and * entity reference, and does not support U+2028 LINE SEPARATOR and
* U+2029 PARAGRAPH SEPARATOR. */ * U+2029 PARAGRAPH SEPARATOR. */
static const char * const char *
count_newline_entities(const char *html, const char *eof, count_newline_entities(const char *html, const char *eof,
int *newlines_out) int *newlines_out)
{ {
@ -858,7 +884,7 @@ start_element(struct element_info *ei,
/* Store formatting information for the currently top element on the /* Store formatting information for the currently top element on the
* stack before processing the new element. */ * stack before processing the new element. */
restore_format = html_is_preformatted(); restore_format = html_is_preformatted();
old_format = par_format; old_format = par_elformat;
/* Check for <meta refresh="..."> and <meta> cache-control directives /* Check for <meta refresh="..."> and <meta> cache-control directives
* inside <body> (see bug 700). */ * inside <body> (see bug 700). */
@ -936,12 +962,12 @@ start_element(struct element_info *ei,
* clickable. */ * clickable. */
#ifdef CONFIG_ECMASCRIPT #ifdef CONFIG_ECMASCRIPT
if (has_attr(attr, "onClick", html_context->doc_cp)) { if (has_attr(attr, "onClick", html_context->doc_cp)) {
/* XXX: Put something better to format.link. --pasky */ /* XXX: Put something better to elformat.link. --pasky */
mem_free_set(&format.link, stracpy("javascript:void(0);")); mem_free_set(&elformat.link, stracpy("javascript:void(0);"));
mem_free_set(&format.target, stracpy(html_context->base_target)); mem_free_set(&elformat.target, stracpy(html_context->base_target));
format.style.color.foreground = format.color.clink; elformat.style.color.foreground = elformat.color.clink;
html_top->pseudo_class = ELEMENT_LINK; html_top->pseudo_class = ELEMENT_LINK;
mem_free_set(&format.title, stracpy("onClick placeholder")); mem_free_set(&elformat.title, stracpy("onClick placeholder"));
/* Er. I know. Well, double html_focusable()s shouldn't /* Er. I know. Well, double html_focusable()s shouldn't
* really hurt. */ * really hurt. */
html_focusable(html_context, attr); html_focusable(html_context, attr);
@ -1015,7 +1041,7 @@ start_element(struct element_info *ei,
/* If we are rendering preformatted text (see above), restore the /* If we are rendering preformatted text (see above), restore the
* formatting attributes that were in effect before processing this * formatting attributes that were in effect before processing this
* element. */ * element. */
if (restore_format) par_format = old_format; if (restore_format) par_elformat = old_format;
return html; return html;
#undef ELEMENT_RENDER_PROLOGUE #undef ELEMENT_RENDER_PROLOGUE

View File

@ -65,7 +65,10 @@ typedef void (element_handler_T)(struct html_context *, char *attr,
int parse_element(char *, char *, char **, int *, char **, char **); int parse_element(char *, char *, char **, int *, char **, char **);
int get_num(char *, char *, int); int get_num(char *, char *, int);
int get_num2(char *);
int get_width(char *, char *, int, struct html_context *); int get_width(char *, char *, int, struct html_context *);
int get_width2(char *, int , struct html_context *);
char *skip_comment(char *, char *); char *skip_comment(char *, char *);
@ -80,6 +83,8 @@ int supports_html_media_attr(const char *media);
void free_tags_lookup(void); void free_tags_lookup(void);
void init_tags_lookup(void); void init_tags_lookup(void);
const char *count_newline_entities(const char *html, const char *eof, int *newlines_out);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -242,10 +242,10 @@ parse_table_attributes(struct table *table, char *attr, int real,
set_table_rules(html_context, table, attr); set_table_rules(html_context, table, attr);
table->align = par_format.align; table->align = par_elformat.align;
get_align(html_context, attr, &table->align); get_align(html_context, attr, &table->align);
table->color.background = par_format.color.background; table->color.background = par_elformat.color.background;
get_bgcolor(html_context, attr, &table->color.background); get_bgcolor(html_context, attr, &table->color.background);
} }

View File

@ -93,7 +93,6 @@ struct table_cache_entry {
static int table_cache_entries; static int table_cache_entries;
static struct hash *table_cache; static struct hash *table_cache;
struct renderer_context { struct renderer_context {
int last_link_to_move; int last_link_to_move;
struct tag *last_tag_to_move; struct tag *last_tag_to_move;
@ -123,11 +122,9 @@ struct renderer_context {
unsigned int nowrap:1; /* Activated/deactivated by SP_NOWRAP. */ unsigned int nowrap:1; /* Activated/deactivated by SP_NOWRAP. */
}; };
static struct renderer_context renderer_context; struct renderer_context renderer_context;
/* Prototypes */ /* Prototypes */
static void line_break(struct html_context *);
static void put_chars(struct html_context *, char *, int); static void put_chars(struct html_context *, char *, int);
#define X(x_) (part->box.x + (x_)) #define X(x_) (part->box.x + (x_))
@ -174,7 +171,7 @@ realloc_line(struct html_context *html_context, struct document *document,
end = &line->chars[length]; end = &line->chars[length];
end->data = ' '; end->data = ' ';
end->attr = 0; end->attr = 0;
set_screen_char_color(end, par_format.color.background, 0x0, set_screen_char_color(end, par_elformat.color.background, 0x0,
COLOR_ENSURE_CONTRAST, /* for bug 461 */ COLOR_ENSURE_CONTRAST, /* for bug 461 */
document->options.color_mode); document->options.color_mode);
@ -288,9 +285,9 @@ get_format_screen_char(struct html_context *html_context,
static struct text_style ta_cache = INIT_TEXT_STYLE(-1, 0x0, 0x0); static struct text_style ta_cache = INIT_TEXT_STYLE(-1, 0x0, 0x0);
static struct screen_char schar_cache; static struct screen_char schar_cache;
if (memcmp(&ta_cache, &format.style, sizeof(ta_cache))) { if (memcmp(&ta_cache, &elformat.style, sizeof(ta_cache))) {
copy_struct(&ta_cache, &format.style); copy_struct(&ta_cache, &elformat.style);
struct text_style final_style = format.style; struct text_style final_style = elformat.style;
get_screen_char_template(&schar_cache, html_context->options, final_style); get_screen_char_template(&schar_cache, html_context->options, final_style);
} }
@ -300,7 +297,7 @@ get_format_screen_char(struct html_context *html_context,
schar_cache.attr ^= SCREEN_ATTR_UNSEARCHABLE; schar_cache.attr ^= SCREEN_ATTR_UNSEARCHABLE;
} }
if (link_state != LINK_STATE_NONE if (link_state != LINK_STATE_NONE
&& !format.form && !elformat.form
&& html_context->options->underline_links) { && html_context->options->underline_links) {
schar_cache.attr |= SCREEN_ATTR_UNDERLINE; schar_cache.attr |= SCREEN_ATTR_UNDERLINE;
} }
@ -326,7 +323,7 @@ draw_frame_hchars(struct part *part, int x, int y, int width,
copy_screen_chars(&POS(x, y), template_, 1); copy_screen_chars(&POS(x, y), template_, 1);
} }
if (par_format.blockquote_level) { if (par_elformat.blockquote_level) {
draw_blockquote_chars(part, y, html_context); draw_blockquote_chars(part, y, html_context);
} }
} }
@ -335,15 +332,15 @@ void
draw_blockquote_chars(struct part *part, int y, struct html_context *html_context) draw_blockquote_chars(struct part *part, int y, struct html_context *html_context)
{ {
int i; int i;
int x = par_format.orig_leftmargin; int x = par_elformat.orig_leftmargin;
struct screen_char *const schar = get_format_screen_char(html_context, 0); struct screen_char *const schar = get_format_screen_char(html_context, 0);
if (LEN(y) + par_format.blockquote_level <= x) { if (LEN(y) + par_elformat.blockquote_level <= x) {
return; return;
} }
schar->data = '>'; schar->data = '>';
for (i = 1; i < par_format.blockquote_level; i++) { for (i = 1; i < par_elformat.blockquote_level; i++) {
copy_screen_chars(&POS(x, y), schar, 1); copy_screen_chars(&POS(x, y), schar, 1);
if (part->char_width) part->char_width[x] = 1; if (part->char_width) part->char_width[x] = 1;
x++; x++;
@ -382,10 +379,10 @@ expand_lines(struct html_context *html_context, struct part *part,
assert(part && part->document); assert(part && part->document);
if_assert_failed return; if_assert_failed return;
if (!use_document_bg_colors(&part->document->options) && !par_format.blockquote_level) if (!use_document_bg_colors(&part->document->options) && !par_elformat.blockquote_level)
return; return;
par_format.color.background = bgcolor; par_elformat.color.background = bgcolor;
if (x < 0) { if (x < 0) {
x = 0; x = 0;
@ -394,7 +391,7 @@ expand_lines(struct html_context *html_context, struct part *part,
for (line = 0; line < lines; line++) { for (line = 0; line < lines; line++) {
if (realloc_line(html_context, part->document, Y(y + line), X(x))) return; if (realloc_line(html_context, part->document, Y(y + line), X(x))) return;
if (par_format.blockquote_level) { if (par_elformat.blockquote_level) {
draw_blockquote_chars(part, y + line, html_context); draw_blockquote_chars(part, y + line, html_context);
} }
} }
@ -568,7 +565,7 @@ set_hline(struct html_context *html_context, char *chars, int charslen,
return 0; return 0;
if (part->begin) { if (part->begin) {
if (par_format.blockquote_level && !html_context->table_level) { if (par_elformat.blockquote_level && !html_context->table_level) {
draw_blockquote_chars(part, y, html_context); draw_blockquote_chars(part, y, html_context);
} }
part->begin = 0; part->begin = 0;
@ -809,7 +806,7 @@ set_hline(struct html_context *html_context, char *chars, int charslen,
return; return;
if (part->begin) { if (part->begin) {
if (par_format.blockquote_level && !html_context->table_level) { if (par_elformat.blockquote_level && !html_context->table_level) {
draw_blockquote_chars(part, y, html_context); draw_blockquote_chars(part, y, html_context);
} }
part->begin = 0; part->begin = 0;
@ -997,7 +994,7 @@ move_chars(struct html_context *html_context, int x, int y, int nx, int ny)
if_assert_failed discard_comb_x_y(part->document); if_assert_failed discard_comb_x_y(part->document);
move_links(html_context, x, y, nx, ny); move_links(html_context, x, y, nx, ny);
if (par_format.blockquote_level && !html_context->table_level) { if (par_elformat.blockquote_level && !html_context->table_level) {
draw_blockquote_chars(part, ny, html_context); draw_blockquote_chars(part, ny, html_context);
} }
} }
@ -1077,7 +1074,7 @@ split_line_at(struct html_context *html_context, int width)
{ {
struct part *part; struct part *part;
int tmp; int tmp;
int new_width = width + par_format.rightmargin; int new_width = width + par_elformat.rightmargin;
assert(html_context); assert(html_context);
if_assert_failed return 0; if_assert_failed return 0;
@ -1097,14 +1094,14 @@ split_line_at(struct html_context *html_context, int width)
#ifdef CONFIG_UTF8 #ifdef CONFIG_UTF8
if (html_context->options->utf8 if (html_context->options->utf8
&& width < part->spaces_len && part->char_width[width] == 2) { && width < part->spaces_len && part->char_width[width] == 2) {
move_chars(html_context, width, part->cy, par_format.leftmargin + par_format.blockquote_level * (html_context->table_level == 0), part->cy + 1); move_chars(html_context, width, part->cy, par_elformat.leftmargin + par_elformat.blockquote_level * (html_context->table_level == 0), part->cy + 1);
del_chars(html_context, width, part->cy); del_chars(html_context, width, part->cy);
} else } else
#endif #endif
{ {
assertm(POS(width, part->cy).data == ' ', assertm(POS(width, part->cy).data == ' ',
"bad split: %c", POS(width, part->cy).data); "bad split: %c", POS(width, part->cy).data);
move_chars(html_context, width + 1, part->cy, par_format.leftmargin + par_format.blockquote_level * (html_context->table_level == 0), part->cy + 1); move_chars(html_context, width + 1, part->cy, par_elformat.leftmargin + par_elformat.blockquote_level * (html_context->table_level == 0), part->cy + 1);
del_chars(html_context, width, part->cy); del_chars(html_context, width, part->cy);
} }
} }
@ -1132,13 +1129,13 @@ split_line_at(struct html_context *html_context, int width)
memset(part->char_width + tmp, 0, width); memset(part->char_width + tmp, 0, width);
#endif #endif
if (par_format.leftmargin + par_format.blockquote_level * (html_context->table_level == 0) > 0) { if (par_elformat.leftmargin + par_elformat.blockquote_level * (html_context->table_level == 0) > 0) {
tmp = part->spaces_len - (par_format.leftmargin + par_format.blockquote_level * (html_context->table_level == 0)); tmp = part->spaces_len - (par_elformat.leftmargin + par_elformat.blockquote_level * (html_context->table_level == 0));
assertm(tmp > 0, "part->spaces_len - par_format.leftmargin == %d", tmp); assertm(tmp > 0, "part->spaces_len - par_elformat.leftmargin == %d", tmp);
/* So tmp is zero, memmove() should survive that. Don't recover. */ /* So tmp is zero, memmove() should survive that. Don't recover. */
memmove(part->spaces + par_format.leftmargin + par_format.blockquote_level * (html_context->table_level == 0), part->spaces, tmp); memmove(part->spaces + par_elformat.leftmargin + par_elformat.blockquote_level * (html_context->table_level == 0), part->spaces, tmp);
#ifdef CONFIG_UTF8 #ifdef CONFIG_UTF8
memmove(part->char_width + par_format.leftmargin + par_format.blockquote_level * (html_context->table_level == 0), part->char_width, tmp); memmove(part->char_width + par_elformat.leftmargin + par_elformat.blockquote_level * (html_context->table_level == 0), part->char_width, tmp);
#endif #endif
} }
@ -1149,7 +1146,7 @@ split_line_at(struct html_context *html_context, int width)
int_lower_bound(&part->box.height, part->cy); int_lower_bound(&part->box.height, part->cy);
return 2; return 2;
} else { } else {
part->cx -= width - (par_format.leftmargin + par_format.blockquote_level * (html_context->table_level == 0)); part->cx -= width - (par_elformat.leftmargin + par_elformat.blockquote_level * (html_context->table_level == 0));
int_lower_bound(&part->box.height, part->cy + 1); int_lower_bound(&part->box.height, part->cy + 1);
return 1; return 1;
} }
@ -1179,40 +1176,40 @@ split_line(struct html_context *html_context)
#ifdef CONFIG_UTF8 #ifdef CONFIG_UTF8
if (html_context->options->utf8) { if (html_context->options->utf8) {
for (x = overlap(par_format); x >= (par_format.leftmargin + par_format.blockquote_level * (html_context->table_level == 0)); x--) { for (x = overlap(par_elformat); x >= (par_elformat.leftmargin + par_elformat.blockquote_level * (html_context->table_level == 0)); x--) {
if (x < part->spaces_len && (part->spaces[x] if (x < part->spaces_len && (part->spaces[x]
|| (part->char_width[x] == 2 || (part->char_width[x] == 2
/* Ugly hack. If we haven't place for /* Ugly hack. If we haven't place for
* double-width characters we print two * double-width characters we print two
* double-width characters. */ * double-width characters. */
&& x != (par_format.leftmargin + par_format.blockquote_level * (html_context->table_level == 0))))) && x != (par_elformat.leftmargin + par_elformat.blockquote_level * (html_context->table_level == 0)))))
return split_line_at(html_context, x); return split_line_at(html_context, x);
} }
for (x = par_format.leftmargin + par_format.blockquote_level * (html_context->table_level == 0); x < part->cx ; x++) { for (x = par_elformat.leftmargin + par_elformat.blockquote_level * (html_context->table_level == 0); x < part->cx ; x++) {
if (x < part->spaces_len && (part->spaces[x] if (x < part->spaces_len && (part->spaces[x]
|| (part->char_width[x] == 2 || (part->char_width[x] == 2
/* We want to break line after _second_ /* We want to break line after _second_
* double-width character. */ * double-width character. */
&& x > (par_format.leftmargin + par_format.blockquote_level * (html_context->table_level == 0))))) && x > (par_elformat.leftmargin + par_elformat.blockquote_level * (html_context->table_level == 0)))))
return split_line_at(html_context, x); return split_line_at(html_context, x);
} }
} else } else
#endif #endif
{ {
for (x = overlap(par_format); x >= (par_format.leftmargin + par_format.blockquote_level * (html_context->table_level == 0)); x--) for (x = overlap(par_elformat); x >= (par_elformat.leftmargin + par_elformat.blockquote_level * (html_context->table_level == 0)); x--)
if (x < part->spaces_len && part->spaces[x]) if (x < part->spaces_len && part->spaces[x])
return split_line_at(html_context, x); return split_line_at(html_context, x);
for (x = par_format.leftmargin + par_format.blockquote_level * (html_context->table_level == 0); x < part->cx ; x++) for (x = par_elformat.leftmargin + par_elformat.blockquote_level * (html_context->table_level == 0); x < part->cx ; x++)
if (x < part->spaces_len && part->spaces[x]) if (x < part->spaces_len && part->spaces[x])
return split_line_at(html_context, x); return split_line_at(html_context, x);
} }
/* Make sure that we count the right margin to the total /* Make sure that we count the right margin to the total
* actual box width. */ * actual box width. */
int_lower_bound(&part->box.width, part->cx + par_format.rightmargin); int_lower_bound(&part->box.width, part->cx + par_elformat.rightmargin);
return 0; return 0;
} }
@ -1318,10 +1315,10 @@ justify_line(struct html_context *html_context, int y)
/* Diff is the difference between the width of the paragraph /* Diff is the difference between the width of the paragraph
* and the current length of the line. */ * and the current length of the line. */
diff = overlap(par_format) - len; diff = overlap(par_elformat) - len;
/* We check diff > 0 because diff can be negative (i.e., we have /* We check diff > 0 because diff can be negative (i.e., we have
* an unbroken line of length > overlap(par_format)) * an unbroken line of length > overlap(par_elformat))
* even when spaces > 1 if the line has only non-breaking spaces. */ * even when spaces > 1 if the line has only non-breaking spaces. */
if (spaces > 1 && diff > 0) { if (spaces > 1 && diff > 0) {
int prev_end = 0; int prev_end = 0;
@ -1332,7 +1329,7 @@ justify_line(struct html_context *html_context, int y)
* line unchanged, rather than halfway there. The * line unchanged, rather than halfway there. The
* following loop assumes the allocation succeeded. */ * following loop assumes the allocation succeeded. */
if (!realloc_line(html_context, html_context->part->document, if (!realloc_line(html_context, html_context->part->document,
Y(y), X(overlap(par_format)))) Y(y), X(overlap(par_elformat))))
goto out_of_memory; goto out_of_memory;
for (word = 0; word < spaces; word++) { for (word = 0; word < spaces; word++) {
@ -1418,17 +1415,17 @@ align_line(struct html_context *html_context, int y, int last)
len = LEN(y); len = LEN(y);
if (!len || par_format.align == ALIGN_LEFT) if (!len || par_elformat.align == ALIGN_LEFT)
return; return;
if (par_format.align == ALIGN_JUSTIFY) { if (par_elformat.align == ALIGN_JUSTIFY) {
if (!last) if (!last)
justify_line(html_context, y); justify_line(html_context, y);
return; return;
} }
shift = overlap(par_format) - len; shift = overlap(par_elformat) - len;
if (par_format.align == ALIGN_CENTER) if (par_elformat.align == ALIGN_CENTER)
shift /= 2; shift /= 2;
if (shift > 0) if (shift > 0)
shift_chars(html_context, y, shift); shift_chars(html_context, y, shift);
@ -1455,13 +1452,13 @@ init_link_event_hooks(struct html_context *html_context, struct link *link)
} while (0) } while (0)
init_list(*link->event_hooks); init_list(*link->event_hooks);
add_evhook(link->event_hooks, SEVHOOK_ONCLICK, format.onclick); add_evhook(link->event_hooks, SEVHOOK_ONCLICK, elformat.onclick);
add_evhook(link->event_hooks, SEVHOOK_ONDBLCLICK, format.ondblclick); add_evhook(link->event_hooks, SEVHOOK_ONDBLCLICK, elformat.ondblclick);
add_evhook(link->event_hooks, SEVHOOK_ONMOUSEOVER, format.onmouseover); add_evhook(link->event_hooks, SEVHOOK_ONMOUSEOVER, elformat.onmouseover);
add_evhook(link->event_hooks, SEVHOOK_ONHOVER, format.onhover); add_evhook(link->event_hooks, SEVHOOK_ONHOVER, elformat.onhover);
add_evhook(link->event_hooks, SEVHOOK_ONFOCUS, format.onfocus); add_evhook(link->event_hooks, SEVHOOK_ONFOCUS, elformat.onfocus);
add_evhook(link->event_hooks, SEVHOOK_ONMOUSEOUT, format.onmouseout); add_evhook(link->event_hooks, SEVHOOK_ONMOUSEOUT, elformat.onmouseout);
add_evhook(link->event_hooks, SEVHOOK_ONBLUR, format.onblur); add_evhook(link->event_hooks, SEVHOOK_ONBLUR, elformat.onblur);
#undef add_evhook #undef add_evhook
} }
@ -1494,30 +1491,30 @@ new_link(struct html_context *html_context, char *name, int namelen)
link = &document->links[document->nlinks++]; link = &document->links[document->nlinks++];
link->number = link_number - 1; link->number = link_number - 1;
if (document->options.use_tabindex) link->number += format.tabindex; if (document->options.use_tabindex) link->number += elformat.tabindex;
link->accesskey = format.accesskey; link->accesskey = elformat.accesskey;
link->title = null_or_stracpy(format.title); link->title = null_or_stracpy(elformat.title);
link->where_img = null_or_stracpy(format.image); link->where_img = null_or_stracpy(elformat.image);
if (!format.form) { if (!elformat.form) {
link->target = null_or_stracpy(format.target); link->target = null_or_stracpy(elformat.target);
link->data.name = memacpy(name, namelen); link->data.name = memacpy(name, namelen);
/* if (strlen(url) > 4 && !c_strncasecmp(url, "MAP@", 4)) { */ /* if (strlen(url) > 4 && !c_strncasecmp(url, "MAP@", 4)) { */
if (format.link if (elformat.link
&& ((format.link[0]|32) == 'm') && ((elformat.link[0]|32) == 'm')
&& ((format.link[1]|32) == 'a') && ((elformat.link[1]|32) == 'a')
&& ((format.link[2]|32) == 'p') && ((elformat.link[2]|32) == 'p')
&& (format.link[3] == '@') && (elformat.link[3] == '@')
&& format.link[4]) { && elformat.link[4]) {
link->type = LINK_MAP; link->type = LINK_MAP;
link->where = stracpy(format.link + 4); link->where = stracpy(elformat.link + 4);
} else { } else {
link->type = LINK_HYPERTEXT; link->type = LINK_HYPERTEXT;
link->where = null_or_stracpy(format.link); link->where = null_or_stracpy(elformat.link);
} }
} else { } else {
struct el_form_control *fc = format.form; struct el_form_control *fc = elformat.form;
struct form *form; struct form *form;
switch (fc->type) { switch (fc->type) {
@ -1544,7 +1541,7 @@ new_link(struct html_context *html_context, char *name, int namelen)
link->type = LINK_BUTTON; link->type = LINK_BUTTON;
} }
link->data.form_control = fc; link->data.form_control = fc;
/* At this point, format.form might already be set but /* At this point, elformat.form might already be set but
* the form_control not registered through SP_CONTROL * the form_control not registered through SP_CONTROL
* yet, therefore without fc->form set. It is always * yet, therefore without fc->form set. It is always
* after the "good" last form was already processed, * after the "good" last form was already processed,
@ -1555,10 +1552,10 @@ new_link(struct html_context *html_context, char *name, int namelen)
link->target = null_or_stracpy(form ? form->target : NULL); link->target = null_or_stracpy(form ? form->target : NULL);
} }
link->color.background = format.style.color.background; link->color.background = elformat.style.color.background;
link->color.foreground = link_is_textinput(link) link->color.foreground = link_is_textinput(link)
? format.style.color.foreground ? elformat.style.color.foreground
: format.color.clink; : elformat.color.clink;
init_link_event_hooks(html_context, link); init_link_event_hooks(html_context, link);
@ -1589,7 +1586,7 @@ html_special_tag(struct document *document, char *t, int x, int y)
} }
static void void
put_chars_conv(struct html_context *html_context, put_chars_conv(struct html_context *html_context,
char *chars, int charslen) char *chars, int charslen)
{ {
@ -1599,14 +1596,14 @@ put_chars_conv(struct html_context *html_context,
assert(html_context->part && chars && charslen); assert(html_context->part && chars && charslen);
if_assert_failed return; if_assert_failed return;
if (format.style.attr & AT_GRAPHICS) { if (elformat.style.attr & AT_GRAPHICS) {
put_chars(html_context, chars, charslen); put_chars(html_context, chars, charslen);
return; return;
} }
convert_string(renderer_context.convert_table, chars, charslen, convert_string(renderer_context.convert_table, chars, charslen,
html_context->options->cp, html_context->options->cp,
(format.style.attr & AT_NO_ENTITIES) ? CSM_NONE : CSM_DEFAULT, (elformat.style.attr & AT_NO_ENTITIES) ? CSM_NONE : CSM_DEFAULT,
NULL, (void (*)(void *, char *, int)) put_chars, html_context); NULL, (void (*)(void *, char *, int)) put_chars, html_context);
} }
@ -1658,19 +1655,19 @@ put_link_number(struct html_context *html_context)
char *symkey = get_opt_str("document.browse.links.label_key", NULL); char *symkey = get_opt_str("document.browse.links.label_key", NULL);
struct part *part = html_context->part; struct part *part = html_context->part;
char s[64]; char s[64];
char *fl = format.link; char *fl = elformat.link;
char *ft = format.target; char *ft = elformat.target;
char *fi = format.image; char *fi = elformat.image;
struct text_style old_style = format.style; struct text_style old_style = elformat.style;
struct el_form_control *ff = format.form; struct el_form_control *ff = elformat.form;
int slen = 0; int slen = 0;
int base = strlen(symkey); int base = strlen(symkey);
format.link = format.target = format.image = NULL; elformat.link = elformat.target = elformat.image = NULL;
format.form = NULL; elformat.form = NULL;
if (html_context->options->use_link_number_color) { if (html_context->options->use_link_number_color) {
format.style.attr &= ~AT_BOLD; elformat.style.attr &= ~AT_BOLD;
format.style.color.foreground = format.color.link_number; elformat.style.color.foreground = elformat.color.link_number;
} }
s[slen++] = '['; s[slen++] = '[';
@ -1687,15 +1684,15 @@ put_link_number(struct html_context *html_context)
/* We might have ended up on a new line after the line breaking /* We might have ended up on a new line after the line breaking
* or putting the link number chars. */ * or putting the link number chars. */
if (part->cx == -1) { if (part->cx == -1) {
part->cx = par_format.leftmargin + par_format.blockquote_level * (html_context->table_level == 0); part->cx = par_elformat.leftmargin + par_elformat.blockquote_level * (html_context->table_level == 0);
part->begin = 1; part->begin = 1;
} }
format.link = fl; elformat.link = fl;
format.target = ft; elformat.target = ft;
format.image = fi; elformat.image = fi;
format.form = ff; elformat.form = ff;
format.style = old_style; elformat.style = old_style;
} }
#define assert_link_variable(old, new) \ #define assert_link_variable(old, new) \
@ -1775,8 +1772,8 @@ process_link(struct html_context *html_context, enum link_state link_state,
case LINK_STATE_NEW: case LINK_STATE_NEW:
part->link_num++; part->link_num++;
init_link_state_info(format.link, format.target, init_link_state_info(elformat.link, elformat.target,
format.image, format.form); elformat.image, elformat.form);
if (!part->document) return; if (!part->document) return;
/* Trim leading space from the link text */ /* Trim leading space from the link text */
@ -1834,16 +1831,16 @@ get_link_state(struct html_context *html_context)
{ {
enum link_state state; enum link_state state;
if (!(format.link || format.image || format.form)) { if (!(elformat.link || elformat.image || elformat.form)) {
state = LINK_STATE_NONE; state = LINK_STATE_NONE;
} else if ((renderer_context.link_state_info.link } else if ((renderer_context.link_state_info.link
|| renderer_context.link_state_info.image || renderer_context.link_state_info.image
|| renderer_context.link_state_info.form) || renderer_context.link_state_info.form)
&& !xstrcmp(format.link, renderer_context.link_state_info.link) && !xstrcmp(elformat.link, renderer_context.link_state_info.link)
&& !xstrcmp(format.target, renderer_context.link_state_info.target) && !xstrcmp(elformat.target, renderer_context.link_state_info.target)
&& !xstrcmp(format.image, renderer_context.link_state_info.image) && !xstrcmp(elformat.image, renderer_context.link_state_info.image)
&& format.form == renderer_context.link_state_info.form) { && elformat.form == renderer_context.link_state_info.form) {
return LINK_STATE_SAME; return LINK_STATE_SAME;
@ -1902,7 +1899,7 @@ put_chars(struct html_context *html_context, char *chars, int charslen)
if (charslen < 1) return; if (charslen < 1) return;
} }
part->cx = par_format.leftmargin + (par_format.blockquote_level * (html_context->table_level == 0)); part->cx = par_elformat.leftmargin + (par_elformat.blockquote_level * (html_context->table_level == 0));
part->begin = 1; part->begin = 1;
} }
@ -1951,13 +1948,13 @@ put_chars(struct html_context *html_context, char *chars, int charslen)
#ifdef CONFIG_UTF8 #ifdef CONFIG_UTF8
if (renderer_context.nowrap if (renderer_context.nowrap
&& part->cx + cells > overlap(par_format)) && part->cx + cells > overlap(par_elformat))
return; return;
part->cx += cells; part->cx += cells;
#else #else
if (renderer_context.nowrap if (renderer_context.nowrap
&& part->cx + charslen > overlap(par_format)) && part->cx + charslen > overlap(par_elformat))
return; return;
part->cx += charslen; part->cx += charslen;
@ -1966,8 +1963,8 @@ put_chars(struct html_context *html_context, char *chars, int charslen)
renderer_context.nobreak = 0; renderer_context.nobreak = 0;
if (html_context->options->wrap || !html_is_preformatted()) { if (html_context->options->wrap || !html_is_preformatted()) {
while (part->cx > overlap(par_format) while (part->cx > overlap(par_elformat)
&& part->cx > (par_format.leftmargin + par_format.blockquote_level * (html_context->table_level == 0))) { && part->cx > (par_elformat.leftmargin + par_elformat.blockquote_level * (html_context->table_level == 0))) {
int x = split_line(html_context); int x = split_line(html_context);
if (!x) break; if (!x) break;
@ -1984,14 +1981,14 @@ put_chars(struct html_context *html_context, char *chars, int charslen)
part->xa += charslen; part->xa += charslen;
#endif /* CONFIG_UTF8 */ #endif /* CONFIG_UTF8 */
int_lower_bound(&part->max_width, part->xa int_lower_bound(&part->max_width, part->xa
+ par_format.leftmargin + par_format.blockquote_level * (html_context->table_level == 0) + par_format.rightmargin + par_elformat.leftmargin + par_elformat.blockquote_level * (html_context->table_level == 0) + par_elformat.rightmargin
- (chars[charslen - 1] == ' ' - (chars[charslen - 1] == ' '
&& (html_context->options->wrap || !html_is_preformatted()))); && (html_context->options->wrap || !html_is_preformatted())));
} }
#undef overlap #undef overlap
static void void
line_break(struct html_context *html_context) line_break(struct html_context *html_context)
{ {
struct part *part; struct part *part;
@ -2005,7 +2002,7 @@ line_break(struct html_context *html_context)
assert(part); assert(part);
if_assert_failed return; if_assert_failed return;
int_lower_bound(&part->box.width, part->cx + par_format.rightmargin); int_lower_bound(&part->box.width, part->cx + par_elformat.rightmargin);
if (renderer_context.nobreak) { if (renderer_context.nobreak) {
renderer_context.nobreak = 0; renderer_context.nobreak = 0;
@ -2019,7 +2016,7 @@ line_break(struct html_context *html_context)
if (!realloc_lines(part->document, part->box.height + part->cy + 1)) if (!realloc_lines(part->document, part->box.height + part->cy + 1))
return; return;
if (part->cx > (par_format.leftmargin + par_format.blockquote_level * (html_context->table_level == 0)) && LEN(part->cy) > part->cx - 1 if (part->cx > (par_elformat.leftmargin + par_elformat.blockquote_level * (html_context->table_level == 0)) && LEN(part->cy) > part->cx - 1
&& POS(part->cx - 1, part->cy).data == ' ') { && POS(part->cx - 1, part->cy).data == ' ') {
del_chars(html_context, part->cx - 1, part->cy); del_chars(html_context, part->cx - 1, part->cy);
part->cx--; part->cx--;
@ -2243,7 +2240,7 @@ static inline void
color_link_lines(struct html_context *html_context) color_link_lines(struct html_context *html_context)
{ {
struct document *document = html_context->part->document; struct document *document = html_context->part->document;
struct color_pair colors = INIT_COLOR_PAIR(par_format.color.background, 0x0); struct color_pair colors = INIT_COLOR_PAIR(par_elformat.color.background, 0x0);
enum color_mode color_mode = document->options.color_mode; enum color_mode color_mode = document->options.color_mode;
enum color_flags color_flags = document->options.color_flags; enum color_flags color_flags = document->options.color_flags;
int y; int y;
@ -2259,14 +2256,14 @@ color_link_lines(struct html_context *html_context)
/* XXX: Entering hack zone! Change to clink color after /* XXX: Entering hack zone! Change to clink color after
* link text has been recolored. */ * link text has been recolored. */
if (schar->data == ':' && colors.foreground == 0x0) if (schar->data == ':' && colors.foreground == 0x0)
colors.foreground = format.color.clink; colors.foreground = elformat.color.clink;
} }
colors.foreground = 0x0; colors.foreground = 0x0;
} }
} }
static void * void *
html_special(struct html_context *html_context, enum html_special_type c, ...) html_special(struct html_context *html_context, enum html_special_type c, ...)
{ {
va_list l; va_list l;
@ -2613,8 +2610,8 @@ render_html_document(struct cache_entry *cached, struct document *document,
} }
done_string(&title); done_string(&title);
part = format_html_part(html_context, start, end, par_format.align, part = format_html_part(html_context, start, end, par_elformat.align,
par_format.leftmargin + par_format.blockquote_level * (html_context->table_level == 0), par_elformat.leftmargin + par_elformat.blockquote_level * (html_context->table_level == 0),
document->options.document_width, document, document->options.document_width, document,
0, 0, head.source, 1); 0, 0, head.source, 1);
@ -2642,7 +2639,7 @@ render_html_document(struct cache_entry *cached, struct document *document,
>= document->options.width)); >= document->options.width));
#endif #endif
document->color.background = par_format.color.background; document->color.background = par_elformat.color.background;
done_html_parser(html_context); done_html_parser(html_context);

View File

@ -77,6 +77,12 @@ struct part *format_html_part(struct html_context *html_context, char *, char *,
int dec2qwerty(int num, char *link_sym, const char *key, int base); int dec2qwerty(int num, char *link_sym, const char *key, int base);
int qwerty2dec(const char *link_sym, const char *key, int base); int qwerty2dec(const char *link_sym, const char *key, int base);
void put_chars_conv(struct html_context *html_context, char *chars, int charslen);
void line_break(struct html_context *html_context);
void *html_special(struct html_context *html_context, enum html_special_type c, ...);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -52,22 +52,22 @@ get_table_frames(struct table *table, struct table_frames *result)
static int static int
get_table_indent(struct html_context *html_context, struct table *table) get_table_indent(struct html_context *html_context, struct table *table)
{ {
int width = par_format.width - table->real_width; int width = par_elformat.width - table->real_width;
int indent; int indent;
switch (table->align) { switch (table->align) {
case ALIGN_CENTER: case ALIGN_CENTER:
indent = /*par_format.blockquote_level +*/ (width + par_format.leftmargin - par_format.rightmargin) / 2; indent = /*par_elformat.blockquote_level +*/ (width + par_elformat.leftmargin - par_elformat.rightmargin) / 2;
break; break;
case ALIGN_RIGHT: case ALIGN_RIGHT:
indent = width - par_format.rightmargin; indent = width - par_elformat.rightmargin;
break; break;
case ALIGN_LEFT: case ALIGN_LEFT:
case ALIGN_JUSTIFY: case ALIGN_JUSTIFY:
default: default:
indent = par_format.leftmargin + par_format.blockquote_level; indent = par_elformat.leftmargin + par_elformat.blockquote_level;
} }
/* Don't use int_bounds(&x, 0, width) here, /* Don't use int_bounds(&x, 0, width) here,
@ -538,7 +538,7 @@ get_table_cellpadding(struct html_context *html_context, struct table *table)
{ {
struct part *part = table->part; struct part *part = table->part;
int cpd_pass = 0, cpd_width = 0, cpd_last = table->cellpadding; int cpd_pass = 0, cpd_width = 0, cpd_last = table->cellpadding;
int margins = /*par_format.blockquote_level +*/ par_format.leftmargin + par_format.rightmargin; int margins = /*par_elformat.blockquote_level +*/ par_elformat.leftmargin + par_elformat.rightmargin;
again: again:
get_cell_widths(html_context, table); get_cell_widths(html_context, table);
@ -870,10 +870,10 @@ draw_table_cell(struct table *table, int col, int row, int x, int y,
state = init_html_parser_state(html_context, ELEMENT_DONT_KILL, state = init_html_parser_state(html_context, ELEMENT_DONT_KILL,
cell->align, 0, 0); cell->align, 0, 0);
if (cell->is_header) format.style.attr |= AT_BOLD; if (cell->is_header) elformat.style.attr |= AT_BOLD;
format.style.color.background = cell->bgcolor; elformat.style.color.background = cell->bgcolor;
par_format.color.background = cell->bgcolor; par_elformat.color.background = cell->bgcolor;
if (cell->valign == VALIGN_MIDDLE) if (cell->valign == VALIGN_MIDDLE)
tmpy += (height - cell->height) / 2; tmpy += (height - cell->height) / 2;
@ -908,7 +908,7 @@ draw_table_cells(struct table *table, int x, int y,
{ {
int col, row; int col, row;
int xp; int xp;
color_T bgcolor = par_format.color.background; color_T bgcolor = par_elformat.color.background;
struct table_frames table_frames; struct table_frames table_frames;
get_table_frames(table, &table_frames); get_table_frames(table, &table_frames);
@ -1033,7 +1033,7 @@ draw_frame_point(struct table *table, signed char *frame[2], int x, int y,
+ 27 * int_max(bottom, 0); + 27 * int_max(bottom, 0);
draw_frame_hchars(table->part, x, y, 1, border_chars[pos], draw_frame_hchars(table->part, x, y, 1, border_chars[pos],
par_format.color.background, table->color.border, par_elformat.color.background, table->color.border,
html_context); html_context);
} }
@ -1050,7 +1050,7 @@ draw_frame_hline(struct table *table, signed char *frame[2], int x, int y,
if (pos < 0 || table->cols_widths[col] <= 0) return; if (pos < 0 || table->cols_widths[col] <= 0) return;
draw_frame_hchars(table->part, x, y, table->cols_widths[col], hltable[pos], draw_frame_hchars(table->part, x, y, table->cols_widths[col], hltable[pos],
par_format.color.background, table->color.border, html_context); par_elformat.color.background, table->color.border, html_context);
} }
static inline void static inline void
@ -1066,7 +1066,7 @@ draw_frame_vline(struct table *table, signed char *frame[2], int x, int y,
if (pos < 0 || table->rows_heights[row] <= 0) return; if (pos < 0 || table->rows_heights[row] <= 0) return;
draw_frame_vchars(table->part, x, y, table->rows_heights[row], vltable[pos], draw_frame_vchars(table->part, x, y, table->rows_heights[row], vltable[pos],
par_format.color.background, table->color.border, html_context); par_elformat.color.background, table->color.border, html_context);
} }
static inline int static inline int
@ -1226,7 +1226,7 @@ draw_table_caption(struct html_context *html_context, struct table *table,
if (!part) return; if (!part) return;
if (par_format.blockquote_level) { if (par_elformat.blockquote_level) {
int yy; int yy;
for (yy = 0; yy < part->box.height; yy++) { for (yy = 0; yy < part->box.height; yy++) {
@ -1304,7 +1304,7 @@ format_table(char *attr, char *html, char *eof,
state = init_html_parser_state(html_context, ELEMENT_DONT_KILL, state = init_html_parser_state(html_context, ELEMENT_DONT_KILL,
ALIGN_LEFT, 0, 0); ALIGN_LEFT, 0, 0);
margins = /*par_format.blockquote_level + */par_format.leftmargin + par_format.rightmargin; margins = /*par_elformat.blockquote_level + */par_elformat.leftmargin + par_elformat.rightmargin;
if (get_table_cellpadding(html_context, table)) goto ret2; if (get_table_cellpadding(html_context, table)) goto ret2;
distribute_table_widths(table); distribute_table_widths(table);
@ -1312,7 +1312,7 @@ format_table(char *attr, char *html, char *eof,
if (!part->document && part->box.x == 1) { if (!part->document && part->box.x == 1) {
int total_width = table->real_width + margins; int total_width = table->real_width + margins;
int_bounds(&total_width, table->real_width, par_format.width); int_bounds(&total_width, table->real_width, par_elformat.width);
int_lower_bound(&part->box.width, total_width); int_lower_bound(&part->box.width, total_width);
part->cy += table->real_height; part->cy += table->real_height;

View File

@ -21,6 +21,7 @@
#include "document/plain/renderer.h" #include "document/plain/renderer.h"
#ifdef CONFIG_XML #ifdef CONFIG_XML
#include "document/xml/renderer.h" #include "document/xml/renderer.h"
#include "document/xml/renderer2.h"
#endif #endif
#include "document/renderer.h" #include "document/renderer.h"
#include "document/view.h" #include "document/view.h"
@ -280,7 +281,12 @@ render_encoded_document(struct cache_entry *cached, struct document *document)
render_dom_document(cached, document, &buffer); render_dom_document(cached, document, &buffer);
else else
#endif #endif
render_html_document(cached, document, &buffer); #ifdef CONFIG_XML
if (document->dom)
render_xhtml_document(cached, document, &buffer);
else
#endif
render_html_document(cached, document, &buffer);
} }
if (encoding != ENCODING_NONE) { if (encoding != ENCODING_NONE) {

View File

@ -0,0 +1,364 @@
/* Plain text document renderer */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "elinks.h"
#include "bookmarks/bookmarks.h"
#include "cache/cache.h"
#include "config/options.h"
#include "document/docdata.h"
#include "document/document.h"
#include "document/format.h"
#include "document/options.h"
#include "document/html/internal.h"
#include "document/html/parser.h"
#include "document/html/parser/parse.h"
#include "document/plain/renderer.h"
#include "document/renderer.h"
#include "document/xml/renderer2.h"
#include "document/xml/tags.h"
#include "globhist/globhist.h"
#include "intl/charsets.h"
#include "protocol/protocol.h"
#include "protocol/uri.h"
#include "terminal/color.h"
#include "terminal/draw.h"
#include "util/color.h"
#include "util/error.h"
#include "util/memory.h"
#include "util/string.h"
#include <libxml++/libxml++.h>
static void
dump_text(struct source_renderer *renderer, unsigned char *html, int length)
{
struct html_context *html_context = renderer->html_context;
unsigned char *eof = html + length;
unsigned char *base_pos = html;
if (length > 0 && (eof[-1] == '\n')) {
length--;
eof--;
}
#ifdef CONFIG_CSS
if (html_context->was_style) {
/// css_parse_stylesheet(&html_context->css_styles, html_context->base_href, html, eof);
return;
}
#endif
//fprintf(stderr, "html='%s'\n", html);
if (length <= 0) {
return;
}
int noupdate = 0;
main_loop:
if (!html_is_preformatted()) {
unsigned char *buffer = fmem_alloc(length+1);
unsigned char *dst;
html_context->part = renderer->part;
html_context->eoff = eof;
if (!buffer) {
return;
}
dst = buffer;
*dst = *html;
for (html++; html <= eof; html++) {
if (isspace(*html)) {
if (*dst != ' ') {
*(++dst) = ' ';
}
} else {
*(++dst) = *html;
}
}
if (dst - buffer > 1) {
if (*buffer == ' ') {
html_context->putsp = HTML_SPACE_ADD;
}
}
put_chrs(html_context, buffer, dst - buffer);
fmem_free(buffer);
}
while (html < eof) {
int dotcounter = 0;
if (!noupdate) {
html_context->part = renderer->part;
html_context->eoff = eof;
base_pos = html;
} else {
noupdate = 0;
}
if (html_is_preformatted()) {
html_context->putsp = HTML_SPACE_NORMAL;
if (*html == ASCII_TAB) {
put_chrs(html_context, base_pos, html - base_pos);
put_chrs(html_context, " ",
8 - (html_context->position % 8));
html++;
continue;
} else if (*html == ASCII_CR || *html == ASCII_LF) {
put_chrs(html_context, base_pos, html - base_pos);
if (html - base_pos == 0 && html_context->line_breax > 0) {
html_context->line_breax--;
}
next_break:
if (*html == ASCII_CR && html < eof - 1 && html[1] == ASCII_LF) {
html++;
}
ln_break(html_context, 1);
html++;
if (*html == ASCII_CR || *html == ASCII_LF) {
html_context->line_breax = 0;
goto next_break;
}
continue;
} else if (html + 5 < eof && *html == '&') {
/* Really nasty hack to make &#13; handling in
* <pre>-tags lynx-compatible. It works around
* the entity handling done in the renderer,
* since checking #13 value there would require
* something along the lines of NBSP_CHAR or
* checking for '\n's in AT_PREFORMATTED text. */
/* See bug 52 and 387 for more info. */
int length = html - base_pos;
int newlines;
html = (unsigned char *) count_newline_entities(html, eof, &newlines);
if (newlines) {
put_chrs(html_context, base_pos, length);
ln_break(html_context, newlines);
continue;
}
}
}
while (*html < ' ') {
if (html - base_pos) {
put_chrs(html_context, base_pos, html - base_pos);
}
dotcounter++;
base_pos = ++html;
if (*html >= ' ' || isspace(*html) || html >= eof) {
unsigned char *dots = fmem_alloc(dotcounter);
if (dots) {
memset(dots, '.', dotcounter);
put_chrs(html_context, dots, dotcounter);
fmem_free(dots);
}
goto main_loop;
}
}
}
}
#define HTML_MAX_DOM_STRUCTURE_DEPTH 1024
static bool
dump_dom_structure(struct source_renderer *renderer, xmlpp::Node *node, int depth)
{
if (depth >= HTML_MAX_DOM_STRUCTURE_DEPTH) {
return false;
}
std::string tag_name = node->get_name();
struct element_info2 *ei = get_tag_value(tag_name.c_str(), tag_name.size());
/* Print this node's entry */
if (ei) {
ei->open(renderer, node, NULL, NULL, NULL, NULL);
}
/* Get the node's first child */
auto children = node->get_children();
auto it = children.begin();
auto end = children.end();
for (;it != end; ++it) {
xmlpp::Element *el = dynamic_cast<xmlpp::Element *>(*it);
if (el) {
dump_dom_structure(renderer, el, depth + 1);
} else {
xmlpp::TextNode *text = dynamic_cast<xmlpp::TextNode *>(*it);
if (text) {
std::string v = text->get_content();
dump_text(renderer, v.c_str(), v.size());
}
}
}
if (ei && ei->close) {
ei->close(renderer, node, NULL, NULL, NULL, NULL);
}
return true;
}
void
render_xhtml_document(struct cache_entry *cached, struct document *document, struct string *buffer)
{
struct html_context *html_context;
struct part *part = NULL;
char *start;
char *end;
struct string title;
struct string head;
struct source_renderer renderer;
assert(cached && document);
if_assert_failed return;
if (!init_string(&head)) return;
if (cached->head) add_to_string(&head, cached->head);
start = buffer->source;
end = buffer->source + buffer->length;
html_context = init_html_parser(cached->uri, &document->options,
start, end, &head, &title,
put_chars_conv, line_break,
html_special);
if (!html_context) return;
/// renderer_context.g_ctrl_num = 0;
/// renderer_context.cached = cached;
/// renderer_context.convert_table = get_convert_table(head.source,
/// document->options.cp,
/// document->options.assume_cp,
/// &document->cp,
/// &document->cp_status,
/// document->options.hard_assume);
struct conv_table *convert_table = get_convert_table(head.source,
document->options.cp,
document->options.assume_cp,
&document->cp,
&document->cp_status,
document->options.hard_assume);;
#ifdef CONFIG_UTF8
html_context->options->utf8 = is_cp_utf8(document->options.cp);
#endif /* CONFIG_UTF8 */
html_context->doc_cp = document->cp;
if (title.length) {
/* CSM_DEFAULT because init_html_parser() did not
* decode entities in the title. */
document->title = convert_string(convert_table,
title.source, title.length,
document->options.cp,
CSM_DEFAULT, NULL, NULL, NULL);
}
done_string(&title);
xmlpp::Document *doc = document->dom;
xmlpp::Element *root = doc->get_root_node();
renderer.html_context = html_context;
html_context->putsp = HTML_SPACE_SUPPRESS;
html_context->line_breax = html_context->table_level ? 2 : 1;
html_context->position = 0;
html_context->was_br = 0;
html_context->was_li = 0;
html_context->was_body = 0;
/* html_context->was_body_background = 0; */
renderer.part = html_context->part = part;
/// html_context->eoff = eof;
dump_dom_structure(&renderer, root, 0);
/// part = format_html_part(html_context, start, end, par_format.align,
/// par_format.leftmargin + par_format.blockquote_level * (html_context->table_level == 0),
/// document->options.document_width, document,
/// 0, 0, head.source, 1);
/* Drop empty allocated lines at end of document if any
* and adjust document height. */
while (document->height && !document->data[document->height - 1].length)
mem_free_if(document->data[--document->height].chars);
/* Calculate document width. */
{
int i;
document->width = 0;
for (i = 0; i < document->height; i++)
int_lower_bound(&document->width, document->data[i].length);
}
#if 1
document->options.needs_width = 1;
#else
/* FIXME: This needs more tuning since if we are centering stuff it
* does not work. */
document->options.needs_width =
(document->width + (document->options.margin
>= document->options.width));
#endif
document->color.background = par_elformat.color.background;
done_html_parser(html_context);
/* Drop forms which has been serving as a placeholder for form items
* added in the wrong order due to the ordering of table rendering. */
{
struct form *form;
foreach (form, document->forms) {
if (form->form_num)
continue;
if (list_empty(form->items))
done_form(form);
break;
}
}
/* @part was residing in html_context so it has to stay alive until
* done_html_parser(). */
done_string(&head);
mem_free_if(part);
#if 0 /* debug purpose */
{
FILE *f = fopen("forms", "ab");
struct el_form_control *form;
char *qq;
fprintf(f,"FORM:\n");
foreach (form, document->forms) {
fprintf(f, "g=%d f=%d c=%d t:%d\n",
form->g_ctrl_num, form->form_num,
form->ctrl_num, form->type);
}
fprintf(f,"fragment: \n");
for (qq = start; qq < end; qq++) fprintf(f, "%c", *qq);
fprintf(f,"----------\n\n");
fclose(f);
}
#endif
}

View File

@ -0,0 +1,19 @@
#ifndef EL__DOCUMENT_XML_RENDERER2_H
#define EL__DOCUMENT_XML_RENDERER2_H
#ifdef __cplusplus
extern "C" {
#endif
struct cache_entry;
struct document;
struct string;
void render_xhtml_document(struct cache_entry *cached, struct document *document, struct string *buffer);
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load Diff