Beispiel #1
0
/*
  push a copy of an inline node onto stack
  but don't push if implicit or OBJECT or APPLET
  (implicit tags are ones generated from the istack)

  One issue arises with pushing inlines when
  the tag is already pushed. For instance:

      <p><em>text
      <p><em>more text

  Shouldn't be mapped to

      <p><em>text</em></p>
      <p><em><em>more text</em></em>
*/
void PushInline( TidyDocImpl* doc, Node *node )
{
    Lexer* lexer = doc->lexer;
    IStack *istack;

    if (node->implicit)
        return;

    if ( !IsNodePushable(node) )
        return;

    if ( !nodeIsFONT(node) && IsPushed(doc, node) )
        return;

    /* make sure there is enough space for the stack */
    if (lexer->istacksize + 1 > lexer->istacklength)
    {
        if (lexer->istacklength == 0)
            lexer->istacklength = 6;   /* this is perhaps excessive */

        lexer->istacklength = lexer->istacklength * 2;
        lexer->istack = (IStack *)MemRealloc(lexer->istack,
                            sizeof(IStack)*(lexer->istacklength));
    }

    istack = &(lexer->istack[lexer->istacksize]);
    istack->tag = node->tag;

    istack->element = tmbstrdup(node->element);
    istack->attributes = DupAttrs( doc, node->attributes );
    ++(lexer->istacksize);
}
Beispiel #2
0
static void declare( TidyTagImpl* tags,
                     ctmbstr name, uint versions, uint model, 
                     Parser *parser, CheckAttribs *chkattrs )
{
    if ( name )
    {
        Dict* np = (Dict*) lookup( tags, name );
        if ( np == null )
        {
            np = (Dict*) MemAlloc( sizeof(Dict) );
            ClearMemory( np, sizeof(Dict) );

            np->name = tmbstrdup( name );
            np->next = tags->declared_tag_list;
            tags->declared_tag_list = np;
        }

        /* Make sure we are not over-writing predefined tags */
        if ( np->id == TidyTag_UNKNOWN )
        {
          np->versions = versions;
          np->model   |= model;
          np->parser   = parser;
          np->chkattrs = chkattrs;
        }
    }
}
Beispiel #3
0
static void ReparseTagType( TidyDocImpl* doc, TidyOptionId optId )
{
    ctmbstr tagdecl = cfgStr( doc, optId );
    tmbstr dupdecl = tmbstrdup( tagdecl );
    ParseConfigValue( doc, optId, dupdecl );
    MemFree( dupdecl );
}
Beispiel #4
0
/* duplicate attributes */
AttVal *DupAttrs( TidyDocImpl* doc, AttVal *attrs)
{
    AttVal *newattrs;

    if (attrs == NULL)
        return attrs;

    newattrs = NewAttribute();
    *newattrs = *attrs;
    newattrs->next = DupAttrs( doc, attrs->next );
    newattrs->attribute = tmbstrdup(attrs->attribute);
    newattrs->value = tmbstrdup(attrs->value);
    newattrs->dict = FindAttribute(doc, newattrs);
    newattrs->asp = attrs->asp ? CloneNode(doc, attrs->asp) : NULL;
    newattrs->php = attrs->php ? CloneNode(doc, attrs->php) : NULL;
    return newattrs;
}
Beispiel #5
0
Node *InsertedToken( TidyDocImpl* doc )
{
    Lexer* lexer = doc->lexer;
    Node *node;
    IStack *istack;
    uint n;

    /* this will only be NULL if inode != NULL */
    if (lexer->insert == NULL)
    {
        node = lexer->inode;
        lexer->inode = NULL;
        return node;
    }

    /*
    
      is this is the "latest" node then update
      the position, otherwise use current values
    */

    if (lexer->inode == NULL)
    {
        lexer->lines = doc->docIn->curline;
        lexer->columns = doc->docIn->curcol;
    }

    node = NewNode(lexer);
    node->type = StartTag;
    node->implicit = yes;
    node->start = lexer->txtstart;
    /* #431734 [JTidy bug #226261 (was 126261)] - fix by Gary Peskin 20 Dec 00 */ 
    node->end = lexer->txtend; /* was : lexer->txtstart; */
    istack = lexer->insert;

#if 0 && defined(_DEBUG)
    if ( lexer->istacksize == 0 )
        fprintf( stderr, "0-size istack!\n" );
#endif

    node->element = tmbstrdup(istack->element);
    node->tag = istack->tag;
    node->attributes = DupAttrs( doc, istack->attributes );

    /* advance lexer to next item on the stack */
    n = (uint)(lexer->insert - &(lexer->istack[0]));

    /* and recover state if we have reached the end */
    if (++n < lexer->istacksize)
        lexer->insert = &(lexer->istack[n]);
    else
        lexer->insert = NULL;

    return node;
}
Beispiel #6
0
Bool SetOptionValue( TidyDocImpl* doc, TidyOptionId optId, ctmbstr val )
{
   const TidyOptionImpl* option = &option_defs[ optId ];
   Bool status = ( optId < N_TIDY_OPTIONS );
   if ( status )
   {
      assert( option->id == optId && option->type == TidyString );
      FreeOptionValue( option, &doc->config.value[ optId ] );
      doc->config.value[ optId ].p = tmbstrdup( val );
   }
   return status;
}
Beispiel #7
0
static void CopyOptionValue( const TidyOptionImpl* option,
                             TidyOptionValue* oldval, const TidyOptionValue* newval )
{
    assert( oldval != NULL );
    FreeOptionValue( option, oldval );

    if ( option->type == TidyString )
    {
        if ( newval->p && newval->p != option->pdflt )
            oldval->p = tmbstrdup( newval->p );
        else
            oldval->p = newval->p;
    }
    else
        oldval->v = newval->v;
}
Beispiel #8
0
void CheckTABLE( TidyDocImpl* doc, Node *node )
{
    Bool HasSummary = no;
    AttVal *attval;

    for (attval = node->attributes; attval != null; attval = attval->next)
    {
        const Attribute* dict = CheckAttribute( doc, node, attval );
        if ( dict && dict->id == TidyAttr_SUMMARY )
            HasSummary = yes;
    }

    /* suppress warning for missing summary for HTML 2.0 and HTML 3.2 */
    if ( cfg(doc, TidyAccessibilityCheckLevel) == 0 )
    {
        Lexer* lexer = doc->lexer;
        if ( !HasSummary 
             && lexer->doctype != VERS_HTML20
             && lexer->doctype != VERS_HTML32 )
        {
            doc->badAccess |= MISSING_SUMMARY;
            ReportMissingAttr( doc, node, "summary");
        }
    }

    /* convert <table border> to <table border="1"> */
    if ( cfgBool(doc, TidyXmlOut) && (attval = GetAttrByName(node, "border")) )
    {
        if (attval->value == null)
            attval->value = tmbstrdup("1");
    }

    /* <table height="..."> is proprietary */
    if ( attval = GetAttrByName(node, "height") )
    {
        ReportAttrError( doc, node, attval, PROPRIETARY_ATTRIBUTE );
        ConstrainVersion( doc, VERS_PROPRIETARY );
    }
}