Skip to content

Commit c8056d3

Browse files
committed
Implemented fragment parsing
1 parent 2ba5b35 commit c8056d3

22 files changed

+128
-66
lines changed

src/AngleSharp.Xml/AngleSharp.Xml.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="AngleSharp" Version="0.11.0" />
12+
<PackageReference Include="AngleSharp" Version="0.12.0" />
1313
</ItemGroup>
1414

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

src/AngleSharp.Xml/AutoSelectedMarkupFormatter.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ private IMarkupFormatter ChildFormatter
5353

5454
return childFormatter ?? HtmlMarkupFormatter.Instance;
5555
}
56-
set
57-
{
58-
childFormatter = value;
59-
}
56+
set => childFormatter = value;
6057
}
6158

6259
#endregion
@@ -68,10 +65,7 @@ private IMarkupFormatter ChildFormatter
6865
/// </summary>
6966
/// <param name="attribute">The attribute to serialize.</param>
7067
/// <returns>The formatted attribute.</returns>
71-
public String Attribute(IAttr attribute)
72-
{
73-
return ChildFormatter.Attribute(attribute);
74-
}
68+
public String Attribute(IAttr attribute) => ChildFormatter.Attribute(attribute);
7569

7670
/// <summary>
7771
/// Formats opening a tag with the given name.
@@ -143,10 +137,7 @@ public String Processing(IProcessingInstruction processing)
143137
/// </summary>
144138
/// <param name="text">The text to sanatize.</param>
145139
/// <returns>The formatted text.</returns>
146-
public String Text(ICharacterData text)
147-
{
148-
return ChildFormatter.Text(text);
149-
}
140+
public String Text(ICharacterData text) => ChildFormatter.Text(text);
150141

151142
#endregion
152143

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
namespace AngleSharp.Xml.Dom
22
{
33
using AngleSharp.Dom;
4+
using AngleSharp.Text;
5+
using AngleSharp.Xml.Parser;
46
using System;
57

68
/// <summary>
@@ -29,6 +31,21 @@ internal String IdAttribute
2931

3032
#region Methods
3133

34+
/// <inheritdoc />
35+
public override IElement ParseSubtree(String html)
36+
{
37+
var context = ((IElement)this).Owner?.Context;
38+
var source = new TextSource(html);
39+
var document = new XmlDocument(context, source);
40+
var parser = new XmlDomBuilder(document);
41+
var options = new XmlParserOptions
42+
{
43+
IsSuppressingErrors = true,
44+
};
45+
return parser.ParseFragment(options, this).DocumentElement;
46+
}
47+
48+
/// <inheritdoc />
3249
public override Node Clone(Document owner, Boolean deep)
3350
{
3451
var node = new XmlElement(owner, LocalName, Prefix);

src/AngleSharp.Xml/Dtd/Declaration/Attribute/AttributeDeclarationEntry.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public String Name
2222

2323
public AttributeTypeDeclaration Type
2424
{
25-
get { return _type; }
25+
get => _type;
2626
set
2727
{
2828
_type = value;
@@ -32,7 +32,7 @@ public AttributeTypeDeclaration Type
3232

3333
public AttributeValueDeclaration Default
3434
{
35-
get { return _value; }
35+
get => _value;
3636
set
3737
{
3838
_value = value;

src/AngleSharp.Xml/Dtd/Declaration/Element/ElementDeclarationEntry.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ abstract class ElementQuantifiedDeclarationEntry : ElementDeclarationEntry
4646

4747
public ElementQuantifier Quantifier
4848
{
49-
get { return _quantifier; }
50-
set { _quantifier = value; }
49+
get => _quantifier;
50+
set => _quantifier = value;
5151
}
5252
}
5353

src/AngleSharp.Xml/Dtd/Parser/DtdContainer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public Node this[Int32 index]
6666
/// </summary>
6767
public Boolean IsInvalid
6868
{
69-
get { return _invalid; }
69+
get => _invalid;
7070
private set
7171
{
7272
_invalid = value;
@@ -90,8 +90,8 @@ public XmlDocument Parent
9090
/// </summary>
9191
public String Url
9292
{
93-
get { return _url ?? (Parent != null ? Parent.BaseUri : String.Empty); }
94-
set { _url = value; }
93+
get => _url ?? (Parent != null ? Parent.BaseUri : String.Empty);
94+
set => _url = value;
9595
}
9696

9797
/// <summary>

src/AngleSharp.Xml/Dtd/Parser/DtdParser.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ public DtdParser(DtdContainer container, TextSource source)
5353
/// </summary>
5454
public Boolean IsInternal
5555
{
56-
get { return _tokenizer.IsExternal; }
57-
set { _tokenizer.IsExternal = !value; }
56+
get => _tokenizer.IsExternal;
57+
set => _tokenizer.IsExternal = !value;
5858
}
5959

6060
/// <summary>

src/AngleSharp.Xml/Dtd/Parser/DtdTokenizer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public String Content
7878
/// </summary>
7979
public Boolean IsExternal
8080
{
81-
get { return _external; }
81+
get => _external;
8282
set
8383
{
8484
_external = value;

src/AngleSharp.Xml/Dtd/Parser/Tokens/DtdCommentToken.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ public DtdCommentToken()
2727
/// </summary>
2828
public String Data
2929
{
30-
get { return _data; }
31-
set { _data = value; }
30+
get => _data;
31+
set => _data = value;
3232
}
3333

3434
#endregion

src/AngleSharp.Xml/Dtd/Parser/Tokens/DtdNotationToken.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@ public Boolean IsPublicId
4949
/// </summary>
5050
public String PublicIdentifier
5151
{
52-
get { return _publicIdentifier ?? String.Empty; }
53-
set { _publicIdentifier = value; }
52+
get => _publicIdentifier ?? String.Empty;
53+
set => _publicIdentifier = value;
5454
}
5555

5656
/// <summary>
5757
/// Gets or sets the value of the system identifier.
5858
/// </summary>
5959
public String SystemIdentifier
6060
{
61-
get { return _systemIdentifier ?? String.Empty; }
62-
set { _systemIdentifier = value; }
61+
get => _systemIdentifier ?? String.Empty;
62+
set => _systemIdentifier = value;
6363
}
6464

6565
#endregion

0 commit comments

Comments
 (0)