Issue #108 - first cut new option --indent-with-tabs yes.
This commit is contained in:
parent
97853993ec
commit
231061e90a
|
@ -80,7 +80,7 @@ typedef enum
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
TidyUnknownOption, /**< Unknown option! */
|
TidyUnknownOption, /**< Unknown option! */
|
||||||
TidyIndentSpaces, /**< Indentation n spaces */
|
TidyIndentSpaces, /**< Indentation n spaces/tabs */
|
||||||
TidyWrapLen, /**< Wrap margin */
|
TidyWrapLen, /**< Wrap margin */
|
||||||
TidyTabSize, /**< Expand tabs to n spaces */
|
TidyTabSize, /**< Expand tabs to n spaces */
|
||||||
|
|
||||||
|
@ -204,6 +204,7 @@ typedef enum
|
||||||
TidySortAttributes, /**< Sort attributes */
|
TidySortAttributes, /**< Sort attributes */
|
||||||
TidyMergeSpans, /**< Merge multiple SPANs */
|
TidyMergeSpans, /**< Merge multiple SPANs */
|
||||||
TidyAnchorAsName, /**< Define anchors as name attributes */
|
TidyAnchorAsName, /**< Define anchors as name attributes */
|
||||||
|
TidyPPrintTabs, /**< Indent using tabs istead of spaces */
|
||||||
N_TIDY_OPTIONS /**< Must be last */
|
N_TIDY_OPTIONS /**< Must be last */
|
||||||
} TidyOptionId;
|
} TidyOptionId;
|
||||||
|
|
||||||
|
|
32
src/config.c
32
src/config.c
|
@ -204,6 +204,13 @@ static ParseProperty ParseDocType;
|
||||||
/* keep-first or keep-last? */
|
/* keep-first or keep-last? */
|
||||||
static ParseProperty ParseRepeatAttr;
|
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[] =
|
static const TidyOptionImpl option_defs[] =
|
||||||
{
|
{
|
||||||
|
@ -313,6 +320,7 @@ static const TidyOptionImpl option_defs[] =
|
||||||
{ TidySortAttributes, PP, "sort-attributes", IN, TidySortAttrNone,ParseSorter, sorterPicks },
|
{ TidySortAttributes, PP, "sort-attributes", IN, TidySortAttrNone,ParseSorter, sorterPicks },
|
||||||
{ TidyMergeSpans, MU, "merge-spans", IN, TidyAutoState, ParseAutoBool, autoBoolPicks },
|
{ TidyMergeSpans, MU, "merge-spans", IN, TidyAutoState, ParseAutoBool, autoBoolPicks },
|
||||||
{ TidyAnchorAsName, MU, "anchor-as-name", BL, yes, ParseBool, boolPicks },
|
{ 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 }
|
{ N_TIDY_OPTIONS, XX, NULL, XY, 0, NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1204,6 +1212,30 @@ Bool ParseCSS1Selector( TidyDocImpl* doc, const TidyOptionImpl* option )
|
||||||
return yes;
|
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 */
|
/* Coordinates Config update and Tags data */
|
||||||
static void DeclareUserTag( TidyDocImpl* doc, TidyOptionId optId,
|
static void DeclareUserTag( TidyDocImpl* doc, TidyOptionId optId,
|
||||||
UserTagType tagType, ctmbstr name )
|
UserTagType tagType, ctmbstr name )
|
||||||
|
|
|
@ -745,7 +745,7 @@ static const TidyOptionDoc option_docs[] =
|
||||||
{TidyTabSize,
|
{TidyTabSize,
|
||||||
"This option specifies the number of columns that Tidy uses between "
|
"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 "
|
"successive tab stops. It is used to map tabs to spaces when reading the "
|
||||||
"input. Tidy never outputs tabs. "
|
"input. "
|
||||||
},
|
},
|
||||||
{TidyVertSpace,
|
{TidyVertSpace,
|
||||||
"This option specifies if Tidy should add some empty lines for "
|
"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. "
|
"is added along an existing id attribute if the DTD allows it. "
|
||||||
"If set to \"no\", any existing name attribute is removed "
|
"If set to \"no\", any existing name attribute is removed "
|
||||||
"if an id attribute exists or has been added. "
|
"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,
|
{N_TIDY_OPTIONS,
|
||||||
NULL
|
NULL
|
||||||
|
|
21
src/pprint.c
21
src/pprint.c
|
@ -36,6 +36,21 @@ static int TextStartsWithWhitespace( Lexer *lexer, Node *node, uint start, uint
|
||||||
static Bool InsideHead( TidyDocImpl* doc, Node *node );
|
static Bool InsideHead( TidyDocImpl* doc, Node *node );
|
||||||
static Bool ShouldIndent( 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
|
#if SUPPORT_ASIAN_ENCODINGS
|
||||||
/* #431953 - start RJ Wraplen adjusted for smooth international ride */
|
/* #431953 - start RJ Wraplen adjusted for smooth international ride */
|
||||||
|
|
||||||
|
@ -582,7 +597,7 @@ static void WrapLine( TidyDocImpl* doc )
|
||||||
{
|
{
|
||||||
uint spaces = GetSpaces( pprint );
|
uint spaces = GetSpaces( pprint );
|
||||||
for ( i = 0; i < spaces; ++i )
|
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 )
|
for ( i = 0; i < pprint->wraphere; ++i )
|
||||||
|
@ -633,7 +648,7 @@ static void WrapAttrVal( TidyDocImpl* doc )
|
||||||
{
|
{
|
||||||
uint spaces = GetSpaces( pprint );
|
uint spaces = GetSpaces( pprint );
|
||||||
for ( i = 0; i < spaces; ++i )
|
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 )
|
for ( i = 0; i < pprint->wraphere; ++i )
|
||||||
|
@ -660,7 +675,7 @@ static void PFlushLineImpl( TidyDocImpl* doc )
|
||||||
{
|
{
|
||||||
uint spaces = GetSpaces( pprint );
|
uint spaces = GetSpaces( pprint );
|
||||||
for ( i = 0; i < spaces; ++i )
|
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 )
|
for ( i = 0; i < pprint->linelen; ++i )
|
||||||
|
|
|
@ -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 );
|
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__ */
|
#endif /* __PPRINT_H__ */
|
||||||
|
|
Loading…
Reference in a new issue