Example #1
0
 /// <summary>
 /// Copies values of this extension's own settings to equivalent values of this page.
 /// </summary>
 private void Load()
 {
     TabSize = Settings.Current.TabSize;
     UseTabSizeInTextEditor = Settings.Current.UseTabSizeInTextEditor ? Toggle.On : Toggle.Off;
     FixedIndentSize        = Settings.Current.FixedIndentSize;
     TrimTrailingSpaces     = Settings.Current.TrimTrailingSpaces ? Toggle.On : Toggle.Off;
     UseHtmlEncode          = Settings.Current.UseHtmlEncode ? Toggle.On : Toggle.Off;
     LineEndType            = Settings.Current.LineEndType;
 }
Example #2
0
        public static string Format(
            string source,
            int tabSize             = 4,
            int fixedIndentSize     = 0,
            bool trimTrailingSpaces = true,
            bool useHtmlEncode      = false,
            LineEndType lineEndType = LineEndType.CrLf)
        {
            if (string.IsNullOrEmpty(source))
            {
                return(source);
            }

            var lineEnd = (lineEndType == LineEndType.CrLf) ? "\r\n" : "\n";

            var trimmed = TrimSpaces(source, tabSize, fixedIndentSize, trimTrailingSpaces);

            var joined = string.Join(lineEnd, trimmed.Append(string.Empty));             // The last empty string is to add line ending at the tail.

            return(useHtmlEncode ? WebUtility.HtmlEncode(joined) : joined);
        }