Skip to content
This repository was archived by the owner on May 21, 2022. It is now read-only.

Commit 8de7389

Browse files
committed
feat: unfinished add image
1 parent 2341e42 commit 8de7389

File tree

10 files changed

+330
-29
lines changed

10 files changed

+330
-29
lines changed

TestFiles/Fail.jpg

11.1 KB
Loading

TestFiles/yaml.jpg

39.6 KB
Loading

md2docx.sln

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ VisualStudioVersion = 15.0.28307.757
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "md2docx", "md2docx\md2docx.csproj", "{57F2D503-1BD2-452E-8B5B-D513E92F204E}"
77
EndProject
8-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "md2docxTests", "md2docxTests\md2docxTests.csproj", "{5389AD7C-77B7-46FE-8876-6546F2AC1E58}"
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "md2docxTests", "md2docxTests\md2docxTests.csproj", "{7F4634A7-B081-47A1-85B1-241FEE59AD72}"
99
EndProject
1010
Global
1111
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -17,10 +17,10 @@ Global
1717
{57F2D503-1BD2-452E-8B5B-D513E92F204E}.Debug|Any CPU.Build.0 = Debug|Any CPU
1818
{57F2D503-1BD2-452E-8B5B-D513E92F204E}.Release|Any CPU.ActiveCfg = Release|Any CPU
1919
{57F2D503-1BD2-452E-8B5B-D513E92F204E}.Release|Any CPU.Build.0 = Release|Any CPU
20-
{5389AD7C-77B7-46FE-8876-6546F2AC1E58}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21-
{5389AD7C-77B7-46FE-8876-6546F2AC1E58}.Debug|Any CPU.Build.0 = Debug|Any CPU
22-
{5389AD7C-77B7-46FE-8876-6546F2AC1E58}.Release|Any CPU.ActiveCfg = Release|Any CPU
23-
{5389AD7C-77B7-46FE-8876-6546F2AC1E58}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{7F4634A7-B081-47A1-85B1-241FEE59AD72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{7F4634A7-B081-47A1-85B1-241FEE59AD72}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{7F4634A7-B081-47A1-85B1-241FEE59AD72}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{7F4634A7-B081-47A1-85B1-241FEE59AD72}.Release|Any CPU.Build.0 = Release|Any CPU
2424
EndGlobalSection
2525
GlobalSection(SolutionProperties) = preSolution
2626
HideSolutionNode = FALSE

md2docx/GeneratedCode.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
using DocumentFormat.OpenXml.Wordprocessing;
7-
using System;
8-
using Microsoft.Toolkit.Parsers.Markdown;
9-
using Microsoft.Toolkit.Parsers.Markdown.Blocks;
103
using DocumentFormat.OpenXml.Wordprocessing;
114
using DocumentFormat.OpenXml.Packaging;
125
using DocumentFormat.OpenXml;
13-
using Microsoft.Toolkit.Parsers.Markdown.Inlines;
146
using A = DocumentFormat.OpenXml.Drawing;
157
using Wp = DocumentFormat.OpenXml.Drawing.Wordprocessing;
168
using Pic = DocumentFormat.OpenXml.Drawing.Pictures;
17-
using Newtonsoft.Json.Linq;
189
namespace md2docx
1910
{
2011
/// <summary>

md2docx/ImageGetter.cs

Lines changed: 92 additions & 0 deletions
Large diffs are not rendered by default.

md2docx/md2docx.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
<HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
7474
</Reference>
7575
<Reference Include="System" />
76+
<Reference Include="System.Drawing" />
7677
<Reference Include="System.IO.FileSystem.Primitives, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
7778
<HintPath>..\packages\System.IO.FileSystem.Primitives.4.3.0\lib\net46\System.IO.FileSystem.Primitives.dll</HintPath>
7879
<Private>True</Private>
@@ -88,6 +89,7 @@
8889
</ItemGroup>
8990
<ItemGroup>
9091
<Compile Include="GeneratedCode.cs" />
92+
<Compile Include="ImageGetter.cs" />
9193
<Compile Include="md2docx.cs" />
9294
<Compile Include="StyleFactory.cs" />
9395
</ItemGroup>

md2docxTests/ImageGetterTests.cs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
using Xunit;
2+
using md2docx;
3+
using System.IO;
4+
using Xunit.Abstractions;
5+
6+
namespace md2docxTests
7+
{
8+
public class ImageGetterTests
9+
{
10+
private readonly ITestOutputHelper output;
11+
12+
public ImageGetterTests(ITestOutputHelper output)
13+
{
14+
this.output = output;
15+
}
16+
17+
[Theory]
18+
[InlineData("Fail.jpg")]
19+
public void DiskFileNotFound(string name)
20+
{
21+
output.WriteLine(System.IO.Directory.GetCurrentDirectory());
22+
DirectoryInfo sourceDir = new DirectoryInfo("../../../TestFiles/");
23+
string expectedPath = Path.Combine(sourceDir.FullName, name);
24+
output.WriteLine(expectedPath);
25+
byte[] expected = File.ReadAllBytes(expectedPath);
26+
27+
string pathNotExist = "/this/path/should/not/be/found/unless/!@#$%^&*()";
28+
ImageGetter imageGetter = new ImageGetter();
29+
bool result = imageGetter.Load(pathNotExist);
30+
output.WriteLine(pathNotExist);
31+
byte[] actual = imageGetter.ImageData;
32+
33+
Assert.False(result);
34+
Assert.Equal(expected, actual);
35+
}
36+
37+
[Theory]
38+
[InlineData("Fail.jpg")]
39+
public void NetFileNotFound(string name)
40+
{
41+
42+
DirectoryInfo sourceDir = new DirectoryInfo("../../../TestFiles/");
43+
string expectedPath = Path.Combine(sourceDir.FullName, name);
44+
byte[] expected = File.ReadAllBytes(expectedPath);
45+
46+
string pathNotExist = "http://Idontcarewhatthiswebsiteis/but/it/should/not/exist!.jpg";
47+
ImageGetter imageGetter = new ImageGetter();
48+
bool result = imageGetter.Load(pathNotExist);
49+
byte[] actual = imageGetter.ImageData;
50+
51+
Assert.False(result);
52+
Assert.Equal(expected, actual);
53+
}
54+
55+
[Theory]
56+
[InlineData("yaml.jpg", "yaml.jpg")]
57+
public void FileInDisk(string name, string data)
58+
{
59+
DirectoryInfo sourceDir = new DirectoryInfo("../../../TestFiles/");
60+
string expectedPath = Path.Combine(sourceDir.FullName, name);
61+
byte[] expected = File.ReadAllBytes(expectedPath);
62+
63+
string actualPath = Path.Combine(sourceDir.FullName, data);
64+
ImageGetter imageGetter = new ImageGetter();
65+
bool result = imageGetter.Load(actualPath);
66+
byte[] actual = imageGetter.ImageData;
67+
68+
Assert.True(result);
69+
Assert.Equal(expected, actual);
70+
}
71+
72+
[Theory]
73+
[InlineData("https://raw.githubusercontent.com/CSUwangj/md2docx-csharp/master/docs/res/yaml.jpg", "yaml.jpg")]
74+
public void FileInNetwork(string url, string data)
75+
{
76+
DirectoryInfo sourceDir = new DirectoryInfo("../../../TestFiles/");
77+
string expectedPath = Path.Combine(sourceDir.FullName, data);
78+
byte[] expected = File.ReadAllBytes(expectedPath);
79+
80+
ImageGetter imageGetter = new ImageGetter();
81+
bool result = imageGetter.Load(url);
82+
byte[] actual = imageGetter.ImageData;
83+
84+
Assert.True(result);
85+
Assert.Equal(expected, actual);
86+
}
87+
}
88+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
[assembly: AssemblyTitle("md2docxTests")]
6+
[assembly: AssemblyDescription("")]
7+
[assembly: AssemblyConfiguration("")]
8+
[assembly: AssemblyCompany("")]
9+
[assembly: AssemblyProduct("md2docxTests")]
10+
[assembly: AssemblyCopyright("Copyright © 2019")]
11+
[assembly: AssemblyTrademark("")]
12+
[assembly: AssemblyCulture("")]
13+
14+
[assembly: ComVisible(false)]
15+
16+
[assembly: Guid("7f4634a7-b081-47a1-85b1-241fee59ad72")]
17+
18+
// [assembly: AssemblyVersion("1.0.*")]
19+
[assembly: AssemblyVersion("1.0.0.0")]
20+
[assembly: AssemblyFileVersion("1.0.0.0")]

md2docxTests/md2docxTests.csproj

Lines changed: 106 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,112 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
2-
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="..\packages\xunit.runner.visualstudio.2.4.1\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\packages\xunit.runner.visualstudio.2.4.1\build\net20\xunit.runner.visualstudio.props')" />
4+
<Import Project="..\packages\xunit.core.2.4.1\build\xunit.core.props" Condition="Exists('..\packages\xunit.core.2.4.1\build\xunit.core.props')" />
5+
<Import Project="..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props')" />
6+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
37
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.1</TargetFramework>
5-
6-
<IsPackable>false</IsPackable>
8+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
9+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
10+
<ProjectGuid>{7F4634A7-B081-47A1-85B1-241FEE59AD72}</ProjectGuid>
11+
<OutputType>Library</OutputType>
12+
<AppDesignerFolder>Properties</AppDesignerFolder>
13+
<RootNamespace>md2docxTests</RootNamespace>
14+
<AssemblyName>md2docxTests</AssemblyName>
15+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
16+
<FileAlignment>512</FileAlignment>
17+
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
18+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
19+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
20+
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
21+
<IsCodedUITest>False</IsCodedUITest>
22+
<TestProjectType>UnitTest</TestProjectType>
23+
<NuGetPackageImportStamp>
24+
</NuGetPackageImportStamp>
725
</PropertyGroup>
8-
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
27+
<DebugSymbols>true</DebugSymbols>
28+
<DebugType>full</DebugType>
29+
<Optimize>false</Optimize>
30+
<OutputPath>bin\Debug\</OutputPath>
31+
<DefineConstants>DEBUG;TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
</PropertyGroup>
35+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
36+
<DebugType>pdbonly</DebugType>
37+
<Optimize>true</Optimize>
38+
<OutputPath>bin\Release\</OutputPath>
39+
<DefineConstants>TRACE</DefineConstants>
40+
<ErrorReport>prompt</ErrorReport>
41+
<WarningLevel>4</WarningLevel>
42+
</PropertyGroup>
43+
<ItemGroup>
44+
<Reference Include="DocumentFormat.OpenXml, Version=2.9.1.0, Culture=neutral, PublicKeyToken=8fb06cb64d019a17, processorArchitecture=MSIL">
45+
<HintPath>..\packages\DocumentFormat.OpenXml.2.9.1\lib\net46\DocumentFormat.OpenXml.dll</HintPath>
46+
</Reference>
47+
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
48+
<HintPath>..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
49+
</Reference>
50+
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
51+
<HintPath>..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
52+
</Reference>
53+
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
54+
<HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
55+
</Reference>
56+
<Reference Include="System" />
57+
<Reference Include="System.Core" />
58+
<Reference Include="System.IO.FileSystem.Primitives, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
59+
<HintPath>..\packages\System.IO.FileSystem.Primitives.4.3.0\lib\net46\System.IO.FileSystem.Primitives.dll</HintPath>
60+
</Reference>
61+
<Reference Include="System.IO.Packaging, Version=4.0.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
62+
<HintPath>..\packages\System.IO.Packaging.4.5.0\lib\net46\System.IO.Packaging.dll</HintPath>
63+
</Reference>
64+
<Reference Include="System.Runtime.Serialization" />
65+
<Reference Include="System.Xml" />
66+
<Reference Include="System.Xml.Linq" />
67+
<Reference Include="WindowsBase" />
68+
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
69+
<HintPath>..\packages\xunit.abstractions.2.0.3\lib\net35\xunit.abstractions.dll</HintPath>
70+
</Reference>
71+
<Reference Include="xunit.assert, Version=2.4.1.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
72+
<HintPath>..\packages\xunit.assert.2.4.1\lib\netstandard1.1\xunit.assert.dll</HintPath>
73+
</Reference>
74+
<Reference Include="xunit.core, Version=2.4.1.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
75+
<HintPath>..\packages\xunit.extensibility.core.2.4.1\lib\net452\xunit.core.dll</HintPath>
76+
</Reference>
77+
<Reference Include="xunit.execution.desktop, Version=2.4.1.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
78+
<HintPath>..\packages\xunit.extensibility.execution.2.4.1\lib\net452\xunit.execution.desktop.dll</HintPath>
79+
</Reference>
80+
</ItemGroup>
81+
<ItemGroup>
82+
<Compile Include="ImageGetterTests.cs" />
83+
<Compile Include="Properties\AssemblyInfo.cs" />
84+
<Compile Include="StyleFactoryTests.cs" />
85+
</ItemGroup>
86+
<ItemGroup>
87+
<None Include="packages.config" />
88+
</ItemGroup>
989
<ItemGroup>
10-
<PackageReference Include="DocumentFormat.OpenXml" Version="2.9.1" />
11-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
12-
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
13-
<PackageReference Include="xunit" Version="2.4.0" />
14-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
90+
<Analyzer Include="..\packages\xunit.analyzers.0.10.0\analyzers\dotnet\cs\xunit.analyzers.dll" />
1591
</ItemGroup>
16-
1792
<ItemGroup>
18-
<ProjectReference Include="..\md2docx\md2docx.csproj" />
93+
<ProjectReference Include="..\md2docx\md2docx.csproj">
94+
<Project>{57f2d503-1bd2-452e-8b5b-d513e92f204e}</Project>
95+
<Name>md2docx</Name>
96+
</ProjectReference>
1997
</ItemGroup>
20-
21-
</Project>
98+
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
99+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
100+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
101+
<PropertyGroup>
102+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
103+
</PropertyGroup>
104+
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props'))" />
105+
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets'))" />
106+
<Error Condition="!Exists('..\packages\xunit.core.2.4.1\build\xunit.core.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.4.1\build\xunit.core.props'))" />
107+
<Error Condition="!Exists('..\packages\xunit.core.2.4.1\build\xunit.core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.4.1\build\xunit.core.targets'))" />
108+
<Error Condition="!Exists('..\packages\xunit.runner.visualstudio.2.4.1\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.runner.visualstudio.2.4.1\build\net20\xunit.runner.visualstudio.props'))" />
109+
</Target>
110+
<Import Project="..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets')" />
111+
<Import Project="..\packages\xunit.core.2.4.1\build\xunit.core.targets" Condition="Exists('..\packages\xunit.core.2.4.1\build\xunit.core.targets')" />
112+
</Project>

md2docxTests/packages.config

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="DocumentFormat.OpenXml" version="2.9.1" targetFramework="net461" />
4+
<package id="MSTest.TestAdapter" version="1.3.2" targetFramework="net461" />
5+
<package id="MSTest.TestFramework" version="1.3.2" targetFramework="net461" />
6+
<package id="Newtonsoft.Json" version="12.0.2" targetFramework="net461" />
7+
<package id="System.IO.FileSystem.Primitives" version="4.3.0" targetFramework="net461" />
8+
<package id="System.IO.Packaging" version="4.5.0" targetFramework="net461" />
9+
<package id="xunit" version="2.4.1" targetFramework="net461" />
10+
<package id="xunit.abstractions" version="2.0.3" targetFramework="net461" />
11+
<package id="xunit.analyzers" version="0.10.0" targetFramework="net461" />
12+
<package id="xunit.assert" version="2.4.1" targetFramework="net461" />
13+
<package id="xunit.core" version="2.4.1" targetFramework="net461" />
14+
<package id="xunit.extensibility.core" version="2.4.1" targetFramework="net461" />
15+
<package id="xunit.extensibility.execution" version="2.4.1" targetFramework="net461" />
16+
<package id="xunit.runner.visualstudio" version="2.4.1" targetFramework="net461" developmentDependency="true" />
17+
</packages>

0 commit comments

Comments
 (0)