⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 htmlgen.c

📁 用于linux和其他unix下面的
💻 C
📖 第 1 页 / 共 2 页
字号:
    }#endif /* USE_COLOR_STYLE */    me->preformatted = YES;	/* free text within tags */    HTMLGen_put_character(me, '<');    HTMLGen_put_string(me, tag->name);    if (present) {	BOOL had_attr = NO;	for (i = 0; i < tag->number_of_attributes; i++) {	    if (present[i]) {		had_attr = YES;		HTMLGen_put_character(me, ' ');		allow_break(me, 11, YES);#ifdef USE_COLOR_STYLE		/*		 *  Try to mimic HTML_start_element's special handling		 *  for HTML_LINK.  If applicable, color the displayed		 *  attribute / value pairs differently. - kw		 */		if (LYPreparsedSource &&		    element_number == HTML_LINK && !title &&		    present[HTML_LINK_CLASS] &&		    value && *value[HTML_LINK_CLASS]!='\0' &&		    !present[HTML_LINK_REV] &&		    (present[HTML_LINK_REL] || present[HTML_LINK_HREF])) {		    if (present[HTML_LINK_TITLE] && *value[HTML_LINK_TITLE]) {			StrAllocCopy(title, value[HTML_LINK_TITLE]);			LYTrimHead(title);			LYTrimTail(title);		    }		    if ((!title || *title=='\0') && present[HTML_LINK_REL]) {			StrAllocCopy(title, value[HTML_LINK_REL]);		    }		    if (title && *title) {			HTSprintf0(&title_tmp, "link.%s.%s",				   value[HTML_LINK_CLASS], title);			CTRACE2(TRACE_STYLE,				(tfp, "CSSTRIM:link=%s\n", title_tmp));			do_cstyle_flush(me);			HText_characterStyle(me->text, hash_code(title_tmp), 1);		    }		}#endif		HTMLGen_put_string(me, tag->attributes[i].name);		if (value[i]) {		    me->preformatted = was_preformatted;		    me->in_attrval = YES;		    if (strchr(value[i], '"') == NULL) {			HTMLGen_put_string(me, "=\"");			HTMLGen_put_string(me, value[i]);			HTMLGen_put_character(me, '"');		    } else if (strchr(value[i], '\'') == NULL) {			HTMLGen_put_string(me, "='");			HTMLGen_put_string(me, value[i]);			HTMLGen_put_character(me, '\'');		    } else {  /* attribute value has both kinds of quotes */			CONST char *p;			HTMLGen_put_string(me, "=\"");			for (p = value[i]; *p; p++) {			    if (*p != '"') {				HTMLGen_put_character(me, *p);			    } else {				HTMLGen_put_string(me, "&#34;");			    }			}			HTMLGen_put_character(me, '"');		    }		    me->preformatted = YES;		    me->in_attrval = NO;		}	    }	}#ifdef USE_COLOR_STYLE	if (had_attr && LYPreparsedSource && element_number == HTML_LINK) {	    /*	     *  Clean up after special HTML_LINK handling - kw	     */	    if (title && *title) {		do_cstyle_flush(me);		HText_characterStyle(me->text, hash_code(title_tmp), 0);		FREE(title_tmp);	    }	    FREE(title);	}#endif	if (had_attr)	    allow_break(me, 12, NO);    }    HTMLGen_put_string(me, ">"); /* got rid of \n LJM */    /*     *	Make very specific HTML assumption that PRE can't be nested!     */    me->preformatted = (element_number == HTML_PRE)  ? YES : was_preformatted;    /*     *	Can break after element start.     */    if (!me->preformatted && tag->contents != SGML_EMPTY) {	if (HTML_dtd.tags[element_number].contents == SGML_ELEMENT)	    allow_break(me, 15, NO);	else	    allow_break(me, 2, NO);    }#if defined(USE_COLOR_STYLE)    /*     *  Same logic as in HTML_start_element, copied from there. - kw     */    /* end really empty tags straight away */    if (LYPreparsedSource && ReallyEmptyTagNum(element_number))    {	CTRACE2(TRACE_STYLE,		(tfp, "STYLE:begin_element:ending EMPTY element style\n"));	do_cstyle_flush(me);	HText_characterStyle(me->text, hcode, STACK_OFF);	TrimColorClass(HTML_dtd.tags[element_number].name,		       Style_className, &hcode);    }#endif /* USE_COLOR_STYLE */    if (element_number == HTML_OBJECT && tag->contents == SGML_LITTERAL) {	/*	 *  These conditions only approximate the ones used in HTML.c.	 *  Let our SGML parser know that further content is to be parsed	 *  normally not literally. - kw	 */	if (!present) {	    return HT_PARSER_OTHER_CONTENT;	} else if (!present[HTML_OBJECT_DECLARE] &&		   !(present[HTML_OBJECT_NAME]  &&		     value[HTML_OBJECT_NAME] && *value[HTML_OBJECT_NAME])) {	    if (present[HTML_OBJECT_SHAPES] ||		!(present[HTML_OBJECT_USEMAP] &&		  value[HTML_OBJECT_USEMAP] && *value[HTML_OBJECT_USEMAP]))		return HT_PARSER_OTHER_CONTENT;	}    }    return HT_OK;}/*		End Element**		-----------***//*	When we end an element, the style must be returned to that**	in effect before that element.	Note that anchors (etc?)**	don't have an associated style, so that we must scan down the**	stack for an element with a defined style. (In fact, the styles**	should be linked to the whole stack not just the top one.)**	TBL 921119*/PRIVATE int HTMLGen_end_element ARGS3(	HTStructured *,		me,	int,			element_number,	char **,		insert GCC_UNUSED){    if (!me->preformatted &&	HTML_dtd.tags[element_number].contents != SGML_EMPTY) {	/*	 *  Can break before element end.	 */	if (HTML_dtd.tags[element_number].contents == SGML_ELEMENT)	    allow_break(me, 14, NO);	else	    allow_break(me, 1, NO);    }    HTMLGen_put_string(me, "</");    HTMLGen_put_string(me, HTML_dtd.tags[element_number].name);    HTMLGen_put_character(me, '>');    if (element_number == HTML_PRE) {	me->preformatted = NO;    }#ifdef USE_COLOR_STYLE    /*     *  Same logic as in HTML_end_element, copied from there. - kw     */    TrimColorClass(HTML_dtd.tags[element_number].name,		   Style_className, &hcode);    if (LYPreparsedSource && !ReallyEmptyTagNum(element_number)) {	CTRACE2(TRACE_STYLE,		(tfp, "STYLE:end_element: ending non-EMPTY style\n"));	do_cstyle_flush(me);	HText_characterStyle(me->text, hcode, STACK_OFF);    }#endif /* USE_COLOR_STYLE */    return HT_OK;}/*		Expanding entities**		------------------***/PRIVATE int HTMLGen_put_entity ARGS2(	HTStructured *,		me,	int,			entity_number){    int nent = HTML_dtd.number_of_entities;    HTMLGen_put_character(me, '&');    if (entity_number < nent) {      HTMLGen_put_string(me, HTML_dtd.entity_names[entity_number]);    }    HTMLGen_put_character(me, ';');    return HT_OK;}/*	Free an HTML object**	-------------------***/PRIVATE void HTMLGen_free ARGS1(	HTStructured *,		me){    (*me->targetClass.put_character)(me->target, '\n');    HTMLGen_flush(me);    (*me->targetClass._free)(me->target);	/* ripple through */#ifdef USE_COLOR_STYLE    FREE(Style_className);#endif    FREE(me);}PRIVATE void PlainToHTML_free ARGS1(	HTStructured *,		me){    HTMLGen_end_element(me, HTML_PRE, 0);    HTMLGen_free(me);}PRIVATE void HTMLGen_abort ARGS2(	HTStructured *,		me,	HTError,		e GCC_UNUSED){    HTMLGen_free(me);#ifdef USE_COLOR_STYLE    FREE(Style_className);#endif}PRIVATE void PlainToHTML_abort ARGS2(	HTStructured *,		me,	HTError,		e GCC_UNUSED){    PlainToHTML_free(me);}/*	Structured Object Class**	-----------------------*/PRIVATE CONST HTStructuredClass HTMLGeneration = /* As opposed to print etc */{	"HTMLGen",	HTMLGen_free,	HTMLGen_abort,	HTMLGen_put_character,	HTMLGen_put_string, HTMLGen_write,	HTMLGen_start_element,	HTMLGen_end_element,	HTMLGen_put_entity};/*	Subclass-specific Methods**	-------------------------*/extern int LYcols;			/* LYCurses.h, set in LYMain.c	*/PUBLIC HTStructured * HTMLGenerator ARGS1(	HTStream *,		output){    HTStructured* me = (HTStructured*)malloc(sizeof(*me));    if (me == NULL)	outofmem(__FILE__, "HTMLGenerator");    me->isa = &HTMLGeneration;    me->target = output;    me->targetClass = *me->target->isa; /* Copy pointers to routines for speed*/    me->write_pointer = me->buffer;    flush_breaks(me);    me->line_break[0] = me->buffer;    me->cleanness =	0;    me->overflowed = NO;    me->delete_line_break_char[0] = NO;    me->preformatted =	NO;    me->in_attrval = NO;    /*     *	For what line length should we attempt to wrap ? - kw     */    if (!LYPreparsedSource) {	me->buffer_maxchars = 80; /* work as before - kw */    } else if (dump_output_width > 1) {	me->buffer_maxchars = dump_output_width; /* try to honor -width - kw */    } else if (dump_output_immediately) {	me->buffer_maxchars = 80; /* try to honor -width - kw */    } else {	me->buffer_maxchars = LYcols - 2;	if (me->buffer_maxchars < 38) /* too narrow, let GridText deal */	    me->buffer_maxchars = 40;    }    if (me->buffer_maxchars > 900) /* likely not true - kw */	me->buffer_maxchars = 78;    if (me->buffer_maxchars > BUFFER_SIZE) /* must not be larger! */	me->buffer_maxchars = BUFFER_SIZE - 2;    /*     *	If dump_output_immediately is set, there likely isn't anything     *	after this stream to interpret the Lynx special chars.	Also     *	if they get displayed via HTPlain, that will probably make     *	non-breaking space chars etc. invisible.  So let's translate     *	them to numerical character references.  For debugging     *	purposes we'll use the new hex format.     */    me->escape_specials = LYPreparsedSource;#ifdef USE_COLOR_STYLE    me->text = NULL;	/* Will be initialized when first needed. - kw */    FREE(Style_className);    class_string[0] = '\0';#endif /* COLOR_STYLE */    return me;}/*	Stream Object Class**	-------------------****	This object just converts a plain text stream into HTML**	It is officially a structured strem but only the stream bits exist.**	This is just the easiest way of typecasting all the routines.*/PRIVATE CONST HTStructuredClass PlainToHTMLConversion ={	"plaintexttoHTML",	HTMLGen_free,	PlainToHTML_abort,	HTMLGen_put_character,	HTMLGen_put_string,	HTMLGen_write,	NULL,		/* Structured stuff */	NULL,	NULL};/*	HTConverter from plain text to HTML Stream**	------------------------------------------*/PUBLIC HTStream* HTPlainToHTML ARGS3(	HTPresentation *,	pres GCC_UNUSED,	HTParentAnchor *,	anchor GCC_UNUSED,	HTStream *,		sink){    HTStructured *me = (HTStructured *)malloc(sizeof(*me));    if (me == NULL)	outofmem(__FILE__, "PlainToHTML");    me->isa = (CONST HTStructuredClass *)&PlainToHTMLConversion;    /*     *	Copy pointers to routines for speed.     */    me->target = sink;    me->targetClass = *me->target->isa;    me->write_pointer = me->buffer;    flush_breaks(me);    me->cleanness =	0;    me->overflowed = NO;    me->delete_line_break_char[0] = NO;    /* try to honor -width - kw */    me->buffer_maxchars = (dump_output_width > 1 ?			   dump_output_width : 80);    HTMLGen_put_string(me, "<HTML>\n<BODY>\n<PRE>\n");    me->preformatted = YES;    me->escape_specials = NO;    me->in_attrval = NO;    return (HTStream*) me;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -