From 2aeb2eeb7a6cb90779ff6bd840eae8cdb80ef194 Mon Sep 17 00:00:00 2001 From: Geoff McLane Date: Fri, 3 Nov 2017 19:16:17 +0100 Subject: [PATCH 1/4] Issue #403 - New 'keep-tabs' option to address this. --- include/tidyenum.h | 1 + src/config.c | 1 + src/language_en.h | 11 +++++++++++ src/streamio.c | 13 ++++++++----- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/include/tidyenum.h b/include/tidyenum.h index 90d7352..ae523a6 100644 --- a/include/tidyenum.h +++ b/include/tidyenum.h @@ -604,6 +604,7 @@ typedef enum TidyJoinClasses, /**< Join multiple class attributes */ TidyJoinStyles, /**< Join multiple style attributes */ TidyKeepFileTimes, /**< If yes last modied time is preserved */ + TidyKeepTabs, /**< If yes keep input source tabs */ TidyLiteralAttribs, /**< If true attributes may use newlines */ TidyLogicalEmphasis, /**< Replace i by em and b by strong */ TidyLowerLiterals, /**< Folds known attribute values to lower case */ diff --git a/src/config.c b/src/config.c index 2fd89d7..7b7bd2e 100644 --- a/src/config.c +++ b/src/config.c @@ -214,6 +214,7 @@ static const TidyOptionImpl option_defs[] = { TidyJoinClasses, MX, "join-classes", BL, no, ParsePickList, &boolPicks }, { TidyJoinStyles, MX, "join-styles", BL, yes, ParsePickList, &boolPicks }, { TidyKeepFileTimes, IO, "keep-time", BL, no, ParsePickList, &boolPicks }, + { TidyKeepTabs, PP, "keep-tabs", BL, no, ParsePickList, &boolPicks }, /* 20171103 - Issue #403 */ { TidyLiteralAttribs, MR, "literal-attributes", BL, no, ParsePickList, &boolPicks }, { TidyLogicalEmphasis, MC, "logical-emphasis", BL, no, ParsePickList, &boolPicks }, { TidyLowerLiterals, MR, "lower-literals", BL, yes, ParsePickList, &boolPicks }, diff --git a/src/language_en.h b/src/language_en.h index f56f1ec..9f5b93e 100644 --- a/src/language_en.h +++ b/src/language_en.h @@ -699,6 +699,17 @@ static languageDefinition language_en = { whichPluralForm_en, { "
" "Note this feature is not supported on some platforms. " }, + {/* Important notes for translators: + - Use only , , , , and +
. + - Entities, tags, attributes, etc., should be enclosed in . + - Option values should be enclosed in . + - It's very important that
be self-closing! + - The strings "Tidy" and "HTML Tidy" are the program name and must not + be translated. */ + TidyKeepTabs, 0, + "This option specifies if Tidy should keep tabs found in the source. " + }, {/* Important notes for translators: - Use only , , , , and
. diff --git a/src/streamio.c b/src/streamio.c index cd36efe..bf75a1a 100644 --- a/src/streamio.c +++ b/src/streamio.c @@ -239,7 +239,6 @@ static void RestoreLastPos( StreamIn *in ) uint TY_(ReadChar)( StreamIn *in ) { uint c = EndOfStream; - uint tabsize = cfg( in->doc, TidyTabSize ); if ( in->pushed ) return PopChar( in ); @@ -269,11 +268,15 @@ uint TY_(ReadChar)( StreamIn *in ) if (c == '\t') { - in->tabs = tabsize > 0 ? - tabsize - ((in->curcol - 1) % tabsize) - 1 - : 0; + Bool keeptabs = cfg( in->doc, TidyKeepTabs ); in->curcol++; - c = ' '; + if (!keeptabs) { + uint tabsize = cfg(in->doc, TidyTabSize); + in->tabs = tabsize > 0 ? + tabsize - ((in->curcol - 1) % tabsize) - 1 + : 0; + c = ' '; + } break; } From b58abe30d0e0bde495b4ca66d9bb976500d2b0ca Mon Sep 17 00:00:00 2001 From: Geoff McLane Date: Sun, 5 Nov 2017 18:04:52 +0100 Subject: [PATCH 2/4] Issue #403 - Special DEBUG change to 'see' tabs --- src/lexer.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/lexer.c b/src/lexer.c index 05fc509..b1f7437 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -63,6 +63,9 @@ static tmbstr get_text_string(Lexer* lexer, Node *node) if (c == '\n') { buffer[i++] = '\\'; buffer[i++] = 'n'; + } else if (c == '\t') { + buffer[i++] = '\\'; + buffer[i++] = 't'; } else if ( c == ' ' ) { if (!insp) buffer[i++] = c; @@ -84,6 +87,9 @@ static tmbstr get_text_string(Lexer* lexer, Node *node) if (c == '\n') { buffer[i++] = '\\'; buffer[i++] = 'n'; + } else if (c == '\t') { + buffer[i++] = '\\'; + buffer[i++] = 't'; } else if ( c == ' ' ) { if (!insp) buffer[i++] = c; @@ -116,6 +122,9 @@ static tmbstr get_text_string(Lexer* lexer, Node *node) if (c == '\n') { buffer[i++] = '\\'; buffer[i++] = 'n'; + } else if (c == '\t') { + buffer[i++] = '\\'; + buffer[i++] = 't'; } else if ( c == ' ' ) { if (!insp) buffer[i++] = c; From 7bbeae3eeaeab7546e3f5639bf1e246c84491aee Mon Sep 17 00:00:00 2001 From: Geoff McLane Date: Tue, 7 Nov 2017 20:29:04 +0100 Subject: [PATCH 3/4] Issue #403 - Fix and enhance descripion of keep-tabs option --- src/language_en.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/language_en.h b/src/language_en.h index 9f5b93e..56b91e8 100644 --- a/src/language_en.h +++ b/src/language_en.h @@ -708,7 +708,17 @@ static languageDefinition language_en = { whichPluralForm_en, { - The strings "Tidy" and "HTML Tidy" are the program name and must not be translated. */ TidyKeepTabs, 0, - "This option specifies if Tidy should keep tabs found in the source. " + "With the default no Tidy will replace all source tabs, with spaces, " + "controlled by the option tab-size, and the current line offset. " + "Of course, except in the special blocks/elments enumerated below, this will later " + "be reduced to just one space. " + "
" + "If set yes this option specifies Tidy should keep certain tabs " + "found in the source, but only " + "in preformatted blocks like <pre>, and other CDATA elements like " + "<script>, <style>, and other pseudo elements like " + "<?php ... ?>. As always, all other tabs, or sequences of tabs, in " + "the source will continue to be replaced with a space. " }, {/* Important notes for translators: - Use only , , , , and From e4fc470592d5f88d4096195bba77c99f6d710649 Mon Sep 17 00:00:00 2001 From: Geoff McLane Date: Tue, 7 Nov 2017 20:36:55 +0100 Subject: [PATCH 4/4] Issue #403 - correct spelling --- src/language_en.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/language_en.h b/src/language_en.h index 56b91e8..f1468a9 100644 --- a/src/language_en.h +++ b/src/language_en.h @@ -710,7 +710,7 @@ static languageDefinition language_en = { whichPluralForm_en, { TidyKeepTabs, 0, "With the default no Tidy will replace all source tabs, with spaces, " "controlled by the option tab-size, and the current line offset. " - "Of course, except in the special blocks/elments enumerated below, this will later " + "Of course, except in the special blocks/elements enumerated below, this will later " "be reduced to just one space. " "
" "If set yes this option specifies Tidy should keep certain tabs "