Issue #108 - first cut new option --indent-with-tabs yes.

This commit is contained in:
Geoff McLane 2015-05-15 15:06:52 +02:00
parent 97853993ec
commit 231061e90a
5 changed files with 66 additions and 5 deletions

View file

@ -80,7 +80,7 @@ typedef enum
typedef enum
{
TidyUnknownOption, /**< Unknown option! */
TidyIndentSpaces, /**< Indentation n spaces */
TidyIndentSpaces, /**< Indentation n spaces/tabs */
TidyWrapLen, /**< Wrap margin */
TidyTabSize, /**< Expand tabs to n spaces */
@ -204,6 +204,7 @@ typedef enum
TidySortAttributes, /**< Sort attributes */
TidyMergeSpans, /**< Merge multiple SPANs */
TidyAnchorAsName, /**< Define anchors as name attributes */
TidyPPrintTabs, /**< Indent using tabs istead of spaces */
N_TIDY_OPTIONS /**< Must be last */
} TidyOptionId;

View file

@ -204,6 +204,13 @@ static ParseProperty ParseDocType;
/* keep-first or keep-last? */
static ParseProperty ParseRepeatAttr;
/*\
* 20150515 - support using tabs instead of spaces - Issue #108
* (a) parser for 't'/'f', 'true'/'false', 'y'/'n', 'yes'/'no' or '1'/'0'
* (b) sets the TidyIndentSpaces to 1 if 'yes'
* (c) sets the indent_char to '\t' or ' '
\*/
static ParseProperty ParseTabs;
static const TidyOptionImpl option_defs[] =
{
@ -313,6 +320,7 @@ static const TidyOptionImpl option_defs[] =
{ TidySortAttributes, PP, "sort-attributes", IN, TidySortAttrNone,ParseSorter, sorterPicks },
{ TidyMergeSpans, MU, "merge-spans", IN, TidyAutoState, ParseAutoBool, autoBoolPicks },
{ TidyAnchorAsName, MU, "anchor-as-name", BL, yes, ParseBool, boolPicks },
{ TidyPPrintTabs, PP, "indent-with-tabs", BL, no, ParseTabs, NULL }, /* 20150515 - Issue #108 */
{ N_TIDY_OPTIONS, XX, NULL, XY, 0, NULL, NULL }
};
@ -1204,6 +1212,30 @@ Bool ParseCSS1Selector( TidyDocImpl* doc, const TidyOptionImpl* option )
return yes;
}
/*\
* 20150515 - support using tabs instead of spaces - Issue #108
* Sets the indent character to a tab if on, and set indent space count to 1
* and sets indent character to a space if off.
\*/
Bool ParseTabs( TidyDocImpl* doc, const TidyOptionImpl* entry )
{
ulong flag = 0;
Bool status = ParseTriState( TidyNoState, doc, entry, &flag );
if ( status ) {
Bool tabs = flag != 0 ? yes : no;
TY_(SetOptionBool)( doc, entry->id, tabs );
if (tabs) {
TY_(PPrintTabs)();
TY_(SetOptionInt)( doc, TidyIndentSpaces, 1 );
} else {
TY_(PPrintSpaces)();
/* optional - TY_(ResetOptionToDefault)( doc, TidyIndentSpaces ); */
}
}
return status;
}
/* Coordinates Config update and Tags data */
static void DeclareUserTag( TidyDocImpl* doc, TidyOptionId optId,
UserTagType tagType, ctmbstr name )

View file

@ -745,7 +745,7 @@ static const TidyOptionDoc option_docs[] =
{TidyTabSize,
"This option specifies the number of columns that Tidy uses between "
"successive tab stops. It is used to map tabs to spaces when reading the "
"input. Tidy never outputs tabs. "
"input. "
},
{TidyVertSpace,
"This option specifies if Tidy should add some empty lines for "
@ -914,6 +914,14 @@ static const TidyOptionDoc option_docs[] =
"is added along an existing id attribute if the DTD allows it. "
"If set to \"no\", any existing name attribute is removed "
"if an id attribute exists or has been added. "
},
{TidyPPrintTabs,
"Set this option \"on\" to indent using tabs instead of the default "
"spaces. The option TidyIndentSpaces controls the number of tabs output "
"per level of indent, which is reset to 1, when this option is set on. "
"And of course, indent must be enabled for this to have any effect. "
"Note TidyTabSize controls converting input tabs to spaces. Set to zero "
"to retain input tabs. "
},
{N_TIDY_OPTIONS,
NULL

View file

@ -36,6 +36,21 @@ static int TextStartsWithWhitespace( Lexer *lexer, Node *node, uint start, uint
static Bool InsideHead( TidyDocImpl* doc, Node *node );
static Bool ShouldIndent( TidyDocImpl* doc, Node *node );
/*\
* 20150515 - support using tabs instead of spaces - Issue #108
* GH: https://github.com/htacg/tidy-html5/issues/108 - Keep indent with tabs #108
* SF: https://sourceforge.net/p/tidy/feature-requests/3/ - #3 tabs in place of spaces
\*/
static uint indent_char = ' ';
void TY_(PPrintTabs)(void)
{
indent_char = '\t';
}
void TY_(PPrintSpaces)(void)
{
indent_char = ' ';
}
#if SUPPORT_ASIAN_ENCODINGS
/* #431953 - start RJ Wraplen adjusted for smooth international ride */
@ -582,7 +597,7 @@ static void WrapLine( TidyDocImpl* doc )
{
uint spaces = GetSpaces( pprint );
for ( i = 0; i < spaces; ++i )
TY_(WriteChar)( ' ', doc->docOut );
TY_(WriteChar)( indent_char, doc->docOut ); /* 20150515 - Issue #108 */
}
for ( i = 0; i < pprint->wraphere; ++i )
@ -633,7 +648,7 @@ static void WrapAttrVal( TidyDocImpl* doc )
{
uint spaces = GetSpaces( pprint );
for ( i = 0; i < spaces; ++i )
TY_(WriteChar)( ' ', doc->docOut );
TY_(WriteChar)( indent_char, doc->docOut ); /* 20150515 - Issue #108 */
}
for ( i = 0; i < pprint->wraphere; ++i )
@ -660,7 +675,7 @@ static void PFlushLineImpl( TidyDocImpl* doc )
{
uint spaces = GetSpaces( pprint );
for ( i = 0; i < spaces; ++i )
TY_(WriteChar)( ' ', doc->docOut );
TY_(WriteChar)( indent_char, doc->docOut ); /* 20150515 - Issue #108 */
}
for ( i = 0; i < pprint->linelen; ++i )

View file

@ -84,5 +84,10 @@ void TY_(PPrintTree)( TidyDocImpl* doc, uint mode, uint indent, Node *node );
void TY_(PPrintXMLTree)( TidyDocImpl* doc, uint mode, uint indent, Node *node );
/*\
* 20150515 - support using tabs instead of spaces
\*/
void TY_(PPrintTabs)(void);
void TY_(PPrintSpaces)(void);
#endif /* __PPRINT_H__ */