/** * Provides a string given `messageType` in the current * localization, in the non-plural form. * * This isn't currently highly optimized; rewriting some * of infrastructure to use hash lookups is a preferred * future optimization. */ ctmbstr TY_(tidyLocalizedString)( uint messageType ) { return TY_(tidyLocalizedStringN)( messageType, 1 ); }
ctmbstr TY_(ReleaseDate)(void) { return TY_(release_date); }
void TY_(ReportAttrError)(TidyDocImpl* doc, Node *node, AttVal *av, uint code) { char const *name = "NULL", *value = "NULL"; char tagdesc[64]; ctmbstr fmt = tidyLocalizedString(code); uint version; ctmbstr extra_string; assert( fmt != NULL ); TagToString(node, tagdesc, sizeof(tagdesc)); if (av) { if (av->attribute) name = av->attribute; if (av->value) value = av->value; } switch (code) { case UNKNOWN_ATTRIBUTE: case INSERTING_ATTRIBUTE: case MISSING_ATTR_VALUE: case XML_ATTRIBUTE_VALUE: case PROPRIETARY_ATTRIBUTE: case JOINING_ATTRIBUTE: messageNode(doc, TidyWarning, code, node, fmt, tagdesc, name); break; case MISMATCHED_ATTRIBUTE_WARN: version = doc->lexer->versionEmitted == 0 ? doc->lexer->doctype : doc->lexer->versionEmitted; extra_string = TY_(HTMLVersionNameFromCode)(version, 0); if (!extra_string) extra_string = tidyLocalizedString(STRING_HTML_PROPRIETARY); messageNode(doc, TidyWarning, code, node, fmt, tagdesc, name, extra_string); break; case MISMATCHED_ATTRIBUTE_ERROR: version = doc->lexer->versionEmitted == 0 ? doc->lexer->doctype : doc->lexer->versionEmitted; extra_string = TY_(HTMLVersionNameFromCode)(version, 0); if (!extra_string) extra_string = tidyLocalizedString(STRING_HTML_PROPRIETARY); messageNode(doc, TidyError, code, node, fmt, tagdesc, name, extra_string); break; case BAD_ATTRIBUTE_VALUE: case BAD_ATTRIBUTE_VALUE_REPLACED: case INVALID_ATTRIBUTE: case INSERTING_AUTO_ATTRIBUTE: messageNode(doc, TidyWarning, code, node, fmt, tagdesc, name, value); break; case UNEXPECTED_QUOTEMARK: case MISSING_QUOTEMARK: case ID_NAME_MISMATCH: case BACKSLASH_IN_URI: case FIXED_BACKSLASH: case ILLEGAL_URI_REFERENCE: case ESCAPED_ILLEGAL_URI: case NEWLINE_IN_URI: case WHITE_IN_URI: case UNEXPECTED_GT: case INVALID_XML_ID: case UNEXPECTED_EQUALSIGN: messageNode(doc, TidyWarning, code, node, fmt, tagdesc); break; case XML_ID_SYNTAX: case PROPRIETARY_ATTR_VALUE: case ANCHOR_NOT_UNIQUE: case ATTR_VALUE_NOT_LCASE: messageNode(doc, TidyWarning, code, node, fmt, tagdesc, value); break; case MISSING_IMAGEMAP: messageNode(doc, TidyWarning, code, node, fmt, tagdesc); doc->badAccess |= BA_MISSING_IMAGE_MAP; break; case REPEATED_ATTRIBUTE: messageNode(doc, TidyWarning, code, node, fmt, tagdesc, value, name); break; case UNEXPECTED_END_OF_FILE_ATTR: /* on end of file adjust reported position to end of input */ doc->lexer->lines = doc->docIn->curline; doc->lexer->columns = doc->docIn->curcol; messageLexer(doc, TidyWarning, code, fmt, tagdesc); break; } }
Bool TY_(nodeCMIsBlock)( Node* node ) { return TY_(nodeHasCM)( node, CM_BLOCK ); }
Bool TY_(nodeCMIsEmpty)( Node* node ) { return TY_(nodeHasCM)( node, CM_EMPTY ); }
/* Many users do not call tidyBufInit() or tidyBufAlloc() or their allocator counterparts. So by default, set the default allocator. */ static void setDefaultAllocator( TidyBuffer* buf ) { buf->allocator = &TY_(g_default_allocator); }
void CheckHTML( TidyDocImpl* doc, Node *node ) { TY_(CheckAttributes)(doc, node); }
int TY_(DocParseStream)( TidyDocImpl* doc, StreamIn* in ) { Bool xmlIn = cfgBool( doc, TidyXmlTags ); int bomEnc; assert( doc != NULL && in != NULL ); assert( doc->docIn == NULL ); doc->docIn = in; TY_(TakeConfigSnapshot)( doc ); /* Save config state */ TY_(FreeLexer)( doc ); TY_(FreeAnchors)( doc ); TY_(FreeNode)(doc, &doc->root); TidyClearMemory(&doc->root, sizeof(Node)); if (doc->givenDoctype) TidyDocFree(doc, doc->givenDoctype); doc->givenDoctype = NULL; doc->lexer = TY_(NewLexer)( doc ); /* doc->lexer->root = &doc->root; */ doc->root.line = doc->lexer->lines; doc->root.column = doc->lexer->columns; doc->inputHadBOM = no; bomEnc = TY_(ReadBOMEncoding)(in); if (bomEnc != -1) { in->encoding = bomEnc; TY_(SetOptionInt)(doc, TidyInCharEncoding, bomEnc); } #ifdef TIDY_WIN32_MLANG_SUPPORT if (in->encoding > WIN32MLANG) TY_(Win32MLangInitInputTranscoder)(in, in->encoding); #endif /* TIDY_WIN32_MLANG_SUPPORT */ /* Tidy doesn't alter the doctype for generic XML docs */ if ( xmlIn ) { TY_(ParseXMLDocument)( doc ); if ( !TY_(CheckNodeIntegrity)( &doc->root ) ) TidyPanic( doc->allocator, integrity ); } else { doc->warnings = 0; TY_(ParseDocument)( doc ); if ( !TY_(CheckNodeIntegrity)( &doc->root ) ) TidyPanic( doc->allocator, integrity ); } #ifdef TIDY_WIN32_MLANG_SUPPORT TY_(Win32MLangUninitInputTranscoder)(in); #endif /* TIDY_WIN32_MLANG_SUPPORT */ doc->docIn = NULL; return tidyDocStatus( doc ); }
TidyDoc TIDY_CALL tidyCreate(void) { TidyDocImpl* impl = tidyDocCreate( &TY_(g_default_allocator) ); return tidyImplToDoc( impl ); }
/* tagask.c -- Interrogate node type (c) 1998-2006 (W3C) MIT, ERCIM, Keio University See tidy.h for the copyright notice. */ #include "tidy-int.h" #include "tags.h" #include "tidy.h" Bool TIDY_CALL tidyNodeIsText( TidyNode tnod ) { return TY_(nodeIsText)( tidyNodeToImpl(tnod) ); } Bool tidyNodeCMIsBlock( TidyNode tnod ); /* not exported yet */ Bool tidyNodeCMIsBlock( TidyNode tnod ) { return TY_(nodeCMIsBlock)( tidyNodeToImpl(tnod) ); } Bool tidyNodeCMIsInline( TidyNode tnod ); /* not exported yet */ Bool tidyNodeCMIsInline( TidyNode tnod ) { return TY_(nodeCMIsInline)( tidyNodeToImpl(tnod) ); } Bool tidyNodeCMIsEmpty( TidyNode tnod ); /* not exported yet */ Bool tidyNodeCMIsEmpty( TidyNode tnod ) { return TY_(nodeCMIsEmpty)( tidyNodeToImpl(tnod) ); }
Bool TIDY_CALL tidyNodeIsHeader( TidyNode tnod ) { return TY_(nodeIsHeader)( tidyNodeToImpl(tnod) ); }
/* tagask.c -- Interrogate node type (c) 1998-2006 (W3C) MIT, ERCIM, Keio University See tidy.h for the copyright notice. */ #include "tidy-int.h" #include "tags.h" #include "tidy.h" Bool TIDY_CALL tidyNodeIsText( TidyNode tnod ) { return TY_(nodeIsText)( tidyNodeToImpl(tnod) ); } Bool tidyNodeCMIsBlock( TidyNode tnod ); /* not exported yet */ Bool tidyNodeCMIsBlock( TidyNode tnod ) { return TY_(nodeCMIsBlock)( tidyNodeToImpl(tnod) ); } Bool tidyNodeCMIsInline( TidyNode tnod ); /* not exported yet */ Bool tidyNodeCMIsInline( TidyNode tnod ) { return TY_(nodeCMIsInline)( tidyNodeToImpl(tnod) ); }
/* tagask.c -- Interrogate node type (c) 1998-2006 (W3C) MIT, ERCIM, Keio University See tidy.h for the copyright notice. */ #include "tidy-int.h" #include "tags.h" #include "tidy.h" Bool TIDY_CALL tidyNodeIsText( TidyNode tnod ) { return TY_(nodeIsText)( tidyNodeToImpl(tnod) ); } Bool tidyNodeCMIsBlock( TidyNode tnod ); /* not exported yet */ Bool tidyNodeCMIsBlock( TidyNode tnod ) { return TY_(nodeCMIsBlock)( tidyNodeToImpl(tnod) ); }
Bool TIDY_CALL tidyNodeIsText( TidyNode tnod ) { return TY_(nodeIsText)( tidyNodeToImpl(tnod) ); }
/* Error reporting functions */ void TIDY_CALL tidyErrorSummary( TidyDoc tdoc ) { TidyDocImpl* impl = tidyDocToImpl( tdoc ); if ( impl ) TY_(ErrorSummary)( impl ); }
int tidyDocCleanAndRepair( TidyDocImpl* doc ) { Bool word2K = cfgBool( doc, TidyWord2000 ); Bool logical = cfgBool( doc, TidyLogicalEmphasis ); Bool clean = cfgBool( doc, TidyMakeClean ); Bool dropFont = cfgBool( doc, TidyDropFontTags ); Bool htmlOut = cfgBool( doc, TidyHtmlOut ); Bool xmlOut = cfgBool( doc, TidyXmlOut ); Bool xhtmlOut = cfgBool( doc, TidyXhtmlOut ); Bool xmlDecl = cfgBool( doc, TidyXmlDecl ); Bool tidyMark = cfgBool( doc, TidyMark ); Bool tidyXmlTags = cfgBool( doc, TidyXmlTags ); Bool wantNameAttr = cfgBool( doc, TidyAnchorAsName ); Bool mergeEmphasis = cfgBool( doc, TidyMergeEmphasis ); Node* node; if (tidyXmlTags) return tidyDocStatus( doc ); /* simplifies <b><b> ... </b> ...</b> etc. */ if ( mergeEmphasis ) TY_(NestedEmphasis)( doc, &doc->root ); /* cleans up <dir>indented text</dir> etc. */ TY_(List2BQ)( doc, &doc->root ); TY_(BQ2Div)( doc, &doc->root ); /* replaces i by em and b by strong */ if ( logical ) TY_(EmFromI)( doc, &doc->root ); if ( word2K && TY_(IsWord2000)(doc) ) { /* prune Word2000's <![if ...]> ... <![endif]> */ TY_(DropSections)( doc, &doc->root ); /* drop style & class attributes and empty p, span elements */ TY_(CleanWord2000)( doc, &doc->root ); TY_(DropEmptyElements)(doc, &doc->root); } /* replaces presentational markup by style rules */ if ( clean || dropFont ) TY_(CleanDocument)( doc ); /* Move terminating <br /> tags from out of paragraphs */ /*! Do we want to do this for all block-level elements? */ /* This is disabled due to http://tidy.sf.net/bug/681116 */ #if 0 FixBrakes( doc, TY_(FindBody)( doc )); #endif /* Reconcile http-equiv meta element with output encoding */ if (cfg( doc, TidyOutCharEncoding) != RAW #ifndef NO_NATIVE_ISO2022_SUPPORT && cfg( doc, TidyOutCharEncoding) != ISO2022 #endif ) TY_(VerifyHTTPEquiv)( doc, TY_(FindHEAD)( doc )); if ( !TY_(CheckNodeIntegrity)( &doc->root ) ) TidyPanic( doc->allocator, integrity ); /* remember given doctype for reporting */ node = TY_(FindDocType)(doc); if (node) { AttVal* fpi = TY_(GetAttrByName)(node, "PUBLIC"); if (AttrHasValue(fpi)) { if (doc->givenDoctype) TidyDocFree(doc, doc->givenDoctype); doc->givenDoctype = TY_(tmbstrdup)(doc->allocator,fpi->value); } } if ( doc->root.content ) { /* If we had XHTML input but want HTML output */ if ( htmlOut && doc->lexer->isvoyager ) { Node* node = TY_(FindDocType)(doc); /* Remove reference, but do not free */ if (node) TY_(RemoveNode)(node); } if (xhtmlOut && !htmlOut) { TY_(SetXHTMLDocType)(doc); /* TY_(FixAnchors)(doc, &doc->root, wantNameAttr, yes); */ TY_(FixXhtmlNamespace)(doc, yes); TY_(FixLanguageInformation)(doc, &doc->root, yes, yes); } else { TY_(FixDocType)(doc); TY_(FixAnchors)(doc, &doc->root, wantNameAttr, yes); TY_(FixXhtmlNamespace)(doc, no); TY_(FixLanguageInformation)(doc, &doc->root, no, yes); } if (tidyMark ) TY_(AddGenerator)(doc); } /* ensure presence of initial <?xml version="1.0"?> */ if ( xmlOut && xmlDecl ) TY_(FixXmlDecl)( doc ); return tidyDocStatus( doc ); }
void TIDY_CALL tidyGeneralInfo( TidyDoc tdoc ) { TidyDocImpl* impl = tidyDocToImpl( tdoc ); if ( impl ) TY_(GeneralInfo)( impl ); }
int tidyDocSaveStream( TidyDocImpl* doc, StreamOut* out ) { Bool showMarkup = cfgBool( doc, TidyShowMarkup ); Bool forceOutput = cfgBool( doc, TidyForceOutput ); #if SUPPORT_UTF16_ENCODINGS Bool outputBOM = ( cfgAutoBool(doc, TidyOutputBOM) == TidyYesState ); Bool smartBOM = ( cfgAutoBool(doc, TidyOutputBOM) == TidyAutoState ); #endif Bool xmlOut = cfgBool( doc, TidyXmlOut ); Bool xhtmlOut = cfgBool( doc, TidyXhtmlOut ); TidyTriState bodyOnly = cfgAutoBool( doc, TidyBodyOnly ); Bool dropComments = cfgBool(doc, TidyHideComments); Bool makeClean = cfgBool(doc, TidyMakeClean); Bool asciiChars = cfgBool(doc, TidyAsciiChars); Bool makeBare = cfgBool(doc, TidyMakeBare); Bool escapeCDATA = cfgBool(doc, TidyEscapeCdata); TidyAttrSortStrategy sortAttrStrat = cfg(doc, TidySortAttributes); if (escapeCDATA) TY_(ConvertCDATANodes)(doc, &doc->root); if (dropComments) TY_(DropComments)(doc, &doc->root); if (makeClean) { /* noop */ TY_(DropFontElements)(doc, &doc->root, NULL); TY_(WbrToSpace)(doc, &doc->root); } if ((makeClean && asciiChars) || makeBare) TY_(DowngradeTypography)(doc, &doc->root); if (makeBare) /* Note: no longer replaces in */ /* attribute values / non-text tokens */ TY_(NormalizeSpaces)(doc->lexer, &doc->root); else TY_(ReplacePreformattedSpaces)(doc, &doc->root); if ( sortAttrStrat != TidySortAttrNone ) TY_(SortAttributes)(&doc->root, sortAttrStrat); if ( showMarkup && (doc->errors == 0 || forceOutput) ) { #if SUPPORT_UTF16_ENCODINGS /* Output a Byte Order Mark if required */ if ( outputBOM || (doc->inputHadBOM && smartBOM) ) TY_(outBOM)( out ); #endif /* No longer necessary. No DOCTYPE == HTML 3.2, ** which gives you only the basic character entities, ** which are safe in any browser. ** if ( !TY_(FindDocType)(doc) ) ** TY_(SetOptionBool)( doc, TidyNumEntities, yes ); */ doc->docOut = out; if ( xmlOut && !xhtmlOut ) TY_(PPrintXMLTree)( doc, NORMAL, 0, &doc->root ); else if ( showBodyOnly( doc, bodyOnly ) ) TY_(PrintBody)( doc ); else TY_(PPrintTree)( doc, NORMAL, 0, &doc->root ); TY_(PFlushLine)( doc, 0 ); doc->docOut = NULL; } TY_(ResetConfigToSnapshot)( doc ); return tidyDocStatus( doc ); }
#define VERS_ELEM_TH (xxxx|HT32|H40T|H41T|X10T|H40F|H41F|X10F|H40S|H41S|X10S|XH11|XB10) #define VERS_ELEM_THEAD (xxxx|xxxx|H40T|H41T|X10T|H40F|H41F|X10F|H40S|H41S|X10S|XH11|xxxx) #define VERS_ELEM_TITLE (HT20|HT32|H40T|H41T|X10T|H40F|H41F|X10F|H40S|H41S|X10S|XH11|XB10) #define VERS_ELEM_TR (xxxx|HT32|H40T|H41T|X10T|H40F|H41F|X10F|H40S|H41S|X10S|XH11|XB10) #define VERS_ELEM_TT (HT20|HT32|H40T|H41T|X10T|H40F|H41F|X10F|H40S|H41S|X10S|XH11|xxxx) #define VERS_ELEM_U (xxxx|HT32|H40T|H41T|X10T|H40F|H41F|X10F|xxxx|xxxx|xxxx|xxxx|xxxx) #define VERS_ELEM_UL (HT20|HT32|H40T|H41T|X10T|H40F|H41F|X10F|H40S|H41S|X10S|XH11|XB10) #define VERS_ELEM_VAR (HT20|HT32|H40T|H41T|X10T|H40F|H41F|X10F|H40S|H41S|X10S|XH11|XB10) #define VERS_ELEM_XMP (HT20|HT32|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx) static const Dict tag_defs[] = { { TidyTag_UNKNOWN, "unknown!", VERS_UNKNOWN, NULL, (0), NULL, NULL }, /* W3C defined elements */ { TidyTag_A, "a", VERS_ELEM_A, &TY_(W3CAttrsFor_A)[0], (CM_INLINE), TY_(ParseInline), NULL }, { TidyTag_ABBR, "abbr", VERS_ELEM_ABBR, &TY_(W3CAttrsFor_ABBR)[0], (CM_INLINE), TY_(ParseInline), NULL }, { TidyTag_ACRONYM, "acronym", VERS_ELEM_ACRONYM, &TY_(W3CAttrsFor_ACRONYM)[0], (CM_INLINE), TY_(ParseInline), NULL }, { TidyTag_ADDRESS, "address", VERS_ELEM_ADDRESS, &TY_(W3CAttrsFor_ADDRESS)[0], (CM_BLOCK), TY_(ParseInline), NULL }, { TidyTag_APPLET, "applet", VERS_ELEM_APPLET, &TY_(W3CAttrsFor_APPLET)[0], (CM_OBJECT|CM_IMG|CM_INLINE|CM_PARAM), TY_(ParseBlock), NULL }, { TidyTag_AREA, "area", VERS_ELEM_AREA, &TY_(W3CAttrsFor_AREA)[0], (CM_BLOCK|CM_EMPTY), TY_(ParseEmpty), CheckAREA }, { TidyTag_B, "b", VERS_ELEM_B, &TY_(W3CAttrsFor_B)[0], (CM_INLINE), TY_(ParseInline), NULL }, { TidyTag_BASE, "base", VERS_ELEM_BASE, &TY_(W3CAttrsFor_BASE)[0], (CM_HEAD|CM_EMPTY), TY_(ParseEmpty), NULL }, { TidyTag_BASEFONT, "basefont", VERS_ELEM_BASEFONT, &TY_(W3CAttrsFor_BASEFONT)[0], (CM_INLINE|CM_EMPTY), TY_(ParseEmpty), NULL }, { TidyTag_BDO, "bdo", VERS_ELEM_BDO, &TY_(W3CAttrsFor_BDO)[0], (CM_INLINE), TY_(ParseInline), NULL }, { TidyTag_BIG, "big", VERS_ELEM_BIG, &TY_(W3CAttrsFor_BIG)[0], (CM_INLINE), TY_(ParseInline), NULL }, { TidyTag_BLOCKQUOTE, "blockquote", VERS_ELEM_BLOCKQUOTE, &TY_(W3CAttrsFor_BLOCKQUOTE)[0], (CM_BLOCK), TY_(ParseBlock), NULL }, { TidyTag_BODY, "body", VERS_ELEM_BODY, &TY_(W3CAttrsFor_BODY)[0], (CM_HTML|CM_OPT|CM_OMITST), TY_(ParseBody), NULL }, { TidyTag_BR, "br", VERS_ELEM_BR, &TY_(W3CAttrsFor_BR)[0], (CM_INLINE|CM_EMPTY), TY_(ParseEmpty), NULL }, { TidyTag_BUTTON, "button", VERS_ELEM_BUTTON, &TY_(W3CAttrsFor_BUTTON)[0], (CM_INLINE), TY_(ParseBlock), NULL }, { TidyTag_CAPTION, "caption", VERS_ELEM_CAPTION, &TY_(W3CAttrsFor_CAPTION)[0], (CM_TABLE), TY_(ParseInline), CheckCaption },
ctmbstr TIDY_CALL tidyReleaseDate(void) { return TY_(ReleaseDate)(); }
/* add missing type attribute when appropriate */ void CheckSCRIPT( TidyDocImpl* doc, Node *node ) { AttVal *lang, *type; char buf[16]; TY_(CheckAttributes)(doc, node); lang = TY_(AttrGetById)(node, TidyAttr_LANGUAGE); type = TY_(AttrGetById)(node, TidyAttr_TYPE); if (!type) { /* check for javascript */ if (lang) { /* Test #696799. lang->value can be NULL. */ buf[0] = '\0'; TY_(tmbstrncpy)(buf, lang->value, sizeof(buf)); buf[10] = '\0'; if (TY_(tmbstrncasecmp)(buf, "javascript", 10) == 0 || TY_(tmbstrncasecmp)(buf, "jscript", 7) == 0) { TY_(AddAttribute)(doc, node, "type", "text/javascript"); } else if (TY_(tmbstrcasecmp)(buf, "vbscript") == 0) { /* per Randy Waki 8/6/01 */ TY_(AddAttribute)(doc, node, "type", "text/vbscript"); } } else { TY_(AddAttribute)(doc, node, "type", "text/javascript"); } type = TY_(AttrGetById)(node, TidyAttr_TYPE); if (type != NULL) { TY_(ReportAttrError)(doc, node, type, INSERTING_ATTRIBUTE); } else { TY_(ReportMissingAttr)(doc, node, "type"); } } }
TidyOption TIDY_CALL tidyGetOption( TidyDoc ARG_UNUSED(tdoc), TidyOptionId optId ) { const TidyOptionImpl* option = TY_(getOption)( optId ); return tidyImplToOption( option ); }
Bool TY_(nodeCMIsInline)( Node* node ) { return TY_(nodeHasCM)( node, CM_INLINE ); }
TidyOption TIDY_CALL tidyGetOptionByName( TidyDoc ARG_UNUSED(doc), ctmbstr optnam ) { const TidyOptionImpl* option = TY_(lookupOption)( optnam ); return tidyImplToOption( option ); }
static void messagePos( TidyDocImpl* doc, TidyReportLevel level, uint code, int line, int col, ctmbstr msg, va_list args ) { enum { sizeMessageBuf=2048 }; char *messageBuf = TidyDocAlloc(doc,sizeMessageBuf); Bool go = UpdateCount( doc, level ); if ( go ) { va_list args_copy; va_copy(args_copy, args); TY_(tmbvsnprintf)(messageBuf, sizeMessageBuf, msg, args); if ( doc->mssgFilt ) { TidyDoc tdoc = tidyImplToDoc( doc ); go = doc->mssgFilt( tdoc, level, line, col, messageBuf ); } if ( doc->mssgFilt2 ) { /* mssgFilt2 is intended to allow LibTidy users to localize messages via their own means by providing a key string and the parameters to fill it. For the key string to remain consistent, we have to ensure that we only ever return the built-in English version of this string. */ TidyDoc tdoc = tidyImplToDoc( doc ); go = go | doc->mssgFilt2( tdoc, level, line, col, tidyDefaultString(code), args_copy ); } if ( doc->mssgFilt3 ) { /* mssgFilt3 is intended to allow LibTidy users to localize messages via their own means by providing a key string and the parameters to fill it. */ TidyDoc tdoc = tidyImplToDoc( doc ); go = go | doc->mssgFilt3( tdoc, level, line, col, tidyErrorCodeAsString(code), args_copy ); } } if ( go ) { enum { sizeBuf=1024 }; char *buf = TidyDocAlloc(doc,sizeBuf); const char *cp; if ( line > 0 && col > 0 ) { ReportPosition(doc, line, col, buf, sizeBuf); #if !defined(NDEBUG) && defined(_MSC_VER) SPRTF("%s",buf); #endif for ( cp = buf; *cp; ++cp ) TY_(WriteChar)( *cp, doc->errout ); } LevelPrefix( level, buf, sizeBuf ); #if !defined(NDEBUG) && defined(_MSC_VER) SPRTF("%s",buf); SPRTF("%s\n",messageBuf); #else for ( cp = buf; *cp; ++cp ) TY_(WriteChar)( *cp, doc->errout ); for ( cp = messageBuf; *cp; ++cp ) TY_(WriteChar)( *cp, doc->errout ); TY_(WriteChar)( '\n', doc->errout ); #endif TidyDocFree(doc, buf); } TidyDocFree(doc, messageBuf); }
ctmbstr TIDY_CALL tidyOptGetEncName( TidyDoc tdoc, TidyOptionId optId ) { uint enc = tidyOptGetInt( tdoc, optId ); return TY_(CharEncodingOptName)( enc ); }
ctmbstr TIDY_CALL tidyLibraryVersion(void) { return TY_(library_version); }
ctmbstr TIDY_CALL tidyOptGetDoc( TidyDoc ARG_UNUSED(tdoc), TidyOption opt ) { const TidyOptionId optId = tidyOptGetId( opt ); const TidyOptionDoc* docDesc = TY_(OptGetDocDesc)( optId ); return docDesc ? docDesc->doc : NULL; }
void TY_(ReportError)(TidyDocImpl* doc, Node *element, Node *node, uint code) { char nodedesc[ 256 ] = {0}; char elemdesc[ 256 ] = {0}; Node* rpt = ( element ? element : node ); ctmbstr fmt = tidyLocalizedString(code); uint versionEmitted, declared, version; ctmbstr extra_string = NULL; assert( fmt != NULL ); TagToString(node, nodedesc, sizeof(nodedesc)); switch ( code ) { case MISSING_STARTTAG: case UNEXPECTED_ENDTAG: case TOO_MANY_ELEMENTS: case INSERTING_TAG: messageNode(doc, TidyWarning, code, node, fmt, node->element); break; case USING_BR_INPLACE_OF: case CANT_BE_NESTED: case PROPRIETARY_ELEMENT: case UNESCAPED_ELEMENT: case NOFRAMES_CONTENT: messageNode(doc, TidyWarning, code, node, fmt, nodedesc); break; case ELEMENT_VERS_MISMATCH_WARN: versionEmitted = doc->lexer->versionEmitted; declared = doc->lexer->doctype; version = versionEmitted == 0 ? declared : versionEmitted; extra_string = TY_(HTMLVersionNameFromCode)(version, 0); if (!extra_string) extra_string = tidyLocalizedString(STRING_HTML_PROPRIETARY); messageNode(doc, TidyWarning, code, node, fmt, nodedesc, extra_string); break; case ELEMENT_VERS_MISMATCH_ERROR: versionEmitted = doc->lexer->versionEmitted; declared = doc->lexer->doctype; version = versionEmitted == 0 ? declared : versionEmitted; extra_string = TY_(HTMLVersionNameFromCode)(version, 0); if (!extra_string) extra_string = tidyLocalizedString(STRING_HTML_PROPRIETARY); messageNode(doc, TidyError, code, node, fmt, nodedesc, extra_string); break; case MISSING_TITLE_ELEMENT: case INCONSISTENT_VERSION: case MALFORMED_DOCTYPE: case CONTENT_AFTER_BODY: case MALFORMED_COMMENT: case BAD_COMMENT_CHARS: case BAD_XML_COMMENT: case BAD_CDATA_CONTENT: case INCONSISTENT_NAMESPACE: case DOCTYPE_AFTER_TAGS: case DTYPE_NOT_UPPER_CASE: messageNode(doc, TidyWarning, code, rpt, "%s", fmt); break; case COERCE_TO_ENDTAG: case NON_MATCHING_ENDTAG: messageNode(doc, TidyWarning, code, rpt, fmt, node->element, node->element); break; case UNEXPECTED_ENDTAG_IN: case TOO_MANY_ELEMENTS_IN: messageNode(doc, TidyWarning, code, node, fmt, node->element, element->element); if (cfgBool( doc, TidyShowWarnings )) messageNode(doc, TidyInfo, PREVIOUS_LOCATION, node, tidyLocalizedString(PREVIOUS_LOCATION), element->element); break; case ENCODING_IO_CONFLICT: case MISSING_DOCTYPE: case SPACE_PRECEDING_XMLDECL: messageNode(doc, TidyWarning, code, node, "%s", fmt); break; case TRIM_EMPTY_ELEMENT: case ILLEGAL_NESTING: case UNEXPECTED_END_OF_FILE: case ELEMENT_NOT_EMPTY: TagToString(element, elemdesc, sizeof(elemdesc)); messageNode(doc, TidyWarning, code, element, fmt, elemdesc); break; case MISSING_ENDTAG_FOR: messageNode(doc, TidyWarning, code, rpt, fmt, element->element); break; case MISSING_ENDTAG_BEFORE: messageNode(doc, TidyWarning, code, rpt, fmt, element->element, nodedesc); break; case DISCARDING_UNEXPECTED: /* Force error if in a bad form, or Issue #166 - repeated <main> element */ messageNode(doc, doc->badForm ? TidyError : TidyWarning, code, node, fmt, nodedesc); break; case TAG_NOT_ALLOWED_IN: messageNode(doc, TidyWarning, code, node, fmt, nodedesc, element->element); if (cfgBool( doc, TidyShowWarnings )) messageNode(doc, TidyInfo, PREVIOUS_LOCATION, element, tidyLocalizedString(PREVIOUS_LOCATION), element->element); break; case REPLACING_UNEX_ELEMENT: TagToString(element, elemdesc, sizeof(elemdesc)); messageNode(doc, TidyWarning, code, rpt, fmt, elemdesc, nodedesc); break; case REMOVED_HTML5: messageNode(doc, TidyError, code, rpt, fmt, nodedesc); break; } }
void CCFHtmlTidy::SetTidyProp(const std::string& strParam, int nNumValue, const std::string& /*strNumValue*/, const std::string& strTextValue) { TidyDoc formatter = tidyImplToDoc(tidy); if ("axd" == strParam) { tidyOptSetBool(formatter, TidyXmlDecl, yes); } else if ("axs" == strParam) { tidyOptSetBool(formatter, TidyXmlSpace, yes); } else if ("aan" == strParam) { tidyOptSetBool(formatter, TidyAnchorAsName, yes); } else if ("axp" == strParam) { tidyOptSetBool(formatter, TidyXmlPIs, yes); } else if ("b" == strParam) { tidyOptSetBool(formatter, TidyMakeBare, yes); } else if ("c" == strParam) { tidyOptSetBool(formatter, TidyMakeClean, yes); } else if ("diu" == strParam) { tidyOptSetBool(formatter, TidyDecorateInferredUL, yes); } else if ("dep" == strParam) { tidyOptSetBool(formatter, TidyDropEmptyParas, yes); } else if ("dft" == strParam) { tidyOptSetBool(formatter, TidyDropFontTags, yes); } else if ("dpa" == strParam) { tidyOptSetBool(formatter, TidyDropPropAttrs, yes); } else if ("ebt" == strParam) { tidyOptSetBool(formatter, TidyEncloseBlockText, yes); } else if ("et" == strParam) { tidyOptSetBool(formatter, TidyEncloseBodyText, yes); } else if ("ec" == strParam) { tidyOptSetBool(formatter, TidyEscapeCdata, yes); } else if ("fb" == strParam) { tidyOptSetBool(formatter, TidyFixBackslash, yes); } else if ("fbc" == strParam) { tidyOptSetBool(formatter, TidyFixComments, yes); } else if ("fu" == strParam) { tidyOptSetBool(formatter, TidyFixUri, yes); } else if ("hc" == strParam) { tidyOptSetBool(formatter, TidyHideComments, yes); } else if ("he" == strParam) { tidyOptSetBool(formatter, TidyHideEndTags, yes); } else if ("ic" == strParam) { tidyOptSetBool(formatter, TidyIndentCdata, yes); } else if ("ix" == strParam) { tidyOptSetBool(formatter, TidyXmlTags, yes); } else if ("jc" == strParam) { tidyOptSetBool(formatter, TidyJoinClasses, yes); } else if ("js" == strParam) { tidyOptSetBool(formatter, TidyJoinStyles, yes); } else if ("la" == strParam) { tidyOptSetBool(formatter, TidyLiteralAttribs, yes); } else if ("le" == strParam) { tidyOptSetBool(formatter, TidyLogicalEmphasis, yes); } else if ("ll" == strParam) { tidyOptSetBool(formatter, TidyLowerLiterals, yes); } else if ("n" == strParam) { tidyOptSetBool(formatter, TidyNCR, yes); } else if ("ne" == strParam) { tidyOptSetBool(formatter, TidyNumEntities, yes); } else if ("oh" == strParam) { tidyOptSetBool(formatter, TidyHtmlOut, yes); } else if ("ox" == strParam) { tidyOptSetBool(formatter, TidyXhtmlOut, yes); } else if ("oxm" == strParam) { tidyOptSetBool(formatter, TidyXmlOut, yes); } else if ("pe" == strParam) { tidyOptSetBool(formatter, TidyPreserveEntities, yes); } else if ("qa" == strParam) { tidyOptSetBool(formatter, TidyQuoteAmpersand, yes); } else if ("qm" == strParam) { tidyOptSetBool(formatter, TidyQuoteMarks, yes); } else if ("qn" == strParam) { tidyOptSetBool(formatter, TidyQuoteNbsp, yes); } else if ("rc" == strParam) { tidyOptSetBool(formatter, TidyReplaceColor, yes); } else if ("ua" == strParam) { tidyOptSetBool(formatter, TidyUpperCaseAttrs, yes); } else if ("ut" == strParam) { tidyOptSetBool(formatter, TidyUpperCaseTags, yes); } else if ("wo" == strParam) { tidyOptSetBool(formatter, TidyWord2000, yes); } else if ("bbb" == strParam) { tidyOptSetBool(formatter, TidyBreakBeforeBR, yes); } else if ("ia" == strParam) { tidyOptSetBool(formatter, TidyIndentAttributes, yes); } else if ("m" == strParam) { tidyOptSetBool(formatter, TidyShowMarkup, yes); } else if ("pw" == strParam) { tidyOptSetBool(formatter, TidyPunctWrap, yes); } else if ("vs" == strParam) { tidyOptSetBool(formatter, TidyVertSpace, yes); } else if ("wa" == strParam) { tidyOptSetBool(formatter, TidyWrapAsp, yes); } else if ("wat" == strParam) { tidyOptSetBool(formatter, TidyWrapAttVals, yes); } else if ("wj" == strParam) { tidyOptSetBool(formatter, TidyWrapJste, yes); } else if ("wp" == strParam) { tidyOptSetBool(formatter, TidyWrapPhp, yes); } else if ("wsl" == strParam) { tidyOptSetBool(formatter, TidyWrapScriptlets, yes); } else if ("ws" == strParam) { tidyOptSetBool(formatter, TidyWrapSection, yes); } else if ("ac" == strParam) { tidyOptSetBool(formatter, TidyAsciiChars, yes); } else if ("sw" == strParam) { tidyOptSetBool(formatter, TidyShowWarnings, yes); } else if ("fo" == strParam) { tidyOptSetBool(formatter, TidyForceOutput, yes); } else if ("i" == strParam) { tidyOptSetInt(formatter, TidyIndentContent, abs(nNumValue - 2) % 3); } else if ("md" == strParam) { tidyOptSetInt(formatter, TidyMergeDivs, abs(nNumValue - 2) % 3); } else if ("ms" == strParam) { tidyOptSetInt(formatter, TidyMergeSpans, abs(nNumValue - 2) % 3); } else if ("sbo" == strParam) { tidyOptSetInt(formatter, TidyBodyOnly, abs(nNumValue - 2) % 3); } else if ("d" == strParam) { tidyOptSetInt(formatter, TidyDoctypeMode, nNumValue % 5); } else if ("du" == strParam) { tidyOptSetValue(formatter, TidyDoctype, strTextValue.c_str()); } else if ("ra" == strParam) { tidyOptSetInt(formatter, TidyDuplicateAttrs, nNumValue % 2); } else if ("sa" == strParam) { tidyOptSetInt(formatter, TidySortAttributes, nNumValue % 2); } else if ("ce" == strParam) { tidySetCharEncoding(formatter, TY_(GetEncodingOptNameFromTidyId)(nNumValue)); } else if ("ie" == strParam) { tidySetInCharEncoding(formatter, TY_(GetEncodingOptNameFromTidyId)(nNumValue)); } else if ("oe" == strParam) { tidySetOutCharEncoding(formatter, TY_(GetEncodingOptNameFromTidyId)(nNumValue)); } else if ("se" == strParam) { tidyOptSetInt(formatter, TidyShowErrors, nNumValue); } else if ("is" == strParam) { tidyOptSetInt(formatter, TidyIndentSpaces, nNumValue); } else if ("ts" == strParam) { tidyOptSetInt(formatter, TidyTabSize, nNumValue); } else if ("w" == strParam) { tidyOptSetInt(formatter, TidyWrapLen, nNumValue); } else if ("at" == strParam) { tidyOptSetValue(formatter, TidyAltText, strTextValue.c_str()); } else if ("cp" == strParam) { tidyOptSetValue(formatter, TidyCSSPrefix, strTextValue.c_str()); } else if ("nbt" == strParam) { tidyOptSetValue(formatter, TidyBlockTags, strTextValue.c_str()); } else if ("net" == strParam) { tidyOptSetValue(formatter, TidyEmptyTags, strTextValue.c_str()); } else if ("nit" == strParam) { tidyOptSetValue(formatter, TidyInlineTags, strTextValue.c_str()); } else if ("npt" == strParam) { tidyOptSetValue(formatter, TidyPreTags, strTextValue.c_str()); } }