Skip to content

Commit 0c03427

Browse files
authored
Merge pull request #13 from AngleSharp/devel
Release 0.14.0
2 parents 4181aa4 + bee8047 commit 0c03427

17 files changed

+151
-87
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# 0.14.0
2+
3+
Released on Tuesday, March 31 2020.
4+
5+
- Added more overloads for `ToXml` and `ToMarkup`
6+
- Allow transforming all empty elements to self closing tags
7+
- Serialize self-closing tags correctly (#11)
8+
- Updated the `IMarkupFormatter` implementations
9+
- Added shallow support for source link
10+
- Support more target frameworks
11+
112
# 0.13.0
213

314
Released on Friday, September 6 2019.

CONTRIBUTORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Thanks :heart: to all who contributed to AngleSharp.Xml via issues, pull request
55
AngleSharp.Xml contains code written by (in order of first pull request / commit):
66

77
* [Florian Rappl](https://github.com/FlorianRappl)
8+
* [Konstantin Safonov](https://github.com/kasthack)
89

910
Without these awesome people AngleSharp.Xml could not exist. Thanks to everyone for your contributions! :beers:
1011

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2013 - 2019 AngleSharp
3+
Copyright (c) 2013 - 2020 AngleSharp
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ This project is supported by the [.NET Foundation](https://dotnetfoundation.org)
7474

7575
The MIT License (MIT)
7676

77-
Copyright (c) 2019 AngleSharp
77+
Copyright (c) 2020 AngleSharp
7878

7979
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8080

build.cake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ var projectName = "AngleSharp.Xml";
33
var solutionName = "AngleSharp.Xml";
44
var frameworks = new Dictionary<String, String>
55
{
6+
{ "net46", "net46" },
7+
{ "net461", "net461" },
8+
{ "net472", "net472" },
69
{ "netstandard1.3", "netstandard1.3" },
10+
{ "netstandard2.0", "netstandard2.0" },
711
};
812

913
#load tools/anglesharp.cake

src/AngleSharp.Xml.Tests/AngleSharp.Xml.Tests.csproj

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@
1313
</ItemGroup>
1414

1515
<ItemGroup>
16-
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
17-
<PackageReference Include="NUnit" Version="3.11.0" />
18-
<PackageReference Include="NUnit3TestAdapter" Version="3.11.0" />
16+
<PackageReference Include="AngleSharp" Version="0.14.0" />
17+
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
18+
<PackageReference Include="NUnit" Version="3.12.0" />
19+
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1">
20+
<PrivateAssets>all</PrivateAssets>
21+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
22+
</PackageReference>
1923
<PackageReference Include="Appveyor.TestLogger" Version="2.0.0" />
2024
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
2125
</ItemGroup>

src/AngleSharp.Xml.Tests/Various.cs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace AngleSharp.Xml.Tests
1+
namespace AngleSharp.Xml.Tests
22
{
33
using AngleSharp.Dom;
44
using AngleSharp.Io;
@@ -63,6 +63,40 @@ public async Task GenerateDocumentFromSvgWithSvgContentType()
6363
Assert.AreEqual("path", document.DocumentElement.FirstElementChild.NodeName);
6464
}
6565

66+
[Test]
67+
public void SelfClosingTagsAreSerializedCorrectlyByDefaultFormatter_Issue11()
68+
{
69+
var parser = new XmlParser();
70+
var xmlDoc = parser.ParseDocument(
71+
@"<Project Sdk=""Microsoft.NET.Sdk"">
72+
<ItemGroup>
73+
<PackageReference Include=""AngleSharp"" Version=""0.12.1"" />
74+
<PackageReference></PackageReference>
75+
</ItemGroup>
76+
</Project>");
77+
var xml = xmlDoc.ToXml();
78+
Assert.AreEqual("<Project Sdk=\"Microsoft.NET.Sdk\">\n <ItemGroup>\n <PackageReference Include=\"AngleSharp\" Version=\"0.12.1\" />\n <PackageReference></PackageReference>\n </ItemGroup>\n </Project>", xml);
79+
}
80+
81+
[Test]
82+
public void EmptyTagsAreSerializedCorrectlyWithStandardFormatterWithOption_Issue11()
83+
{
84+
var parser = new XmlParser();
85+
var xmlDoc = parser.ParseDocument(
86+
@"<Project Sdk=""Microsoft.NET.Sdk"">
87+
<ItemGroup>
88+
<PackageReference Include=""AngleSharp"" Version=""0.12.1"" />
89+
<PackageReference></PackageReference>
90+
</ItemGroup>
91+
</Project>");
92+
var formatter = new XmlMarkupFormatter
93+
{
94+
IsAlwaysSelfClosing = true,
95+
};
96+
var xml = xmlDoc.ToHtml(formatter);
97+
Assert.AreEqual("<Project Sdk=\"Microsoft.NET.Sdk\">\n <ItemGroup>\n <PackageReference Include=\"AngleSharp\" Version=\"0.12.1\" />\n <PackageReference />\n </ItemGroup>\n </Project>", xml);
98+
}
99+
66100
private static Task<IDocument> GenerateDocument(String content, String contentType)
67101
{
68102
var config = Configuration.Default.WithDefaultLoader().WithXml();

src/AngleSharp.Xml.nuspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1212
<description>Adds a powerful XML and DTD parser to AngleSharp.</description>
1313
<releaseNotes>https://github.com/AngleSharp/AngleSharp.Xml/blob/master/CHANGELOG.md</releaseNotes>
14-
<copyright>Copyright 2016-2019, AngleSharp</copyright>
14+
<copyright>Copyright 2016-2020, AngleSharp</copyright>
1515
<tags>html html5 css css3 dom requester http https xml dtd</tags>
1616
<dependencies>
17-
<dependency id="AngleSharp" version="0.13.0" />
17+
<dependency id="AngleSharp" version="0.14.0" />
1818
</dependencies>
1919
</metadata>
2020
</package>

src/AngleSharp.Xml/AngleSharp.Xml.csproj

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,26 @@
22
<PropertyGroup>
33
<AssemblyName>AngleSharp.Xml</AssemblyName>
44
<RootNamespace>AngleSharp.Xml</RootNamespace>
5-
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">netstandard1.3</TargetFrameworks>
5+
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netstandard1.3;netstandard2.0</TargetFrameworks>
6+
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">netstandard1.3;netstandard2.0;net46;net461;net472</TargetFrameworks>
67
<SignAssembly>true</SignAssembly>
78
<AssemblyOriginatorKeyFile>Key.snk</AssemblyOriginatorKeyFile>
89
<GenerateDocumentationFile>true</GenerateDocumentationFile>
10+
<LangVersion>7.1</LangVersion>
11+
<RepositoryUrl>https://github.com/AngleSharp/AngleSharp.Xml</RepositoryUrl>
12+
<RepositoryType>git</RepositoryType>
13+
<PublishRepositoryUrl>true</PublishRepositoryUrl>
14+
<EmbedUntrackedSources>true</EmbedUntrackedSources>
15+
<IncludeSymbols>true</IncludeSymbols>
16+
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
917
</PropertyGroup>
1018

1119
<ItemGroup>
12-
<PackageReference Include="AngleSharp" Version="0.13.0" />
20+
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
21+
</ItemGroup>
22+
23+
<ItemGroup>
24+
<PackageReference Include="AngleSharp" Version="0.14.0" />
1325
</ItemGroup>
1426

1527
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT' ">

src/AngleSharp.Xml/AutoSelectedMarkupFormatter.cs

Lines changed: 16 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace AngleSharp.Xml
99
/// AutoSelectedMarkupFormatter class to select the proper MarkupFormatter
1010
/// implementation depending on the used document type.
1111
/// </summary>
12-
public sealed class AutoSelectedMarkupFormatter : IMarkupFormatter
12+
public class AutoSelectedMarkupFormatter : IMarkupFormatter
1313
{
1414
#region Fields
1515

@@ -60,84 +60,46 @@ private IMarkupFormatter ChildFormatter
6060

6161
#region Methods
6262

63-
/// <summary>
64-
/// Formats an attribute specified by the argument.
65-
/// </summary>
66-
/// <param name="attribute">The attribute to serialize.</param>
67-
/// <returns>The formatted attribute.</returns>
68-
public String Attribute(IAttr attribute) => ChildFormatter.Attribute(attribute);
69-
70-
/// <summary>
71-
/// Formats opening a tag with the given name.
72-
/// </summary>
73-
/// <param name="element">The element to open.</param>
74-
/// <param name="selfClosing">
75-
/// Is the element actually self-closing?
76-
/// </param>
77-
/// <returns>The formatted opening tag.</returns>
78-
public String OpenTag(IElement element, Boolean selfClosing)
63+
/// <inheritdoc />
64+
public virtual String OpenTag(IElement element, Boolean selfClosing)
7965
{
8066
Confirm(element.Owner.Doctype);
8167
return ChildFormatter.OpenTag(element, selfClosing);
8268
}
8369

84-
/// <summary>
85-
/// Formats closing a tag with the given name.
86-
/// </summary>
87-
/// <param name="element">The element to close.</param>
88-
/// <param name="selfClosing">
89-
/// Is the element actually self-closing?
90-
/// </param>
91-
/// <returns>The formatted closing tag.</returns>
92-
public String CloseTag(IElement element, Boolean selfClosing)
70+
/// <inheritdoc />
71+
public virtual String CloseTag(IElement element, Boolean selfClosing)
9372
{
9473
Confirm(element.Owner.Doctype);
9574
return ChildFormatter.CloseTag(element, selfClosing);
9675
}
9776

98-
/// <summary>
99-
/// Formats the given comment.
100-
/// </summary>
101-
/// <param name="comment">The comment to stringify.</param>
102-
/// <returns>The formatted comment.</returns>
103-
public String Comment(IComment comment)
77+
/// <inheritdoc />
78+
public virtual String Comment(IComment comment)
10479
{
10580
Confirm(comment.Owner.Doctype);
10681
return ChildFormatter.Comment(comment);
10782
}
10883

109-
/// <summary>
110-
/// Formats the given doctype using the name, public and system
111-
/// identifiers.
112-
/// </summary>
113-
/// <param name="doctype">The document type to stringify.</param>
114-
/// <returns>The formatted doctype.</returns>
115-
public String Doctype(IDocumentType doctype)
84+
/// <inheritdoc />
85+
public virtual String Doctype(IDocumentType doctype)
11686
{
11787
Confirm(doctype);
11888
return ChildFormatter.Doctype(doctype);
11989
}
12090

121-
/// <summary>
122-
/// Formats the given processing instruction using the target and the
123-
/// data.
124-
/// </summary>
125-
/// <param name="processing">
126-
/// The processing instruction to stringify.
127-
/// </param>
128-
/// <returns>The formatted processing instruction.</returns>
129-
public String Processing(IProcessingInstruction processing)
91+
/// <inheritdoc />
92+
public virtual String Processing(IProcessingInstruction processing)
13093
{
13194
Confirm(processing.Owner.Doctype);
13295
return ChildFormatter.Processing(processing);
13396
}
13497

135-
/// <summary>
136-
/// Formats the given text.
137-
/// </summary>
138-
/// <param name="text">The text to sanatize.</param>
139-
/// <returns>The formatted text.</returns>
140-
public String Text(ICharacterData text) => ChildFormatter.Text(text);
98+
/// <inheritdoc />
99+
public virtual String Text(ICharacterData text) => ChildFormatter.Text(text);
100+
101+
/// <inheritdoc />
102+
public virtual String LiteralText(ICharacterData text) => ChildFormatter.LiteralText(text);
141103

142104
#endregion
143105

src/AngleSharp.Xml/Dom/Internal/SvgDocument.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ internal SvgDocument(IBrowsingContext context = null)
4545

4646
#region Methods
4747

48-
public override Element CreateElementFrom(String name, String prefix)
49-
{
50-
return _factory.Create(this, name, prefix) as Element;
51-
}
48+
public override Element CreateElementFrom(String name, String prefix, NodeFlags flags = NodeFlags.None) => _factory.Create(this, name, prefix, flags);
5249

5350
public override Node Clone(Document owner, Boolean deep)
5451
{

src/AngleSharp.Xml/Dom/Internal/XmlDocument.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ internal XmlDocument(IBrowsingContext context = null)
3737

3838
#region Methods
3939

40-
public override Element CreateElementFrom(String name, String prefix) => new XmlElement(this, name, prefix);
40+
public override Element CreateElementFrom(String name, String prefix, NodeFlags flags = NodeFlags.None) => new XmlElement(this, name, prefix, flags: flags);
4141

4242
public override Node Clone(Document owner, Boolean deep)
4343
{

src/AngleSharp.Xml/Dom/Internal/XmlElement.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ sealed class XmlElement : Element
1212
{
1313
#region ctor
1414

15-
public XmlElement(Document owner, String name, String prefix = null)
16-
: base(owner, name, prefix, null)
15+
public XmlElement(Document owner, String name, String prefix = null, String namespaceUri = null, NodeFlags flags = NodeFlags.None)
16+
: base(owner, name, prefix, namespaceUri, flags)
1717
{
1818
}
1919

src/AngleSharp.Xml/MarkupFormatterExtensions.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace AngleSharp.Xml
22
{
33
using System;
4+
using System.IO;
45

56
/// <summary>
67
/// Extensions for the markup formattable elements.
@@ -16,6 +17,14 @@ public static class MarkupFormatterExtensions
1617
public static String ToXml(this IMarkupFormattable markup) =>
1718
markup.ToHtml(XmlMarkupFormatter.Instance);
1819

20+
/// <summary>
21+
/// Serializes the object model guided by the XML markup formatter.
22+
/// </summary>
23+
/// <param name="markup">The markup to serialize.</param>
24+
/// <param name="writer">The output target of the serialization.</param>
25+
public static void ToXml(this IMarkupFormattable markup, TextWriter writer) =>
26+
markup.ToHtml(writer, XmlMarkupFormatter.Instance);
27+
1928
/// <summary>
2029
/// Returns the serialization of the object model guided by the
2130
/// auto selected (XML, XHTML, HTML) markup formatter.
@@ -24,5 +33,14 @@ public static String ToXml(this IMarkupFormattable markup) =>
2433
/// <returns>The source code snippet.</returns>
2534
public static String ToMarkup(this IMarkupFormattable markup) =>
2635
markup.ToHtml(new AutoSelectedMarkupFormatter());
36+
37+
/// <summary>
38+
/// Serializes the object model guided by the auto selected (XML,
39+
/// XHTML, HTML) markup formatter.
40+
/// </summary>
41+
/// <param name="markup">The markup to serialize.</param>
42+
/// <param name="writer">The output target of the serialization.</param>
43+
public static void ToMarkup(this IMarkupFormattable markup, TextWriter writer) =>
44+
markup.ToHtml(writer, new AutoSelectedMarkupFormatter());
2745
}
2846
}

src/AngleSharp.Xml/Parser/XmlDomBuilder.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ private void InBody(XmlToken token)
271271
case XmlTokenType.StartTag:
272272
{
273273
var tagToken = (XmlTagToken)token;
274-
var element = CreateElement(tagToken.Name);
274+
var element = CreateElement(tagToken.Name, tagToken.IsSelfClosing);
275275
CurrentNode.AppendChild(element);
276276

277277
for (var i = 0; i < tagToken.Attributes.Count; i++)
@@ -402,18 +402,19 @@ private void AfterBody(XmlToken token)
402402

403403
#region Helpers
404404

405-
private Element CreateElement(String name)
405+
private Element CreateElement(String name, Boolean selfClosing)
406406
{
407407
var prefix = default(String);
408408
var colon = name.IndexOf(Symbols.Colon);
409+
var flags = selfClosing ? NodeFlags.SelfClosing : NodeFlags.None;
409410

410411
if (colon > 0 && colon < name.Length - 1)
411412
{
412413
prefix = name.Substring(0, colon);
413414
name = name.Substring(colon + 1);
414415
}
415416

416-
return _document.CreateElementFrom(name, prefix);
417+
return _document.CreateElementFrom(name, prefix, flags);
417418
}
418419

419420
private Attr CreateAttribute(String name, String value)

0 commit comments

Comments
 (0)