Skip to content

Commit 3071e62

Browse files
authored
Release 3.2.6
Release 3.2.6
2 parents 03b5fb1 + a795aee commit 3071e62

File tree

8 files changed

+96
-28
lines changed

8 files changed

+96
-28
lines changed

.github/workflows/publish_nuget.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# This workflow will build, pack and deploy the solution on Nuget
2+
3+
name: 'publish_nuget.yml'
4+
5+
on:
6+
push:
7+
tags:
8+
- '[0-9]+.[0-9]+'
9+
branches:
10+
- master
11+
12+
jobs:
13+
publish:
14+
if: startsWith(github.ref, 'refs/tags/') && github.ref_type == 'tag' && github.ref_name != ''
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
- name: Ensure tag is on master
19+
run: |
20+
TAG_COMMIT=$(git rev-list -n 1 ${{ github.ref_name }})
21+
if ! git merge-base --is-ancestor $TAG_COMMIT origin/master; then
22+
echo "Tag is not on master branch. Skipping publish."
23+
exit 1
24+
fi
25+
- name: Setup .NET 8.
26+
uses: actions/setup-dotnet@v4
27+
with:
28+
dotnet-version: '8.0.x'
29+
- name: Build
30+
run: dotnet build --configuration Release
31+
- name: Pack
32+
run: dotnet pack src/Html2OpenXml/HtmlToOpenXml.csproj --configuration Release --output ./nupkg
33+
- name: Push nuget to NuGet.org
34+
run: dotnet nuget push ./nupkg/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json
35+
- name: Create Release and Upload Artifact to Release
36+
run: gh release create ${{github.ref_name}} -t "Release ${{github.ref_name}}" *.nupkg --generate-notes --draft

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 3.2.6
4+
5+
- Fix handling Uri with an anchor #209
6+
- New option DefaultStyles.NumberedHeadingStyle to support an alternate heading style #210
7+
38
## 3.2.5
49

510
- Fix a crash with the new whitespace handling introduced in 3.2.3 #191

src/Html2OpenXml/Expressions/HyperlinkExpression.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,6 @@ public override IEnumerable<OpenXmlElement> Interpret (ParsingContext context)
112112
{
113113
h = new Hyperlink() { History = true, Anchor = "_top" };
114114
}
115-
// is it an anchor?
116-
else if (context.Converter.SupportsAnchorLinks && linkNode.Hash.Length > 1 && linkNode.Hash[0] == '#')
117-
{
118-
h = new Hyperlink(
119-
) { History = true, Anchor = linkNode.Hash.Substring(1) };
120-
}
121115
// ensure the links does not start with javascript:
122116
else if (AngleSharpExtensions.TryParseUrl(att, UriKind.Absolute, out var uri))
123117
{
@@ -126,6 +120,13 @@ public override IEnumerable<OpenXmlElement> Interpret (ParsingContext context)
126120
h = new Hyperlink(
127121
) { History = true, Id = extLink.Id };
128122
}
123+
// is it an anchor?
124+
else if (context.Converter.SupportsAnchorLinks && linkNode.Hash.Length > 1 && linkNode.Hash[0] == '#')
125+
{
126+
h = new Hyperlink(
127+
)
128+
{ History = true, Anchor = linkNode.Hash.Substring(1) };
129+
}
129130

