📄 html.c
字号:
HText_endAnchor(me->text, 0); LYEnsureSingleSpace(me); } else { CHECK_ID(HTML_IFRAME_ID); } FREE(id_string); break; case HTML_BANNER: case HTML_MARQUEE: change_paragraph_style(me, styles[HTML_BANNER]); UPDATE_STYLE; if (me->sp->tag_number == ElementNumber) LYEnsureDoubleSpace(me); /* * Treat this as a toolbar if we don't have one * yet, and we are in the first half of the * first page. - FM */ if ((!HText_hasToolbar(me->text) && HText_getLines(me->text) < (display_lines/2)) && (ID_A = HTAnchor_findChildAndLink( me->node_anchor, /* Parent */ LYToolbarName, /* Tag */ NULL, /* Addresss */ (HTLinkType*)0))) { /* Type */ HText_beginAnchor(me->text, me->inUnderline, ID_A); HText_endAnchor(me->text, 0); HText_setToolbar(me->text); } CHECK_ID(HTML_GEN_ID); break; case HTML_CENTER: case HTML_DIV: if (me->Division_Level < (MAX_NESTING - 1)) { me->Division_Level++; } else if (TRACE) { fprintf(stderr, "HTML: ****** Maximum nesting of %d divisions exceeded!\n", MAX_NESTING); } if (ElementNumber == HTML_CENTER) { me->DivisionAlignments[me->Division_Level] = HT_CENTER; change_paragraph_style(me, styles[HTML_DCENTER]); UPDATE_STYLE; me->current_default_alignment = styles[HTML_DCENTER]->alignment; } else if (present && present[HTML_DIV_ALIGN] && value[HTML_DIV_ALIGN] && *value[HTML_DIV_ALIGN]) { if (!strcasecomp(value[HTML_DIV_ALIGN], "center")) { me->DivisionAlignments[me->Division_Level] = HT_CENTER; change_paragraph_style(me, styles[HTML_DCENTER]); UPDATE_STYLE; me->current_default_alignment = styles[HTML_DCENTER]->alignment; } else if (!strcasecomp(value[HTML_DIV_ALIGN], "right")) { me->DivisionAlignments[me->Division_Level] = HT_RIGHT; change_paragraph_style(me, styles[HTML_DRIGHT]); UPDATE_STYLE; me->current_default_alignment = styles[HTML_DRIGHT]->alignment; } else { me->DivisionAlignments[me->Division_Level] = HT_LEFT; change_paragraph_style(me, styles[HTML_DLEFT]); UPDATE_STYLE; me->current_default_alignment = styles[HTML_DLEFT]->alignment; } } else { me->DivisionAlignments[me->Division_Level] = HT_LEFT; change_paragraph_style(me, styles[HTML_DLEFT]); UPDATE_STYLE; me->current_default_alignment = styles[HTML_DLEFT]->alignment; } CHECK_ID(HTML_DIV_ID); break; case HTML_H1: case HTML_H2: case HTML_H3: case HTML_H4: case HTML_H5: case HTML_H6: /* * Close the previous style if not done by HTML doc. * Added to get rid of core dumps in BAD HTML on the net. * GAB 07-07-94 * But then again, these are actually allowed to nest. I guess * I have to depend on the HTML writers correct style. * GAB 07-12-94 if (i_prior_style != -1) { HTML_end_element(me, i_prior_style); } i_prior_style = ElementNumber; */ /* * Check whether we have an H# in a list, * and if so, treat it as an LH. - FM */ if ((me->List_Nesting_Level >= 0) && (me->sp[0].tag_number == HTML_UL || me->sp[0].tag_number == HTML_OL || me->sp[0].tag_number == HTML_MENU || me->sp[0].tag_number == HTML_DIR)) { if (HTML_dtd.tags[HTML_LH].contents == SGML_EMPTY) { ElementNumber = HTML_LH; } else { me->new_style = me->sp[0].style; ElementNumber = me->sp[0].tag_number; UPDATE_STYLE; } /* * Some authors use H# headers as a substitute for * FONT, so check if this one immediately followed * an LI. If so, both me->inP and me->in_word will * be FALSE (though the line might not be empty due * to a bullet and/or nbsp) and we can assume it is * just for a FONT change. We thus will not create * another line break nor add to the current left * indentation. - FM */ if (!(me->inP == FALSE && me->in_word == NO)) { HText_appendParagraph(me->text); HTML_put_character(me, HT_NON_BREAK_SPACE); HText_setLastChar(me->text, ' '); me->in_word = NO; me->inP = FALSE; } CHECK_ID(HTML_H_ID); break; } if (present && present[HTML_H_ALIGN] && value[HTML_H_ALIGN] && *value[HTML_H_ALIGN]) { if (!strcasecomp(value[HTML_H_ALIGN], "center")) change_paragraph_style(me, styles[HTML_HCENTER]); else if (!strcasecomp(value[HTML_H_ALIGN], "right")) change_paragraph_style(me, styles[HTML_HRIGHT]); else if (!strcasecomp(value[HTML_H_ALIGN], "left") || !strcasecomp(value[HTML_H_ALIGN], "justify")) change_paragraph_style(me, styles[HTML_HLEFT]); else change_paragraph_style(me, styles[ElementNumber]); } else if (me->Division_Level >= 0) { if (me->DivisionAlignments[me->Division_Level] == HT_CENTER) { change_paragraph_style(me, styles[HTML_HCENTER]); } else if (me->DivisionAlignments[me->Division_Level] == HT_LEFT) { change_paragraph_style(me, styles[HTML_HLEFT]); } else if (me->DivisionAlignments[me->Division_Level] == HT_RIGHT) { change_paragraph_style(me, styles[HTML_HRIGHT]); } } else { change_paragraph_style(me, styles[ElementNumber]); } UPDATE_STYLE; CHECK_ID(HTML_H_ID); if ((bold_headers == TRUE || (ElementNumber == HTML_H1 && bold_H1 == TRUE)) && (styles[ElementNumber]->font&HT_BOLD)) { if (me->inBoldA == FALSE && me->inBoldH == FALSE) { HText_appendCharacter(me->text, LY_BOLD_START_CHAR); } me->inBoldH = TRUE; } break; case HTML_P: LYHandleP(me, present, value, (char **)&include, TRUE); break; case HTML_BR: UPDATE_STYLE; CHECK_ID(HTML_GEN_ID); if ((LYCollapseBRs == FALSE) || HText_LastLineSize(me->text, FALSE)) { HText_setLastChar(me->text, ' '); /* absorb white space */ HText_appendCharacter(me->text, '\r'); } me->in_word = NO; me->inP = FALSE; break; case HTML_WBR: UPDATE_STYLE; CHECK_ID(HTML_GEN_ID); HText_setBreakPoint(me->text); break; case HTML_HY: case HTML_SHY: UPDATE_STYLE; CHECK_ID(HTML_GEN_ID); HText_appendCharacter(me->text, LY_SOFT_HYPHEN); break; case HTML_HR: { int width; /* * Start a new line only if we had printable * characters following the previous newline, * or remove the previous line if both it and * the last line are blank. - FM */ UPDATE_STYLE; if (HText_LastLineSize(me->text, FALSE)) { HText_setLastChar(me->text, ' '); /* absorb white space */ HText_appendCharacter(me->text, '\r'); } else if (!HText_PreviousLineSize(me->text, FALSE)) { HText_RemovePreviousLine(me->text); } me->in_word = NO; me->inP = FALSE; /* * Add an ID link if needed. - FM */ CHECK_ID(HTML_HR_ID); /* * Center lines within the current margins, if * a right or left ALIGNment is not specified. * If WIDTH="#%" is given and not garbage, * use that to calculate the width, otherwise * use the default width. - FM */ if (present && present[HTML_HR_ALIGN] && value[HTML_HR_ALIGN]) { if (!strcasecomp(value[HTML_HR_ALIGN], "right")) { me->sp->style->alignment = HT_RIGHT; } else if (!strcasecomp(value[HTML_HR_ALIGN], "left")) { me->sp->style->alignment = HT_LEFT; } else { me->sp->style->alignment = HT_CENTER; } } else { me->sp->style->alignment = HT_CENTER; } width = LYcols - 1 - me->new_style->leftIndent - me->new_style->rightIndent; if (present && present[HTML_HR_WIDTH] && value[HTML_HR_WIDTH] && isdigit(*value[HTML_HR_WIDTH]) && value[HTML_HR_WIDTH][strlen(value[HTML_HR_WIDTH])-1] == '%') { char *percent = NULL; int Percent, Width; StrAllocCopy(percent, value[HTML_HR_WIDTH]); percent[strlen(percent)-1] = '\0'; Percent = atoi(percent); if (Percent > 100 || Percent < 1) width -= 5; else { Width = (width * Percent) / 100; if (Width < 1) width = 1; else width = Width; } FREE(percent); } else { width -= 5; } for (i = 0; i < width; i++) HTML_put_character(me, '_'); HText_appendCharacter(me->text, '\r'); me->in_word = NO; me->inP = FALSE; /* * Reset the alignment appropriately * for the division and/or block. - FM */ if (me->List_Nesting_Level < 0 && me->Division_Level >= 0) { me->sp->style->alignment = me->DivisionAlignments[me->Division_Level]; } else if (!strcmp(me->sp->style->name, "HeadingCenter") || !strcmp(me->sp->style->name, "Heading1")) { me->sp->style->alignment = HT_CENTER; } else if (!strcmp(me->sp->style->name, "HeadingRight")) { me->sp->style->alignment = HT_RIGHT; } else { me->sp->style->alignment = HT_LEFT; } /* * Add a blank line and set the second line * indentation for lists and addresses, or a * paragraph separator for other blocks. - FM */ if (me->List_Nesting_Level >= 0 || me->sp[0].tag_number == HTML_ADDRESS) { HText_setLastChar(me->text, ' '); /* absorb white space */ HText_appendCharacter(me->text, '\r'); } else { HText_appendParagraph(me->text); } } break; case HTML_TAB: if (!present) { /* Bad tag. Must have at least one attribute. - FM */ if (TRACE) fprintf(stderr, "HTML: TAB tag has no attributes. Ignored.\n"); break; } UPDATE_STYLE; if (present[HTML_TAB_ALIGN] && value[HTML_TAB_ALIGN] && (strcasecomp(value[HTML_TAB_ALIGN], "left") || !(present[HTML_TAB_TO] || present[HTML_TAB_INDENT]))) { /* * Just ensure a collapsible space, until we have * the ALIGN and DP attributes implemented. - FM */ HTML_put_character(me, ' '); if (TRACE) fprintf(stderr, "HTML: ALIGN not 'left'. Using space instead of TAB.\n"); } else if (!LYoverride_default_alignment(me) && me->current_default_alignment != HT_LEFT) { /* * Just ensure a collapsible space, until we * can replace HText_getCurrentColumn() in * GridText.c with code which doesn't require * that the alignment be HT_LEFT. - FM */ HTML_put_character(me, ' '); if (TRACE) fprintf(stderr, "HTML: Not HT_LEFT. Using space instead of TAB.\n"); } else if ((present[HTML_TAB_TO] && value[HTML_TAB_TO] && *value[HTML_TAB_TO]) || (present[HTML_TAB_INDENT] && value[HTML_TAB_INDENT] && isdigit(*value[HTML_TAB_INDENT]))) { int column, target = -1; int enval = 2; column = HText_getCurrentColumn(me->text); if (present[HTML_TAB_TO]) { /* * TO has priority over INDENT if both are present. - FM */ StrAllocCopy(temp, value[HTML_TAB_TO]); TRANSLATE_AND_UNESCAPE_TO_STD(&temp); if (*temp) { target = HText_getTabIDColumn(me->text, temp); } } else if (!(temp && *temp) && present[HTML_TAB_INDENT] && value[HTML_TAB_INDENT] && isdigit(*value[HTML_TAB_INDENT])) { /* * The INDENT value is in "en" (enval per column) units. * Divide it by enval, rounding odd values up. - FM */ target = (int)(((1.0 * atoi(value[HTML_TAB_INDENT]))/enval)+(0.5)); } FREE(temp); /* * If we are being directed to a column too far to the left * or right, just add a collapsible space, otherwise, add the * appropriate number of spaces. - FM */ if (target < column || target > HText_getMaximumColumn(me->text)) { HTML_put_character(me, ' '); if (TRACE) fprintf(stderr, "HTML: Column out of bounds. Using space instead of TAB.\n"); } else { for (i = column; i < target; i++) HText_appendCharacter(me->text, ' '); HText_setLastChar(me->text, ' '); /* absorb white space */ } } me->in_word = NO; /* * If we have an ID attribute, save it together * with the value of the column we've reached. - FM */ if (present[HTML_TAB_ID] && value[HTML_TAB_ID] && *value[HTML_TAB_ID]) { StrAllocCopy(temp, value[HTML_TAB_ID]); TRANSLATE_AND_UNESCAPE_TO_STD(&temp); if (*temp) HText_setTabID(me->text, temp); FREE(temp); } break; case HTML_BASEFONT: break; case HTML_FONT: /* * FONT *may* have been declared SGML_EMPTY in HTMLDTD.c, and * SGML_character() in SGML.c *may* check for a FONT end * tag to call HTML_end_element() directly (with a * check in that to bypass decrementing of the HTML * parser's stack). Or this may have been really a </FONT> * end tag, for which some incarnations of SGML.c would fake * a <FONT> start tag instead. - fm & kw * * But if we have an open FONT, DON'T close that one now, * since FONT tags can be legally nested AFAIK, and Lynx * currently doesn't do anything with them anyway... - kw */#ifdef NOTUSED_FOTEMODS if (me->inFONT == TRUE) HTML_end_element(me, HTML_FONT, (char **)&include);#endif /* NOTUSED_FOTEMODS */ /* * Set flag to know we are in a FONT container, and * add code to do something about it, someday. - FM */ me->inFONT = TRUE; break; case HTML_B: /* Physical character highlighting */ case HTML_BLINK: case HTML_I: case HTML_U: case HTML_CITE: /* Logical character highlighting */ case HTML_EM: case HTML_STRONG: UPDATE_STYLE; me->Underline_Level++; CHECK_ID(HTML_GEN_ID); /* * Ignore this if inside of a bold anchor or header. * Can't display both underline and bold at same time. */ if (me->inBoldA == TRUE || me->inBoldH == TRUE) { if (TRACE) fprintf(stderr,"Underline Level is %d\n", me->Underline_Level); break; } if (me->inUnderline == FALSE) { HText_appendCharacter(me->text, LY_UNDERLINE_START_CHAR); me->inUnderline = TRUE; if (TRACE) fprintf(stderr,"Beginning underline\n"); } else { if (TRACE) fprintf(stderr,"Underline Level is %d\n", me->Underline_Level); } break; case HTML_ABBREV: /* Miscellaneous character containers */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -