Skip to content

Commit

Permalink
Use this.options, move options to the misc region, remove RefreshProp…
Browse files Browse the repository at this point in the history
…erties attribute
  • Loading branch information
virzak committed Dec 29, 2023
1 parent 9ab8ece commit 92662c1
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void Process(XmlReader xmlReader, StringBuilder output, ElementProcessCon
// http://www.w3.org/TR/2008/REC-xml-20081126/#sec-line-ends
// Change them back into the environment newline characters.
output.Append("<![CDATA[")
.Append(xmlReader.Value.Replace("\n", options.NewLine))
.Append(xmlReader.Value.Replace("\n", this.options.NewLine))
.Append("]]>");
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/XamlStyler/DocumentProcessors/CommentDocumentProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void Process(XmlReader xmlReader, StringBuilder output, ElementProcessCon

if ((output.Length > 0) && !output.IsNewLine())
{
output.Append(options.NewLine);
output.Append(this.options.NewLine);
}

if (content.Contains("<") && content.Contains(">"))
Expand All @@ -41,7 +41,7 @@ public void Process(XmlReader xmlReader, StringBuilder output, ElementProcessCon

if (content.Contains("\n"))
{
output.Append(String.Join(options.NewLine, content.GetLines().Select(_ => _.TrimEnd(' '))));
output.Append(String.Join(this.options.NewLine, content.GetLines().Select(_ => _.TrimEnd(' '))));

if (content.TrimEnd(' ').EndsWith("\n", StringComparison.Ordinal))
{
Expand All @@ -66,10 +66,10 @@ public void Process(XmlReader xmlReader, StringBuilder output, ElementProcessCon
var contentIndentString = this.indentService.GetIndentString(xmlReader.Depth + 1);
foreach (var line in content.Trim().GetLines())
{
output.Append(options.NewLine).Append(contentIndentString).Append(line.Trim());
output.Append(this.options.NewLine).Append(contentIndentString).Append(line.Trim());
}

output.Append(options.NewLine).Append(currentIndentString).Append("-->");
output.Append(this.options.NewLine).Append(currentIndentString).Append("-->");
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions src/XamlStyler/DocumentProcessors/ElementDocumentProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void Process(XmlReader xmlReader, StringBuilder output, ElementProcessCon
}
else
{
output.Append(options.NewLine).Append(currentIndentString);
output.Append(this.options.NewLine).Append(currentIndentString);
}
}
}
Expand Down Expand Up @@ -115,7 +115,7 @@ public void Process(XmlReader xmlReader, StringBuilder output, ElementProcessCon
if (putEndingBracketOnNewLine)
{
// Indent ending bracket just like an attribute.
output.Append(options.NewLine).Append(attributeIndetationString);
output.Append(this.options.NewLine).Append(attributeIndetationString);
}

if (isEmptyElement)
Expand Down Expand Up @@ -302,7 +302,7 @@ public void Process(XmlReader xmlReader, StringBuilder output, ElementProcessCon
}
else
{
output.Append(options.NewLine)
output.Append(this.options.NewLine)
.Append(this.indentService.Normalize(attributeIndentationString + attributeLines[i].Trim()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public EndElementDocumentProcessor(IStylerOptions options, IndentService indentS

if (!output.IsNewLine())
{
output.Append(options.NewLine);
output.Append(this.options.NewLine);
}

output.Append(currentIndentString).Append("</").Append(xmlReader.Name).Append(">");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void Process(XmlReader xmlReader, StringBuilder output, ElementProcessCon

if (!output.IsNewLine())
{
output.Append(options.NewLine);
output.Append(this.options.NewLine);
}

output.Append($"{currentIndentString}<?{xmlReader.Name} {xmlReader.Value}?>");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void Process(XmlReader xmlReader, StringBuilder output, ElementProcessCon
// All newlines are returned by XmlReader as '\n' due to requirements in the XML Specification.
// http://www.w3.org/TR/2008/REC-xml-20081126/#sec-line-ends
// Change them back into the environment newline characters.
output.Append(xmlReader.Value.Replace("\n", options.NewLine));
output.Append(xmlReader.Value.Replace("\n", this.options.NewLine));
}
}
}
4 changes: 2 additions & 2 deletions src/XamlStyler/DocumentProcessors/TextDocumentProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void Process(XmlReader xmlReader, StringBuilder output, ElementProcessCon
var xmlEncodedContent = xmlReader.Value.ToXmlEncodedString(ignoreCarrier: true);
if (elementProcessContext.Current.IsPreservingSpace)
{
output.Append(xmlEncodedContent.Replace("\n", options.NewLine));
output.Append(xmlEncodedContent.Replace("\n", this.options.NewLine));
}
else
{
Expand All @@ -45,7 +45,7 @@ public void Process(XmlReader xmlReader, StringBuilder output, ElementProcessCon
var trimmedLine = line.Trim();
if (trimmedLine.Length > 0)
{
output.Append(options.NewLine).Append(currentIndentString).Append(trimmedLine);
output.Append(this.options.NewLine).Append(currentIndentString).Append(trimmedLine);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void Process(XmlReader xmlReader, StringBuilder output, ElementProcessCon
.Replace(" ", String.Empty)
.Replace("\t", String.Empty)
.Replace("\r", String.Empty)
.Replace("\n", options.NewLine));
.Replace("\n", this.options.NewLine));
}
else
{
Expand All @@ -46,7 +46,7 @@ public void Process(XmlReader xmlReader, StringBuilder output, ElementProcessCon
// B
// </Run>
// </TextBlock>
output.Append(xmlReader.Value.Replace("\n", options.NewLine));
output.Append(xmlReader.Value.Replace("\n", this.options.NewLine));
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/XamlStyler/Options/IStylerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ public interface IStylerOptions

int CommentSpaces { get; set; }

string NewLine { get; }

string EndOfLine { get; set; }

#endregion Misc

#region Configuration
Expand All @@ -119,10 +123,6 @@ public interface IStylerOptions

bool SuppressProcessing { get; set; }

string NewLine { get; }

string EndOfLine { get; set; }

#endregion Configuration
}
}
2 changes: 0 additions & 2 deletions src/XamlStyler/Options/StylerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@ public string ConfigPath
private string endOfLine;

[Category("Misc")]
[RefreshProperties(RefreshProperties.All)]
[Description("Defines end of line character. Specify 'lf' or 'crlf'; otherwise, default character of the host will be used.")]
[JsonProperty("EndOfLine", DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
[DefaultValue("")]
Expand All @@ -378,7 +377,6 @@ public string EndOfLine
[JsonIgnore]
public string NewLine { get; private set; } = Environment.NewLine;


/// <summary>
/// Creates a clone from the current instance.
/// </summary>
Expand Down
10 changes: 5 additions & 5 deletions src/XamlStyler/StylerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,18 @@ private void ApplyOptions(IList<string> ignoredNamespacesPrefixes, bool ignoreDe
// { XmlNodeType.None, null },
{ XmlNodeType.Element, new ElementDocumentProcessor(options, xamlLanguageOptions, attributeInfoFactory, attributeInfoFormatter, indentService, xmlEscapingService) },
// { XmlNodeType.Attribute, null },
{ XmlNodeType.Text, new TextDocumentProcessor(options, indentService) },
{ XmlNodeType.CDATA, new CDATADocumentProcessor(options, indentService) },
{ XmlNodeType.Text, new TextDocumentProcessor(this.options, indentService) },
{ XmlNodeType.CDATA, new CDATADocumentProcessor(this.options, indentService) },
// { XmlNodeType.EntityReference, null },
// { XmlNodeType.Entity, null },
{ XmlNodeType.ProcessingInstruction, new ProcessInstructionDocumentProcessor(options, indentService) },
{ XmlNodeType.ProcessingInstruction, new ProcessInstructionDocumentProcessor(this.options, indentService) },
{ XmlNodeType.Comment, new CommentDocumentProcessor(options, indentService) },
// { XmlNodeType.Document, null },
// { XmlNodeType.DocumentType, null },
// { XmlNodeType.DocumentFragment, null },
// { XmlNodeType.Notation, null },
{ XmlNodeType.Whitespace, new WhitespaceDocumentProcessor(options) },
{ XmlNodeType.SignificantWhitespace, new SignificantWhitespaceDocumentProcessor(options) },
{ XmlNodeType.Whitespace, new WhitespaceDocumentProcessor(this.options) },
{ XmlNodeType.SignificantWhitespace, new SignificantWhitespaceDocumentProcessor(this.options) },
{ XmlNodeType.EndElement, new EndElementDocumentProcessor(options, indentService) },
// { XmlNodeType.EndEntity, null },
// ignoring xml declarations for Xamarin support
Expand Down

0 comments on commit 92662c1

Please sign in to comment.