Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clippit 2.0 #41

Merged
merged 73 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
0444f98
feat: migration to .net6
sergey-tihon Nov 12, 2021
b22f61d
feat: add dependency to SixLabors.ImageSharp.Drawing
sergey-tihon Nov 21, 2021
573cfba
feat: migrate from Bitmap to ImageSharp Image
sergey-tihon Nov 21, 2021
670026a
faet: remove dependency on System.Drawing.Common
sergey-tihon Nov 21, 2021
cf74ad6
fix: do not install libgdiplus
sergey-tihon Nov 21, 2021
a537917
fix: tests (ignore not existing files)
sergey-tihon Nov 21, 2021
12c62b8
feat: FAKE dependencies update
sergey-tihon Nov 21, 2021
7066705
feat: release notes
sergey-tihon Nov 21, 2021
565be0c
hk: refact & cleanup
sergey-tihon Nov 21, 2021
e9cf8a8
hk: auto-props
sergey-tihon Nov 21, 2021
0f78d52
feat: merge CalcWidthOfRun implementations
sergey-tihon Nov 22, 2021
ea4617d
feat: unified relId generation
sergey-tihon Nov 22, 2021
08c0f96
feat: project renamed
sergey-tihon Nov 22, 2021
230de20
fix: remove unused test
sergey-tihon Nov 22, 2021
27e0c6d
fix: remove unused test files
sergey-tihon Nov 22, 2021
9424399
hr: refactor to Clippit.Excel ns
sergey-tihon Nov 22, 2021
ecf2de0
hk: moved WmlDocument to Clippit.Word namespace
sergey-tihon Nov 22, 2021
d6b403d
hk: moved PmlDocument to Clippit.PowerPoint namespace
sergey-tihon Nov 22, 2021
b07ba0c
hk: namespaces cleanup
sergey-tihon Nov 22, 2021
ea6442c
hk: remove duplicated block
sergey-tihon Nov 22, 2021
3adce21
Revert "hk: remove duplicated block"
sergey-tihon Nov 23, 2021
02e4b72
fix: restore both blocks
sergey-tihon Nov 23, 2021
fc8f671
Merge branch 'master' into net6
sergey-tihon Jan 28, 2022
4e10b86
fix: code cleanup
sergey-tihon Feb 9, 2022
8c3abd3
fix: stream usage
sergey-tihon Feb 9, 2022
33d046a
Merge branch 'feat/fix-streams' into net6
sergey-tihon Feb 9, 2022
dd827b3
feat: SixLabors.ImageSharp 2.0.0 & Co
sergey-tihon Feb 11, 2022
4e6aa3a
feat: 2.0.0-beta1 release
sergey-tihon Feb 12, 2022
a8f7c0f
feat: using refactoring
sergey-tihon Feb 12, 2022
91cb338
feat: inline out var declaration
sergey-tihon Feb 12, 2022
b82ced6
feat: or patter matching
sergey-tihon Feb 12, 2022
f8f9b31
feat: index from end expression
sergey-tihon Feb 12, 2022
0551e7c
feat: substring range
sergey-tihon Feb 12, 2022
5750eb2
feat: string interpolation
sergey-tihon Feb 12, 2022
118bad8
feat: explicit private modifier
sergey-tihon Feb 12, 2022
8d4ab59
feat: readonly fields
sergey-tihon Feb 12, 2022
127ef2c
feat: switch expressions
sergey-tihon Feb 12, 2022
c24356c
feat: use var
sergey-tihon Feb 12, 2022
f7732af
feat: type keyword
sergey-tihon Feb 12, 2022
6e8b1ba
fix: lang version
sergey-tihon Feb 12, 2022
fb735ce
revert: index from end
sergey-tihon Feb 12, 2022
0be53c7
revert: subsrting range
sergey-tihon Feb 13, 2022
8901f48
feat: string interpolation
sergey-tihon Feb 13, 2022
e16d52b
feat: remove NET35 conditions and format validation against new schemas
sergey-tihon Feb 13, 2022
874fff8
feat: disposable analysers and major fixes
sergey-tihon Feb 13, 2022
2a45bd3
feat: more switch expressions
sergey-tihon Feb 13, 2022
f4b7aba
feat: some formatting
sergey-tihon Feb 13, 2022
425ad89
feat: remove redundant ToString()
sergey-tihon Feb 13, 2022
119c413
feat: some formatting
sergey-tihon Feb 13, 2022
f4138e1
Merge branch 'master' into net6
sergey-tihon Feb 17, 2022
bd5bcb8
Merge branch 'master' into net6
sergey-tihon Feb 19, 2022
776c327
Merge branch 'master' into net6
sergey-tihon Mar 16, 2022
601d3db
Merge branch 'master' into net6
sergey-tihon May 29, 2022
19f50bd
fix: docs generation
sergey-tihon May 29, 2022
6f28bd0
Merge branch 'master' into net6
sergey-tihon Jun 2, 2022
f315658
Merge branch 'master' into net6
sergey-tihon Jul 11, 2022
9c97cd7
feat: public TextReplacer & dependencies update
sergey-tihon Aug 4, 2022
44cc95a
Merge branch 'master' into net6
sergey-tihon Oct 4, 2022
c0fae74
Merge branch 'master' into net6
sergey-tihon Dec 5, 2022
38c27ea
fix: deps on 7.0 System packages
sergey-tihon Dec 6, 2022
4621959
Merge branch 'master' into net6
sergey-tihon Mar 27, 2023
0ff1848
DocumentFormat.OpenXml 3.0 beta 3 (IPackage) (#63)
sergey-tihon Sep 7, 2023
f414e2b
feat: nuget release
sergey-tihon Sep 7, 2023
75798f5
feat: drop support of .net standard (#69)
sergey-tihon Sep 8, 2023
26c5eb1
WIP: DocumentFormat.OpenXml v3 and deps update (#71)
sergey-tihon Nov 26, 2023
d2bdc80
fix: remove redundant type casts
sergey-tihon Nov 26, 2023
66720b3
fix: remove redundant control flow jump statements
sergey-tihon Nov 26, 2023
1a26dcb
fix: Initializing field by default value is redundant
sergey-tihon Nov 26, 2023
44f4560
fix: Comparison with true is redundant
sergey-tihon Nov 26, 2023
7f2c765
fix: join declarations and assignments
sergey-tihon Nov 26, 2023
3eaac54
fix: Using directive is not required by the code and can be safely re…
sergey-tihon Nov 26, 2023
d777c31
fix: Redundant 'Object.ToString()' call
sergey-tihon Nov 26, 2023
2321c28
fix: Qualifier is redundant
sergey-tihon Nov 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
"isRoot": true,
"tools": {
"paket": {
"version": "7.2.1",
"version": "8.0.0",
"commands": [
"paket"
]
},
"fake-cli": {
"version": "5.20.4",
"version": "6.0.0",
"commands": [
"fake"
]
Expand Down
11 changes: 3 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
pull_request:
branches:
- master
- net6

jobs:
build:
Expand All @@ -15,7 +16,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
dotnet: [5.0.408]
dotnet: [6.0.407]
runs-on: ${{ matrix.os }}

steps:
Expand All @@ -25,12 +26,6 @@ jobs:
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ matrix.dotnet }}
- name: Install libgdiplus on macOS
if: matrix.os == 'macOS-latest'
run: brew install mono-libgdiplus
- name: Install libgdiplus on Ubuntu
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get update -y && sudo apt-get install -y libgdiplus
- name: Install local tools
run: dotnet tool restore
- name: Paket Restore
Expand All @@ -53,7 +48,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.408
dotnet-version: 6.0.407
- name: Install local tools
run: dotnet tool restore
- name: Paket Restore
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net5.0</TargetFrameworks>
<TargetFramework>net6.0</TargetFramework>
<RollForward>LatestMajor</RollForward>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<LangVersion>9.0</LangVersion>
<LangVersion>latest</LangVersion>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<RootNamespace>Clippit.Tests</RootNamespace>
<AssemblyName>Clippit.Tests</AssemblyName>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\OpenXmlPowerTools\OpenXmlPowerTools.csproj" />
<ProjectReference Include="..\Clippit\Clippit.csproj" />
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Globalization;
using System.IO;
using Clippit.PowerPoint;
using Clippit.Word;
using DocumentFormat.OpenXml.Packaging;
using Xunit;
using Xunit.Abstractions;
Expand Down Expand Up @@ -229,7 +232,7 @@ public void CU001(string name)

private static string ToExcelInteger(DateTime dateTime)
{
return dateTime.ToOADate().ToString();
return dateTime.ToOADate().ToString(CultureInfo.CurrentCulture);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

using System.IO;
using System.Xml.Linq;
using Clippit.Excel;
using Clippit.PowerPoint;
using Clippit.Word;
using Xunit;
using Xunit.Abstractions;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -225,165 +224,152 @@ private static string InnerDelText(XContainer e)
[Fact]
public void CanReplaceTextWithQuotationMarks()
{
XDocument partDocument = XDocument.Parse(QuotationMarksDocumentXmlString);
XElement p = partDocument.Descendants(W.p).First();
string innerText = InnerText(p);
var partDocument = XDocument.Parse(QuotationMarksDocumentXmlString);
var p = partDocument.Descendants(W.p).First();
var innerText = InnerText(p);

Assert.Equal(
"Text can be enclosed in “normal double quotes” and in «double angle quotation marks».",
innerText);

using (var stream = new MemoryStream())
using (WordprocessingDocument wordDocument = WordprocessingDocument.Create(stream, DocumentType))
{
MainDocumentPart part = wordDocument.AddMainDocumentPart();
part.PutXDocument(partDocument);

IEnumerable<XElement> content = partDocument.Descendants(W.p);
var regex = new Regex(string.Format("{0}(?<words>{1}){2}", LeftDoubleQuotationMarks, Words,
RightDoubleQuotationMarks));
int count = OpenXmlRegex.Replace(content, regex, "‘changed ${words}’", null);

p = partDocument.Descendants(W.p).First();
innerText = InnerText(p);

Assert.Equal(2, count);
Assert.Equal(
"Text can be enclosed in ‘changed normal double quotes’ and in ‘changed double angle quotation marks’.",
innerText);
}
using var stream = new MemoryStream();
using var wordDocument = WordprocessingDocument.Create(stream, DocumentType);
var part = wordDocument.AddMainDocumentPart();
part.PutXDocument(partDocument);

var content = partDocument.Descendants(W.p);
var regex = new Regex($"{LeftDoubleQuotationMarks}(?<words>{Words}){RightDoubleQuotationMarks}");
var count = OpenXmlRegex.Replace(content, regex, "‘changed ${words}’", null);

p = partDocument.Descendants(W.p).First();
innerText = InnerText(p);

Assert.Equal(2, count);
Assert.Equal(
"Text can be enclosed in ‘changed normal double quotes’ and in ‘changed double angle quotation marks’.",
innerText);
}

[Fact]
public void CanReplaceTextWithQuotationMarksAndAddTrackedChangesWhenReplacing()
{
XDocument partDocument = XDocument.Parse(QuotationMarksDocumentXmlString);
XElement p = partDocument.Descendants(W.p).First();
string innerText = InnerText(p);
var partDocument = XDocument.Parse(QuotationMarksDocumentXmlString);
var p = partDocument.Descendants(W.p).First();
var innerText = InnerText(p);

Assert.Equal(
"Text can be enclosed in “normal double quotes” and in «double angle quotation marks».",
innerText);

using (var stream = new MemoryStream())
using (WordprocessingDocument wordDocument = WordprocessingDocument.Create(stream, DocumentType))
{
MainDocumentPart part = wordDocument.AddMainDocumentPart();
part.PutXDocument(partDocument);
using var stream = new MemoryStream();
using var wordDocument = WordprocessingDocument.Create(stream, DocumentType);
var part = wordDocument.AddMainDocumentPart();
part.PutXDocument(partDocument);

IEnumerable<XElement> content = partDocument.Descendants(W.p);
var regex = new Regex(string.Format("{0}(?<words>{1}){2}", LeftDoubleQuotationMarks, Words,
RightDoubleQuotationMarks));
int count = OpenXmlRegex.Replace(content, regex, "‘changed ${words}’", null, true, "John Doe");
var content = partDocument.Descendants(W.p);
var regex = new Regex($"{LeftDoubleQuotationMarks}(?<words>{Words}){RightDoubleQuotationMarks}");
var count = OpenXmlRegex.Replace(content, regex, "‘changed ${words}’", null, true, "John Doe");

p = partDocument.Descendants(W.p).First();
innerText = InnerText(p);
p = partDocument.Descendants(W.p).First();
innerText = InnerText(p);

Assert.Equal(2, count);
Assert.Equal(
"Text can be enclosed in ‘changed normal double quotes’ and in ‘changed double angle quotation marks’.",
innerText);
Assert.Equal(2, count);
Assert.Equal(
"Text can be enclosed in ‘changed normal double quotes’ and in ‘changed double angle quotation marks’.",
innerText);

Assert.Contains(p.Elements(W.ins), e => InnerText(e) == "‘changed normal double quotes’");
Assert.Contains(p.Elements(W.ins), e => InnerText(e) == "‘changed double angle quotation marks’");
Assert.Contains(p.Elements(W.ins), e => InnerText(e) == "‘changed normal double quotes’");
Assert.Contains(p.Elements(W.ins), e => InnerText(e) == "‘changed double angle quotation marks’");

Assert.Contains(p.Elements(W.del), e => InnerDelText(e) == "“normal double quotes”");
Assert.Contains(p.Elements(W.del), e => InnerDelText(e) == "«double angle quotation marks»");
}
Assert.Contains(p.Elements(W.del), e => InnerDelText(e) == "“normal double quotes”");
Assert.Contains(p.Elements(W.del), e => InnerDelText(e) == "«double angle quotation marks»");
}

[Fact]
public void CanReplaceTextWithQuotationMarksAndTrackedChanges()
{
XDocument partDocument = XDocument.Parse(QuotationMarksAndTrackedChangesDocumentXmlString);
XElement p = partDocument.Descendants(W.p).First();
string innerText = InnerText(p);
var partDocument = XDocument.Parse(QuotationMarksAndTrackedChangesDocumentXmlString);
var p = partDocument.Descendants(W.p).First();
var innerText = InnerText(p);

Assert.Equal(
"Text can be enclosed in “normal double quotes” and in «double angle quotation marks».",
innerText);

using (var stream = new MemoryStream())
using (WordprocessingDocument wordDocument = WordprocessingDocument.Create(stream, DocumentType))
{
MainDocumentPart part = wordDocument.AddMainDocumentPart();
part.PutXDocument(partDocument);
using var stream = new MemoryStream();
using var wordDocument = WordprocessingDocument.Create(stream, DocumentType);
var part = wordDocument.AddMainDocumentPart();
part.PutXDocument(partDocument);

IEnumerable<XElement> content = partDocument.Descendants(W.p);
var regex = new Regex(string.Format("{0}(?<words>{1}){2}", LeftDoubleQuotationMarks, Words,
RightDoubleQuotationMarks));
int count = OpenXmlRegex.Replace(content, regex, "‘changed ${words}’", null, true, "John Doe");
var content = partDocument.Descendants(W.p);
var regex = new Regex($"{LeftDoubleQuotationMarks}(?<words>{Words}){RightDoubleQuotationMarks}");
var count = OpenXmlRegex.Replace(content, regex, "‘changed ${words}’", null, true, "John Doe");

p = partDocument.Descendants(W.p).First();
innerText = InnerText(p);
p = partDocument.Descendants(W.p).First();
innerText = InnerText(p);

Assert.Equal(2, count);
Assert.Equal(
"Text can be enclosed in ‘changed normal double quotes’ and in ‘changed double angle quotation marks’.",
innerText);
Assert.Equal(2, count);
Assert.Equal(
"Text can be enclosed in ‘changed normal double quotes’ and in ‘changed double angle quotation marks’.",
innerText);

Assert.Contains(p.Elements(W.ins), e => InnerText(e) == "‘changed normal double quotes’");
Assert.Contains(p.Elements(W.ins), e => InnerText(e) == "‘changed double angle quotation marks’");
}
Assert.Contains(p.Elements(W.ins), e => InnerText(e) == "‘changed normal double quotes’");
Assert.Contains(p.Elements(W.ins), e => InnerText(e) == "‘changed double angle quotation marks’");
}

[Fact]
public void CanReplaceTextWithSymbolsAndTrackedChanges()
{
XDocument partDocument = XDocument.Parse(SymbolsAndTrackedChangesDocumentXmlString);
XElement p = partDocument.Descendants(W.p).First();
string innerText = InnerText(p);
var partDocument = XDocument.Parse(SymbolsAndTrackedChangesDocumentXmlString);
var p = partDocument.Descendants(W.p).First();
var innerText = InnerText(p);

Assert.Equal("We can also use symbols such as \uF021 or \uF028.", innerText);

using (var stream = new MemoryStream())
using (WordprocessingDocument wordDocument = WordprocessingDocument.Create(stream, DocumentType))
{
MainDocumentPart part = wordDocument.AddMainDocumentPart();
part.PutXDocument(partDocument);
using var stream = new MemoryStream();
using var wordDocument = WordprocessingDocument.Create(stream, DocumentType);
var part = wordDocument.AddMainDocumentPart();
part.PutXDocument(partDocument);

IEnumerable<XElement> content = partDocument.Descendants(W.p);
var regex = new Regex(@"[\uF021]");
int count = OpenXmlRegex.Replace(content, regex, "\uF028", null, true, "John Doe");
var content = partDocument.Descendants(W.p);
var regex = new Regex(@"[\uF021]");
var count = OpenXmlRegex.Replace(content, regex, "\uF028", null, true, "John Doe");

p = partDocument.Descendants(W.p).First();
innerText = InnerText(p);
p = partDocument.Descendants(W.p).First();
innerText = InnerText(p);

Assert.Equal(1, count);
Assert.Equal("We can also use symbols such as \uF028 or \uF028.", innerText);
Assert.Equal(1, count);
Assert.Equal("We can also use symbols such as \uF028 or \uF028.", innerText);

Assert.Contains(p.Descendants(W.ins), ins => ins.Descendants(W.sym).Any(
sym => sym.Attribute(W.font).Value == "Wingdings" &&
sym.Attribute(W._char).Value == "F028"));
}
Assert.Contains(p.Descendants(W.ins), ins => ins.Descendants(W.sym).Any(
sym => sym.Attribute(W.font).Value == "Wingdings" &&
sym.Attribute(W._char).Value == "F028"));
}

[Fact]
public void CanReplaceTextWithFields()
{
XDocument partDocument = XDocument.Parse(FieldsDocumentXmlString);
XElement p = partDocument.Descendants(W.p).Last();
string innerText = InnerText(p);
var partDocument = XDocument.Parse(FieldsDocumentXmlString);
var p = partDocument.Descendants(W.p).Last();
var innerText = InnerText(p);

Assert.Equal("As stated in Article {__1} and this Section {__1.1}, this is described in Schedule C (Performance Framework).",
innerText);

using (var stream = new MemoryStream())
using (WordprocessingDocument wordDocument = WordprocessingDocument.Create(stream, DocumentType))
{
MainDocumentPart part = wordDocument.AddMainDocumentPart();
part.PutXDocument(partDocument);
using var stream = new MemoryStream();
using var wordDocument = WordprocessingDocument.Create(stream, DocumentType);
var part = wordDocument.AddMainDocumentPart();
part.PutXDocument(partDocument);

IEnumerable<XElement> content = partDocument.Descendants(W.p);
var regex = new Regex(@"Schedule C \(Performance Framework\)");
int count = OpenXmlRegex.Replace(content, regex, "Exhibit 4", null, true, "John Doe");
var content = partDocument.Descendants(W.p);
var regex = new Regex(@"Schedule C \(Performance Framework\)");
var count = OpenXmlRegex.Replace(content, regex, "Exhibit 4", null, true, "John Doe");

p = partDocument.Descendants(W.p).Last();
innerText = InnerText(p);
p = partDocument.Descendants(W.p).Last();
innerText = InnerText(p);

Assert.Equal(1, count);
Assert.Equal("As stated in Article {__1} and this Section {__1.1}, this is described in Exhibit 4.", innerText);
}
Assert.Equal(1, count);
Assert.Equal("As stated in Article {__1} and this Section {__1.1}, this is described in Exhibit 4.", innerText);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Globalization;
using System.IO;
using Clippit.Word;
using DocumentFormat.OpenXml.Packaging;
using Xunit;
using Xunit.Abstractions;
Expand Down Expand Up @@ -212,7 +214,7 @@ public void UpdatePowerPoints(string fileName)

private static string ToExcelInteger(DateTime dateTime)
{
return dateTime.ToOADate().ToString();
return dateTime.ToOADate().ToString(CultureInfo.CurrentCulture);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.IO;
using System.IO;
using Xunit;
using Xunit.Abstractions;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using Clippit.Internal;
using DocumentFormat.OpenXml.Packaging;
using Xunit;
using Xunit.Abstractions;
Expand Down
Loading
Loading