Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ jobs:
id: check_job
run: |
echo "value: ${{ env.DOCS_PATH != null && github.ref == env.DOCS_BRANCH }}"
echo "::set-output name=value::${{ env.DOCS_PATH != null && github.ref == env.DOCS_BRANCH }}"
echo "value=${{ env.DOCS_PATH != null && github.ref == env.DOCS_BRANCH }}" >> "${GITHUB_OUTPUT}"

documentation:
needs: [can_document]
runs-on: ubuntu-latest
if: needs.can_document.outputs.value == 'true'

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: "14.x"
registry-url: 'https://registry.npmjs.org'
Expand All @@ -48,10 +48,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Setup dotnet
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.0.x
Expand All @@ -64,10 +64,10 @@ jobs:
runs-on: windows-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Setup dotnet
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.0.x
Expand Down
26 changes: 18 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
# 1.0.6

Released on Saturday, November 11 2023

- Fixed case-sensitiveness in virtual responses
- Fixed warning for outdated actions in CI/CD workflow (#1145) @martincostello
- Fixed AoT warning when trimming (#1144) @martincostello
- Fixed decoding of entities in `InnerHtml` of `<noscript>` (#1139)
- Updated `PrettyMarkupFormatter` to keep new lines on demand (#1131) @dramlian

# 1.0.5

Released on Tuesday, October 3 2023
Released on Tuesday, October 3 2023

- Improved codebase (#1128, #1126, #1133) @matkoch @ivandrofly
- Improved documentation (#1127)
- Improved child selector performance (#1135) @lahma
- Improved query selector all performance (#584, #1134) @lahma
- Fixed issue with foreign content using end tags
- Fixed typo `descendants` (#1136) @SimonCropp
- Added a way to resolve symbols by their name to `HtmlEntityProvider` (#396)
- Improved codebase (#1128, #1126, #1133) @matkoch @ivandrofly
- Improved documentation (#1127)
- Improved child selector performance (#1135) @lahma
- Improved query selector all performance (#584, #1134) @lahma
- Fixed issue with foreign content using end tags
- Fixed typo `descendants` (#1136) @SimonCropp
- Added a way to resolve symbols by their name to `HtmlEntityProvider` (#396)

# 1.0.4

Expand Down
16 changes: 16 additions & 0 deletions src/AngleSharp.Core.Tests/Html/HtmlEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ namespace AngleSharp.Core.Tests.Html
{
using AngleSharp.Dom;
using AngleSharp.Html;
using AngleSharp.Html.Parser;
using NUnit.Framework;

/// <summary>
Expand Down Expand Up @@ -1042,5 +1043,20 @@ public void ResolveNameBySymbol_Issue396()
var result = reverseResolver.GetName(resolver.GetSymbol(symbol));
Assert.AreEqual(symbol, result);
}

[Test]
public void EntityDecodingInNoScript_Issue1139()
{
var html = @"<html></head><body><noscript><div></div></noscript></body></html>";
var parser = new HtmlParser(new HtmlParserOptions
{
IsScripting = true
});
var dom = parser.ParseDocument(html);
var noscript = dom.QuerySelector("noscript");
Assert.AreEqual("<div></div>", noscript.InnerHtml);
noscript.InnerHtml = noscript.InnerHtml.Replace("<", "&lt;").Replace(">", "&gt;");
Assert.AreEqual("&lt;div&gt;&lt;/div&gt;", noscript.InnerHtml);
}
}
}
37 changes: 33 additions & 4 deletions src/AngleSharp.Core.Tests/Library/PrettyMarkupPrinter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace AngleSharp.Core.Tests.Library
using AngleSharp.Html;
using NUnit.Framework;
using System;
using System.Collections.Generic;

[TestFixture]
public class PrettyMarkupPrinter
Expand Down Expand Up @@ -164,16 +165,44 @@ public void SpacedConsecutivePrependedTextNodesKeepSpace()
Assert.AreEqual(result.Replace(Environment.NewLine, "\n"), output);
}

[Test]
public void PreservingFormatting_Issue1131()
{
var document = "<!DOCTYPE html><html lang=\"en\"><head><title>Some Title</title></head><body><h1>Test</h1><pre><code class=\"language-F#\">let a = \"something\"\nlet b = \"something else\"\nlet c = \"something completely different\"\n</code></pre></body></html>".ToHtmlDocument();
IEnumerable<INode> toPreserve=new List<INode>() { document.QuerySelector("code")};
var output = Print(document, toPreserve);
var result = @"<!DOCTYPE html>
<html lang=""en"">
<head>
<title>Some Title</title>
</head>
<body>
<h1>Test</h1>
<pre>
<code class=""language-F#"">let a = ""something""
let b = ""something else""
let c = ""something completely different""
</code>
</pre>
</body>
</html>";

Assert.AreEqual(result.Replace(Environment.NewLine, "\n"), output);
}

private static String Print(IDocument document, IEnumerable<INode> toPreserve)
{
return document.ToHtml(new PrettyMarkupFormatter(toPreserve));
}

private static String Print(String html)
{
var document = html.ToHtmlDocument();
return Print(document);
return Print(html.ToHtmlDocument());
}

private static String Print(IDocument document)
{
var formatter = new PrettyMarkupFormatter();
return document.ToHtml(formatter);
return document.ToHtml(new PrettyMarkupFormatter());
}
}
}
4 changes: 4 additions & 0 deletions src/AngleSharp/Common/ObjectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,11 @@ public static Double Constraint(this Double value, Double min, Double max)
/// </summary>
/// <param name="code">A specific error code.</param>
/// <returns>The description of the error.</returns>
#if NET6_0_OR_GREATER
public static String GetMessage<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] T>(this T code)
#else
public static String GetMessage<T>(this T code)
#endif
where T : Enum
{
var field = typeof(T).GetField(code.ToString());
Expand Down
2 changes: 1 addition & 1 deletion src/AngleSharp/Html/Parser/HtmlDomBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public HtmlDocument ParseFragment(HtmlParserOptions options, Element context)
{
_tokenizer.State = HtmlParseMode.Plaintext;
}
else if (tagName.Is(TagNames.NoScript) && options.IsScripting)
else if (tagName.Is(TagNames.NoScript) && (options.IsScripting || context.Flags.HasFlag(NodeFlags.LiteralText)))
{
_tokenizer.State = HtmlParseMode.Rawtext;
}
Expand Down
24 changes: 22 additions & 2 deletions src/AngleSharp/Html/PrettyMarkupFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace AngleSharp.Html
using AngleSharp.Dom;
using AngleSharp.Text;
using System;
using System.Collections.Generic;
using System.Linq;

/// <summary>
Expand All @@ -15,6 +16,7 @@ public class PrettyMarkupFormatter : HtmlMarkupFormatter
private String _indentString;
private String _newLineString;
private Int32 _indentCount;
private IEnumerable<INode>? _preserveTextFormatting;

#endregion

Expand All @@ -30,6 +32,20 @@ public PrettyMarkupFormatter()
_newLineString = "\n";
}

/// <summary>
/// Creates a new instance of the pretty markup formatter,
/// along with nodes where formatting of text shall be ignored
/// </summary>
/// <param name="preserveTextFormatting">Nodes in which the structure of the
/// text content should be preserved</param>
public PrettyMarkupFormatter(IEnumerable<INode> preserveTextFormatting)
{
_indentCount = 0;
_indentString = "\t";
_newLineString = "\n";
_preserveTextFormatting = preserveTextFormatting.SelectMany(x => (IEnumerable<INode>)x.ChildNodes).Where(y => y is ICharacterData);
}

#endregion

#region Properties
Expand Down Expand Up @@ -80,6 +96,10 @@ public override String Processing(IProcessingInstruction processing) =>
/// <inheritdoc />
public override String Text(ICharacterData text)
{
if (_preserveTextFormatting?.Contains(text) == true)
{
return text.Data.TrimEnd('\n').Replace("\n", IndentBefore(1));
}
var content = text.Data;
var before = String.Empty;
var singleLine = content.Replace(Symbols.LineFeed, Symbols.Space);
Expand All @@ -95,7 +115,7 @@ public override String Text(ICharacterData text)
before = IndentBefore();
}

return before + HtmlMarkupFormatter.EscapeText(singleLine);
return before + EscapeText(singleLine);
}

/// <inheritdoc />
Expand Down Expand Up @@ -138,7 +158,7 @@ private static Boolean EndsWithSpace(ICharacterData text)
return content.Length > 0 && content[content.Length - 1].IsSpaceCharacter();
}

private String IndentBefore() => _newLineString + String.Join(String.Empty, Enumerable.Repeat(_indentString, _indentCount));
private String IndentBefore(int i=0) => _newLineString + String.Join(String.Empty, Enumerable.Repeat(_indentString, _indentCount-i));

#endregion
}
Expand Down
2 changes: 1 addition & 1 deletion src/AngleSharp/Io/VirtualResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private VirtualResponse()
{
_address = Url.Create("http://localhost/");
_status = HttpStatusCode.OK;
_headers = new Dictionary<String, String>();
_headers = new Dictionary<String, String>(StringComparer.OrdinalIgnoreCase);
_content = MemoryStream.Null;
_dispose = false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<Description>AngleSharp is the ultimate angle brackets parser library. It parses HTML5, CSS3, and XML to construct a DOM based on the official W3C specification.</Description>
<Product>AngleSharp</Product>
<Version>1.0.5</Version>
<Version>1.0.6</Version>
<LangVersion>latest</LangVersion>
<SignAssembly>true</SignAssembly>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
Expand Down