130131
if (h == null)
131132
{

src/Html2OpenXml/Expressions/Numbering/HeadingElementExpression.cs

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,43 @@ public override IEnumerable<OpenXmlElement> Interpret (ParsingContext context)
4040

4141
paragraph ??= new(childElements);
4242
paragraph.ParagraphProperties ??= new();
43-
paragraph.ParagraphProperties.ParagraphStyleId =
44-
context.DocumentStyle.GetParagraphStyle(context.DocumentStyle.DefaultStyles.HeadingStyle + level);
45-
43+
4644
var runElement = childElements.FirstOrDefault();
4745
if (runElement != null && context.Converter.SupportsHeadingNumbering && IsNumbering(runElement))
4846
{
49-
var abstractNumId = GetOrCreateListTemplate(context, HeadingNumberingName);
50-
var instanceId = GetListInstance(abstractNumId);
51-
if (!instanceId.HasValue)
47+
if (string.Equals(context.DocumentStyle.DefaultStyles.HeadingStyle, context.DocumentStyle.DefaultStyles.NumberedHeadingStyle))
5248
{
53-
instanceId = IncrementInstanceId(context, abstractNumId);
49+
// Only apply the numbering if a custom numbered heading style has not been defined.
50+
// If the user defined a custom numbered heading style (with numbering), Word has
51+
// the numbering automatically done.
52+
// Defining a numbering here messes that up, so we only add the numbering if
53+
// a specific numbering heading style has not been provided
54+
var abstractNumId = GetOrCreateListTemplate(context, HeadingNumberingName);
55+
var instanceId = GetListInstance(abstractNumId);
56+
57+
if (!instanceId.HasValue)
58+
{
59+
instanceId = IncrementInstanceId(context, abstractNumId);
60+
}
61+
62+
var numbering = context.MainPart.NumberingDefinitionsPart!.Numbering!;
63+
numbering.Append(
64+
new NumberingInstance(
65+
new AbstractNumId() { Val = abstractNumId }
66+
)
67+
{ NumberID = instanceId });
68+
SetNumbering(paragraph, level - '0', instanceId.Value);
5469
}
5570

56-
var numbering = context.MainPart.NumberingDefinitionsPart!.Numbering!;
57-
numbering.Append(
58-
new NumberingInstance(
59-
new AbstractNumId() { Val = abstractNumId }
60-
)
61-
{ NumberID = instanceId });
62-
SetNumbering(paragraph, level - '0', instanceId.Value);
71+
// Apply numbered heading style
72+
paragraph.ParagraphProperties.ParagraphStyleId =
73+
context.DocumentStyle.GetParagraphStyle(context.DocumentStyle.DefaultStyles.NumberedHeadingStyle + level);
74+
}
75+
else
76+
{
77+
// Apply normal heading style
78+
paragraph.ParagraphProperties.ParagraphStyleId =
79+
context.DocumentStyle.GetParagraphStyle(context.DocumentStyle.DefaultStyles.HeadingStyle + level);
6380
}
6481

6582
return [paragraph];

src/Html2OpenXml/HtmlToOpenXml.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
<AssemblyName>HtmlToOpenXml</AssemblyName>
1010
<RootNamespace>HtmlToOpenXml</RootNamespace>
1111
<PackageId>HtmlToOpenXml.dll</PackageId>
12-
<Version>3.2.5</Version>
12+
<Version>3.2.6</Version>
1313
<PackageIcon>icon.png</PackageIcon>
1414
<Copyright>Copyright 2009-$([System.DateTime]::Now.Year) Olivier Nizet</Copyright>
1515
<PackageReleaseNotes>See changelog https://github.com/onizet/html2openxml/blob/master/CHANGELOG.md</PackageReleaseNotes>
1616
<PackageReadmeFile>README.md</PackageReadmeFile>
1717
<PackageTags>office openxml netcore html</PackageTags>
18-
<AssemblyVersion>3.2.5</AssemblyVersion>
18+
<AssemblyVersion>3.2.6</AssemblyVersion>
1919
<PackageLicenseExpression>MIT</PackageLicenseExpression>
2020
<PackageProjectUrl>https://github.com/onizet/html2openxml</PackageProjectUrl>
2121
<RepositoryUrl>https://github.com/onizet/html2openxml</RepositoryUrl>

src/Html2OpenXml/Primitives/DefaultStyles.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ public class DefaultStyles
5454
/// <value>Heading</value>
5555
public string HeadingStyle { get; set; } = PredefinedStyles.Heading;
5656

57+
/// <summary>
58+
/// Default style for numbered headings
59+
/// Appends the level at the end of the style name
60+
/// </summary>
61+
/// <value>Heading</value>
62+
public string NumberedHeadingStyle { get; set; } = PredefinedStyles.Heading;
63+
5764
/// <summary>
5865
/// Default style for hyperlinks
5966
/// </summary>

test/HtmlToOpenXml.Tests/LinkTests.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ public class LinkTests : HtmlConverterTestBase
1616
[TestCase("://www.site.com")]
1717
[TestCase("www.site.com")]
1818
[TestCase("http://www.site.com")]
19-
public void ExternalLink_ShouldSucceed (string link)
19+
[TestCase("http://www.site.com/#anchor1", "http://www.site.com/#anchor1")]
20+
public void ExternalLink_ShouldSucceed(string link, string expectedUri = "http://www.site.com/")
2021
{
2122
var elements = converter.Parse($@"<a href=""{link}"" title=""Test Tooltip"">Test Caption</a>");
22-
AssertHyperlink(mainPart, elements);
23+
AssertHyperlink(mainPart, elements, expectedUri);
2324
}
2425

2526
[TestCase(@"<a href=""javascript:alert()"">Js</a>")]
@@ -193,7 +194,7 @@ public async Task ParseIntoDocumentPart_ReturnsHyperlinkParentedToPart (Type ope
193194
throw new NotSupportedException($"Test case not supported for {openXmlPartType.FullName}");
194195
}
195196

196-
AssertHyperlink(container, host.ChildElements);
197+
AssertHyperlink(container, host.ChildElements, "http://www.site.com/");
197198
AssertThatOpenXmlDocumentIsValid();
198199
}
199200

@@ -249,7 +250,8 @@ await converter.ParseBody(@"<a href='#_top'>Move to top
249250
Assert.That(rel.Uri.ToString(), Is.EqualTo("#_top"));
250251
}
251252

252-
private static void AssertHyperlink(OpenXmlPartContainer container, IEnumerable<OpenXmlElement> elements)
253+
private static void AssertHyperlink(OpenXmlPartContainer container, IEnumerable<OpenXmlElement> elements,
254+
string expectedUri)
253255
{
254256
Assert.That(elements.Count(), Is.EqualTo(1));
255257
Assert.Multiple(() => {
@@ -272,7 +274,7 @@ private static void AssertHyperlink(OpenXmlPartContainer container, IEnumerable<
272274
var extLink = container.HyperlinkRelationships.FirstOrDefault(r => r.Id == hyperlink.Id);
273275
Assert.That(extLink, Is.Not.Null);
274276
Assert.That(extLink.IsExternal, Is.EqualTo(true));
275-
Assert.That(extLink.Uri.AbsoluteUri, Is.EqualTo("http://www.site.com/"));
277+
Assert.That(extLink.Uri.AbsoluteUri, Is.EqualTo(expectedUri));
276278
}
277279
}
278280
}

test/HtmlToOpenXml.Tests/Utilities/MockHttpMessageHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public MockHttpMessageHandler(Func<Uri, Task<HttpResponseMessage>> getResponseFu
1616

1717
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
1818
{
19-
return await _getResponseFunc(request.RequestUri);
19+
return await _getResponseFunc(request.RequestUri!);
2020
}
2121
}
2222
}

0 commit comments

Comments
 (0)