preformatted;
HTTag * tag = &HTML_dtd.tags[element_number];
me->preformatted = NO; /* free text within tags */
HTMLGen_put_character(me, '<');
HTMLGen_put_string(me, tag->name);
if (present) for (i=0; i< tag->number_of_attributes; i++) {
if (present[i]) {
HTMLGen_put_character(me, ' ');
HTMLGen_put_string(me, tag->attributes[i].name);
if (value[i]) {
HTMLGen_put_string(me, "=\"");
HTMLGen_put_string(me, value[i]);
HTMLGen_put_character(me, '"');
}
}
}
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) {
me->line_break = me->write_pointer; /* Don't you hate SGML? */
me->cleanness = 1;
me->delete_line_break_char = NO;
}
}
/* 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 void HTMLGen_end_element ARGS3(HTStructured *, me,
int , element_number, char **, insert)
{
if (!me->preformatted &&
HTML_dtd.tags[element_number].contents != SGML_EMPTY) {
/* can break before element end */
me->line_break = me->write_pointer; /* Don't you hate SGML? */
me->cleanness = 1;
me->delete_line_break_char = 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;
}
/* Expanding entities
** ------------------
**
*/
PRIVATE void HTMLGen_put_entity ARGS2(HTStructured *, me, int, entity_number)
{
HTMLGen_put_character(me, '&');
HTMLGen_put_string(me, HTML_dtd.entity_names[entity_number]);
HTMLGen_put_character(me, ';');
}
/* 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 */
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)
{
HTMLGen_free(me);
}
PRIVATE void PlainToHTML_abort ARGS2(HTStructured *, me, HTError, e)
{
PlainToHTML_free(me);
}
/* Structured Object Class
** -----------------------
*/
PRIVATE CONST HTStructuredClass HTMLGeneration = /* As opposed to print etc */
{
"text/html",
HTMLGen_free,
HTMLGen_abort,
HTMLGen_put_character, HTMLGen_put_string, HTMLGen_write,
HTMLGen_start_element, HTMLGen_end_element,
HTMLGen_put_entity
};
/* Subclass-specific Methods
** -------------------------
*/
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;
me->line_break = me->buffer;
me->cleanness = 0;
me->delete_line_break_char = NO;
me->preformatted = NO;
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,
HTParentAnchor *, anchor,
HTStream *, sink)
{
HTStructured* me = (HTStructured*)malloc(sizeof(*me));
if (me == NULL)
outofmem(__FILE__, "PlainToHTML");
me->isa = (HTStructuredClass*) &PlainToHTMLConversion;
me->target = sink;
me->targetClass = *me->target->isa;
/* Copy pointers to routines for speed*/
HTMLGen_put_string(me, "\n\n\n");
me->preformatted = YES;
return (HTStream*) me;
}