345
348
static const TidyOptionId TidyPreTagsLinks[] =
346
349
{ TidyBlockTags, TidyEmptyTags, TidyInlineTags, TidyUnknownOption };
347
350
static const TidyOptionId TidyMergeDivsLinks[] =
348
{ TidyMakeClean, TidyUnknownOption };
351
{ TidyMakeClean, TidyMergeSpans, TidyUnknownOption };
352
static const TidyOptionId TidyMergeSpansLinks[] =
353
{ TidyMakeClean, TidyMergeDivs, TidyUnknownOption };
349
354
static const TidyOptionId TidyAsciiCharsLinks[] =
350
355
{ TidyMakeClean, TidyUnknownOption };
351
356
static const TidyOptionId TidyNumEntitiesLinks[] =
352
{ TidyDoctype, TidyUnknownOption };
357
{ TidyDoctype, TidyPreserveEntities, TidyUnknownOption };
358
static const TidyOptionId TidyDropFontTagsLinks[] =
359
{ TidyMakeClean, TidyUnknownOption };
360
static const TidyOptionId TidyMakeCleanTagsLinks[] =
361
{ TidyDropFontTags, TidyUnknownOption };
354
363
/* Documentation of options */
355
364
static const TidyOptionDoc option_docs[] =
835
tmbstrncpy( buf, "Info: ", count );
877
TY_(tmbstrncpy)( buf, "Info: ", count );
837
879
case TidyWarning:
838
tmbstrncpy( buf, "Warning: ", count );
880
TY_(tmbstrncpy)( buf, "Warning: ", count );
841
tmbstrncpy( buf, "Config: ", count );
883
TY_(tmbstrncpy)( buf, "Config: ", count );
844
tmbstrncpy( buf, "Access: ", count );
886
TY_(tmbstrncpy)( buf, "Access: ", count );
847
tmbstrncpy( buf, "Error: ", count );
889
TY_(tmbstrncpy)( buf, "Error: ", count );
849
891
case TidyBadDocument:
850
tmbstrncpy( buf, "Document: ", count );
892
TY_(tmbstrncpy)( buf, "Document: ", count );
853
tmbstrncpy( buf, "panic: ", count );
895
TY_(tmbstrncpy)( buf, "panic: ", count );
856
return buf + tmbstrlen( buf );
898
return buf + TY_(tmbstrlen)( buf );
859
901
/* Updates document message counts and
901
943
/* Change formatting to be parsable by GNU Emacs */
902
944
if ( cfgBool(doc, TidyEmacs) && cfgStr(doc, TidyEmacsFile) )
903
tmbsnprintf(buf, count, "%s:%d:%d: ",
904
cfgStr(doc, TidyEmacsFile), line, col);
945
TY_(tmbsnprintf)(buf, count, "%s:%d:%d: ",
946
cfgStr(doc, TidyEmacsFile), line, col);
905
947
else /* traditional format */
906
tmbsnprintf(buf, count, "line %d column %d - ", line, col);
907
return buf + tmbstrlen( buf );
948
TY_(tmbsnprintf)(buf, count, "line %d column %d - ", line, col);
949
return buf + TY_(tmbstrlen)( buf );
910
952
/* General message writing routine.
988
enum { sizeBuf=1024 };
989
char *buf = TidyDocAlloc(doc,sizeBuf);
947
991
if ( line > 0 && col > 0 )
949
ReportPosition(doc, line, col, buf, sizeof(buf));
993
ReportPosition(doc, line, col, buf, sizeBuf);
950
994
for ( cp = buf; *cp; ++cp )
951
WriteChar( *cp, doc->errout );
995
TY_(WriteChar)( *cp, doc->errout );
954
LevelPrefix( level, buf, sizeof(buf) );
998
LevelPrefix( level, buf, sizeBuf );
955
999
for ( cp = buf; *cp; ++cp )
956
WriteChar( *cp, doc->errout );
1000
TY_(WriteChar)( *cp, doc->errout );
958
1002
for ( cp = messageBuf; *cp; ++cp )
959
WriteChar( *cp, doc->errout );
960
WriteChar( '\n', doc->errout );
1003
TY_(WriteChar)( *cp, doc->errout );
1004
TY_(WriteChar)( '\n', doc->errout );
1005
TidyDocFree(doc, buf);
1007
TidyDocFree(doc, messageBuf);
1010
/* Reports error at current Lexer line/column. */
1012
void message( TidyDocImpl* doc, TidyReportLevel level, ctmbstr msg, ... )
1014
__attribute__((format(printf, 3, 4)))
1018
/* Reports error at node line/column. */
1020
void messageNode( TidyDocImpl* doc, TidyReportLevel level,
1021
Node* node, ctmbstr msg, ... )
1023
__attribute__((format(printf, 4, 5)))
1027
/* Reports error at given line/column. */
1029
void messageLexer( TidyDocImpl* doc, TidyReportLevel level,
1032
__attribute__((format(printf, 3, 4)))
1036
/* For general reporting. Emits nothing if --quiet yes */
1038
void tidy_out( TidyDocImpl* doc, ctmbstr msg, ... )
1040
__attribute__((format(printf, 2, 3)))
964
1045
void message( TidyDocImpl* doc, TidyReportLevel level, ctmbstr msg, ... )
1039
if (nodeIsElement(tag))
1040
tmbsnprintf(buf, count, "<%s>", tag->element);
1124
if (TY_(nodeIsElement)(tag))
1125
TY_(tmbsnprintf)(buf, count, "<%s>", tag->element);
1041
1126
else if (tag->type == EndTag)
1042
tmbsnprintf(buf, count, "</%s>", tag->element);
1127
TY_(tmbsnprintf)(buf, count, "</%s>", tag->element);
1043
1128
else if (tag->type == DocTypeTag)
1044
tmbsnprintf(buf, count, "<!DOCTYPE>");
1129
TY_(tmbsnprintf)(buf, count, "<!DOCTYPE>");
1045
1130
else if (tag->type == TextNode)
1046
tmbsnprintf(buf, count, "plain text");
1131
TY_(tmbsnprintf)(buf, count, "plain text");
1047
1132
else if (tag->type == XmlDecl)
1048
tmbsnprintf(buf, count, "XML declaration");
1133
TY_(tmbsnprintf)(buf, count, "XML declaration");
1049
1134
else if (tag->element)
1050
tmbsnprintf(buf, count, "%s", tag->element);
1135
TY_(tmbsnprintf)(buf, count, "%s", tag->element);
1052
return buf + tmbstrlen(buf);
1137
return buf + TY_(tmbstrlen)(buf);
1055
1140
/* lexer is not defined when this is called */
1056
void ReportUnknownOption( TidyDocImpl* doc, ctmbstr option )
1141
void TY_(ReportUnknownOption)( TidyDocImpl* doc, ctmbstr option )
1058
1143
assert( option != NULL );
1059
1144
message( doc, TidyConfig, "unknown option: %s", option );
1062
1147
/* lexer is not defined when this is called */
1063
void ReportBadArgument( TidyDocImpl* doc, ctmbstr option )
1148
void TY_(ReportBadArgument)( TidyDocImpl* doc, ctmbstr option )
1065
1150
assert( option != NULL );
1066
1151
message( doc, TidyConfig,
1275
1361
tidy_out(doc, " \n");
1278
void ReportAccessWarning( TidyDocImpl* doc, Node* node, uint code )
1364
void TY_(ReportAccessWarning)( TidyDocImpl* doc, Node* node, uint code )
1280
1366
ctmbstr fmt = GetFormatFromCode(code);
1281
doc->badAccess = yes;
1367
doc->badAccess |= BA_WAI;
1282
1368
messageNode( doc, TidyAccess, node, fmt );
1285
void ReportAccessError( TidyDocImpl* doc, Node* node, uint code )
1371
void TY_(ReportAccessError)( TidyDocImpl* doc, Node* node, uint code )
1287
1373
ctmbstr fmt = GetFormatFromCode(code);
1288
doc->badAccess = yes;
1374
doc->badAccess |= BA_WAI;
1289
1375
messageNode( doc, TidyAccess, node, fmt );
1292
1378
#endif /* SUPPORT_ACCESSIBILITY_CHECKS */
1294
void ReportWarning(TidyDocImpl* doc, Node *element, Node *node, uint code)
1380
void TY_(ReportWarning)(TidyDocImpl* doc, Node *element, Node *node, uint code)
1296
1382
Node* rpt = (element ? element : node);
1297
1383
ctmbstr fmt = GetFormatFromCode(code);
1566
1658
if (doc->badAccess)
1568
if ( cfg(doc, TidyAccessibilityCheckLevel) > 0 )
1570
tidy_out(doc, "For further advice on how to make your pages accessible, see\n");
1571
tidy_out(doc, "%s", ACCESS_URL );
1572
tidy_out(doc, "and\n" );
1573
tidy_out(doc, "%s", ATRC_ACCESS_URL );
1660
/* Tidy "classic" accessibility tests */
1661
if ( cfg(doc, TidyAccessibilityCheckLevel) == 0 )
1663
if (doc->badAccess & BA_MISSING_SUMMARY)
1665
tidy_out(doc, "The table summary attribute should be used to describe\n");
1666
tidy_out(doc, "the table structure. It is very helpful for people using\n");
1667
tidy_out(doc, "non-visual browsers. The scope and headers attributes for\n");
1668
tidy_out(doc, "table cells are useful for specifying which headers apply\n");
1669
tidy_out(doc, "to each table cell, enabling non-visual browsers to provide\n");
1670
tidy_out(doc, "a meaningful context for each cell.\n\n");
1673
if (doc->badAccess & BA_MISSING_IMAGE_ALT)
1675
tidy_out(doc, "The alt attribute should be used to give a short description\n");
1676
tidy_out(doc, "of an image; longer descriptions should be given with the\n");
1677
tidy_out(doc, "longdesc attribute which takes a URL linked to the description.\n");
1678
tidy_out(doc, "These measures are needed for people using non-graphical browsers.\n\n");
1681
if (doc->badAccess & BA_MISSING_IMAGE_MAP)
1683
tidy_out(doc, "Use client-side image maps in preference to server-side image\n");
1684
tidy_out(doc, "maps as the latter are inaccessible to people using non-\n");
1685
tidy_out(doc, "graphical browsers. In addition, client-side maps are easier\n");
1686
tidy_out(doc, "to set up and provide immediate feedback to users.\n\n");
1689
if (doc->badAccess & BA_MISSING_LINK_ALT)
1691
tidy_out(doc, "For hypertext links defined using a client-side image map, you\n");
1692
tidy_out(doc, "need to use the alt attribute to provide a textual description\n");
1693
tidy_out(doc, "of the link for people using non-graphical browsers.\n\n");
1696
if ((doc->badAccess & BA_USING_FRAMES) && !(doc->badAccess & BA_USING_NOFRAMES))
1698
tidy_out(doc, "Pages designed using frames presents problems for\n");
1699
tidy_out(doc, "people who are either blind or using a browser that\n");
1700
tidy_out(doc, "doesn't support frames. A frames-based page should always\n");
1701
tidy_out(doc, "include an alternative layout inside a NOFRAMES element.\n\n");
1706
tidy_out(doc, "For further advice on how to make your pages accessible\n");
1707
tidy_out(doc, "see %s", ACCESS_URL );
1708
if ( cfg(doc, TidyAccessibilityCheckLevel) > 0 )
1709
tidy_out(doc, " and %s", ATRC_ACCESS_URL );
1574
1710
tidy_out(doc, ".\n" );
1575
tidy_out(doc, "You may also want to try \"http://www.cast.org/bobby/\" which is a free Web-based\n");
1576
tidy_out(doc, "service for checking URLs for accessibility.\n\n");
1580
if (doc->badAccess & MISSING_SUMMARY)
1582
tidy_out(doc, "The table summary attribute should be used to describe\n");
1583
tidy_out(doc, "the table structure. It is very helpful for people using\n");
1584
tidy_out(doc, "non-visual browsers. The scope and headers attributes for\n");
1585
tidy_out(doc, "table cells are useful for specifying which headers apply\n");
1586
tidy_out(doc, "to each table cell, enabling non-visual browsers to provide\n");
1587
tidy_out(doc, "a meaningful context for each cell.\n\n");
1590
if (doc->badAccess & MISSING_IMAGE_ALT)
1592
tidy_out(doc, "The alt attribute should be used to give a short description\n");
1593
tidy_out(doc, "of an image; longer descriptions should be given with the\n");
1594
tidy_out(doc, "longdesc attribute which takes a URL linked to the description.\n");
1595
tidy_out(doc, "These measures are needed for people using non-graphical browsers.\n\n");
1598
if (doc->badAccess & MISSING_IMAGE_MAP)
1600
tidy_out(doc, "Use client-side image maps in preference to server-side image\n");
1601
tidy_out(doc, "maps as the latter are inaccessible to people using non-\n");
1602
tidy_out(doc, "graphical browsers. In addition, client-side maps are easier\n");
1603
tidy_out(doc, "to set up and provide immediate feedback to users.\n\n");
1606
if (doc->badAccess & MISSING_LINK_ALT)
1608
tidy_out(doc, "For hypertext links defined using a client-side image map, you\n");
1609
tidy_out(doc, "need to use the alt attribute to provide a textual description\n");
1610
tidy_out(doc, "of the link for people using non-graphical browsers.\n\n");
1613
if ((doc->badAccess & USING_FRAMES) && !(doc->badAccess & USING_NOFRAMES))
1615
tidy_out(doc, "Pages designed using frames presents problems for\n");
1616
tidy_out(doc, "people who are either blind or using a browser that\n");
1617
tidy_out(doc, "doesn't support frames. A frames-based page should always\n");
1618
tidy_out(doc, "include an alternative layout inside a NOFRAMES element.\n\n");
1621
tidy_out(doc, "For further advice on how to make your pages accessible\n");
1622
tidy_out(doc, "see " );
1623
tidy_out(doc, ACCESS_URL );
1624
1711
tidy_out(doc, ". You may also want to try\n" );
1625
1712
tidy_out(doc, "\"http://www.cast.org/bobby/\" which is a free Web-based\n");
1626
1713
tidy_out(doc, "service for checking URLs for accessibility.\n\n");
1630
1716
if (doc->badLayout)
1668
void UnknownOption( TidyDocImpl* doc, char c )
1755
void TY_(UnknownOption)( TidyDocImpl* doc, char c )
1670
1757
message( doc, TidyConfig,
1671
1758
"unrecognized option -%c use -help to list options\n", c );
1674
void UnknownFile( TidyDocImpl* doc, ctmbstr program, ctmbstr file )
1761
void TY_(UnknownFile)( TidyDocImpl* doc, ctmbstr program, ctmbstr file )
1676
1763
message( doc, TidyConfig,
1677
1764
"%s: can't open file \"%s\"\n", program, file );
1680
void NeedsAuthorIntervention( TidyDocImpl* doc )
1768
void TY_(NeedsAuthorIntervention)( TidyDocImpl* doc )
1682
1770
tidy_out(doc, "This document has errors that must be fixed before\n");
1683
1771
tidy_out(doc, "using HTML Tidy to generate a tidied up version.\n\n");
1686
void GeneralInfo( TidyDocImpl* doc )
1774
void TY_(GeneralInfo)( TidyDocImpl* doc )
1688
1776
tidy_out(doc, "To learn more about HTML Tidy see http://tidy.sourceforge.net\n");
1689
tidy_out(doc, "Please send bug reports to html-tidy@w3.org\n");
1777
tidy_out(doc, "Please fill bug reports and queries using the \"tracker\" on the Tidy web site.\n");
1778
tidy_out(doc, "Additionally, questions can be sent to html-tidy@w3.org\n");
1690
1779
tidy_out(doc, "HTML and CSS specifications are available from http://www.w3.org/\n");
1691
1780
tidy_out(doc, "Lobby your company to join W3C, see http://www.w3.org/Consortium\n");
1694
1783
#if SUPPORT_ACCESSIBILITY_CHECKS
1696
void AccessibilityHelloMessage( TidyDocImpl* doc )
1785
void TY_(AccessibilityHelloMessage)( TidyDocImpl* doc )
1698
1787
tidy_out( doc, "\n" );
1699
1788
tidy_out( doc, "Accessibility Checks: Version 0.1\n" );
1714
1804
helper = " for ";
1717
if ( tmbstrcmp(filename, "stdin") == 0 )
1807
if ( TY_(tmbstrcmp)(filename, "stdin") == 0 )
1719
1809
/* Filename will be ignored at end of varargs */
1720
1810
msgfmt = "\nHTML Tidy for %s (vers %s; built on %s, at %s)\n"
1721
1811
"Parsing console input (stdin)\n";
1724
tmbsnprintf(buf, sizeof(buf), msgfmt, helper, platform,
1725
date, __DATE__, __TIME__, filename);
1814
TY_(tmbsnprintf)(buf, sizeof(buf), msgfmt, helper, platform,
1815
date, __DATE__, __TIME__, filename);
1726
1816
tidy_out( doc, buf );
1729
void ReportMarkupVersion( TidyDocImpl* doc )
1820
void TY_(ReportMarkupVersion)( TidyDocImpl* doc )
1731
1822
if (doc->givenDoctype)
1740
1831
uint apparentVers;
1743
apparentVers = ApparentVersion( doc );
1834
apparentVers = TY_(ApparentVersion)( doc );
1745
vers = HTMLVersionNameFromCode( apparentVers, isXhtml );
1836
vers = TY_(HTMLVersionNameFromCode)( apparentVers, isXhtml );
1748
1839
vers = "HTML Proprietary";
1750
1841
message( doc, TidyInfo, "Document content looks like %s", vers );
1843
/* Warn about missing sytem identifier (SI) in emitted doctype */
1844
if ( TY_(WarnMissingSIInEmittedDocType)( doc ) )
1845
message( doc, TidyInfo, "No system identifier in emitted doctype" );
1754
void ReportNumWarnings( TidyDocImpl* doc )
1849
void TY_(ReportNumWarnings)( TidyDocImpl* doc )
1756
1851
if ( doc->warnings > 0 || doc->errors > 0 )
1758
tidy_out( doc, "%d %s, %d %s were found!",
1853
tidy_out( doc, "%u %s, %u %s were found!",
1759
1854
doc->warnings, doc->warnings == 1 ? "warning" : "warnings",
1760
1855
doc->errors, doc->errors == 1 ? "error" : "errors" );