Skip to content

Commit

Permalink
Merge branch 'dev' into memory-span
Browse files Browse the repository at this point in the history
  • Loading branch information
onizet authored Dec 16, 2024
2 parents 52a3610 + 5c6bfe2 commit 2b14315
Show file tree
Hide file tree
Showing 33 changed files with 736 additions and 311 deletions.
1 change: 0 additions & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ on:
- 'docs/**'
- '**/*.md'
pull_request:
branches: [ "dev" ]

jobs:
net8:
Expand Down
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@

- Rewriting of parsing to use System.Span instead of Regex
- Set Timeout on remaining Regex to prevent any DoS attack
=======
## 3.2.2

- Supports a feature to disable heading numbering #175
- Support center image with margin auto #171
- Support deprecrated align attribute for block #171
- Fix parsing of style attribute with a key with no value
- Improve parsing of style attribute to avoid an extra call to HtmlDecode
- Extend support of nested list for non-W3C compliant html #173
- Change way to apply table 100% width
- Allow to apply percentage widths cells

## 3.2.1

- Fix indentation of numbering list #166
- Bordered container must render its content with one bordered frame #168
- Fix serialisation of the "Harvard" style for lower-roman list
- Fix ParseHeader/Footer where input with multiple paragraphs output only the latest
- Ensure to apply default style for paragraphs, to avoid a paragraph between 2 list is mis-guessed

## 3.2.0

Expand Down
2 changes: 1 addition & 1 deletion HtmlToOpenXml.sln
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ Global
SolutionGuid = {14EE1026-6507-4295-9FEE-67A55C3849CE}
SolutionGuid = {194D4CBE-A20A-4E32-967B-E1BBD3922C29}
EndGlobalSection
EndGlobal
EndGlobal
15 changes: 7 additions & 8 deletions examples/Demo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static class Program
static async Task Main(string[] args)
{
const string filename = "test.docx";
string html = ResourceHelper.GetString("Resources.AdvancedTable.html");
string html = ResourceHelper.GetString("Resources.CompleteRunTest.html");
if (File.Exists(filename)) File.Delete(filename);

using (MemoryStream generatedDocument = new MemoryStream())
Expand All @@ -28,8 +28,8 @@ static async Task Main(string[] args)
}

generatedDocument.Position = 0L;
using (WordprocessingDocument package = WordprocessingDocument.Open(generatedDocument, true))
//using (WordprocessingDocument package = WordprocessingDocument.Create(generatedDocument, WordprocessingDocumentType.Document))
//using (WordprocessingDocument package = WordprocessingDocument.Open(generatedDocument, true))
using (WordprocessingDocument package = WordprocessingDocument.Create(generatedDocument, WordprocessingDocumentType.Document))
{
MainDocumentPart mainPart = package.MainDocumentPart;
if (mainPart == null)
Expand All @@ -38,12 +38,11 @@ static async Task Main(string[] args)
new Document(new Body()).Save(mainPart);
}

HtmlConverter converter = new HtmlConverter(mainPart);
HtmlConverter converter = new(mainPart, new HtmlToOpenXml.IO.DefaultWebRequest(){
BaseImageUrl = new Uri(Path.Combine(Environment.CurrentDirectory, "images"))
});
converter.RenderPreAsTable = true;
Body body = mainPart.Document.Body;

await converter.ParseBody(html);
mainPart.Document.Save();

AssertThatOpenXmlDocumentIsValid(package);
}
Expand Down Expand Up @@ -75,4 +74,4 @@ static void AssertThatOpenXmlDocumentIsValid(WordprocessingDocument wpDoc)
Console.ReadLine();
}
}
}
}
132 changes: 85 additions & 47 deletions examples/Demo/Resources/CompleteRunTest.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@
<title></title>
</head>
<body>

<table style="width: 100%; border-collapse: collapse; margin: 20px auto; border: 1px solid #ccc;">
<tr style="background-color: #f4f4f4; text-align: left;">
<th style="width: 10%; border: 1px solid #ccc; padding: 8px;">Column 1</th>
<th style="width: 60%; border: 1px solid #ccc; padding: 8px;">Column 2</th>
<th style="width: 30%; border: 1px solid #ccc; padding: 8px;">Column 3</th>
</tr>
<tr>
<td style="width: 10%; border: 1px solid #ccc; padding: 8px;">Row 1, Cell 1</td>
<td style="width: 60%; border: 1px solid #ccc; padding: 8px;">Row 1, Cell 2</td>
<td style="width: 30%; border: 1px solid #ccc; padding: 8px;">Row 1, Cell 3</td>
</tr>
<tr>
<td style="width: 10%; border: 1px solid #ccc; padding: 8px;">Row 2, Cell 1</td>
<td style="width: 60%; border: 1px solid #ccc; padding: 8px;">Row 2, Cell 2</td>
<td style="width: 30%; border: 1px solid #ccc; padding: 8px;">Row 2, Cell 3</td>
</tr>
</table>

<h1></h1>
<h1>Heading 1</h1>
<h2>Heading 2</h2>
Expand All @@ -15,8 +34,11 @@ <h5>Heading 5</h5>
<span style="font-variant: small-caps"> Small caps</span><br />
<strike>Strike</strike> <span style="text-decoration: line-through"> Line Through</span> <span style="text-decoration: overline"> Overline</span> <span style="text-decoration: underline"> Underline</span><br />
<b> Bold</b><br />
<span>This is a <b>bold
</b>text</span>
<span>
This is a <b>
bold
</b>text
</span>
<span style="font-weight: bold">Bold</span><br />
<span style="font-weight: bolder">Bolder</span><br />
<span style="font-weight: lighter">Lighter</span><br />
Expand Down Expand Up @@ -47,7 +69,8 @@ <h5>Heading 5</h5>
<a href="www.github.com"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot" /></a>

<!-- multiline images -->
<p><img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAoHBwgHBgoICAgLCgoLDhgQDg0NDh0VFhEYIx8l
<p>
<img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAoHBwgHBgoICAgLCgoLDhgQDg0NDh0VFhEYIx8l
JCIfIiEmKzcvJik0KSEiMEExNDk7Pj4+JS5ESUM8SDc9Pjv/wAALCABVAEABAREA/8QAHwAA
AQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQR
BRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RF
Expand Down Expand Up @@ -88,7 +111,8 @@ <h5>Heading 5</h5>
OfDEXhz/AIRbxtAkV1pYNrJHNC0qSbPlDKQDg8e3tVD4Q6BKPGmp67Y2lxbaJ5ckVo04IMgZ
1KjnqAByfXFezMiv95Q2PUZoCKOigY9BSkA9QDjmgqGBDAEHsaia0tnQxtbxMjdVKAg0W9pb
Wilba3ihB6iNAufyoltLaZw8tvFIw6FkBNSgADA4FLRRRRRRRX//2Q==
"></p>
">
</p>

<img src="https://www.w3schools.com/tags/smiley.gif" alt="Smiley face" width="42" height="42">

Expand All @@ -102,67 +126,81 @@ <h5>Heading 5</h5>
<br />


<blockquote cite="http://www.worldwildlife.org/who/index.html">
For 50 years, <b>WWF</b> has been protecting the future of nature. The world's leading conservation organization, WWF works in 100 countries and is supported by 1.2 million members in the United States and close to 5 million globally.
</blockquote>
<blockquote cite="http://www.worldwildlife.org/who/index.html">
For 50 years, <b>WWF</b> has been protecting the future of nature. The world's leading conservation organization, WWF works in 100 countries and is supported by 1.2 million members in the United States and close to 5 million globally.
</blockquote>

<br class="ibp-rteFontSize-5"/><span style="font-size: 16.9px">My Text </span>
<br class="ibp-rteFontSize-5" /><span style="font-size: 16.9px">My Text </span>

<p>An ordered list:</p>
<p>An ordered list:</p>
<ol>
<li>Coffee</li>
<li>Tea</li>
<li>Milk
<ul>
<li>Coffee</li>
<li>Tea
<ol>
<li>Earl Grey</li>
<li>Green</li>
<li>Rosboh</li>
</ol>
</li>
<li>Milk</li>
</ul>
</li>
<li>Wine</li>
<li>Coffee</li>
<li>Tea</li>
<li>
Milk
<ul>
<li>Coffee</li>
<li>
Tea
<ol>
<li>Earl Grey</li>
<li>Green</li>
<li>Rosboh</li>
</ol>
</li>
<li>Milk</li>
</ul>
</li>
<li>Wine</li>
</ol>

<table border=1><tr><td>Inside table</td></tr></table>
<hr />
<p>delta parameter (<span style='font-family:Symbol'>d</span>)</p>
Looks how cool is <font size="x-large" color="maroon"><b>Open Xml</b></font>.
<hr />
Now with <font color="red"><u>HtmlToOpenXml</u></font>, it never been so easy to convert html.
<p>
If you like it, add me a rating on <a href="https://github.com/onizet/html2openxml">github</a>
</p>

simple text
<div style="page-orientation: landscape; page-break-before: always">
Hello !
je suis du texte
<span style="font-style: oblique">écrit en oblique.</span>

<pre lang="fr-FR" class="c#"> public void SetContentType(System.Web.HttpRequest request, System.Web.HttpResponse response, String reportName)
<table border=1><tr><td>Inside table</td></tr></table>
<hr />
<p>delta parameter (<span style='font-family:Symbol'>d</span>)</p>
Looks how cool is <font size="x-large" color="maroon"><b>Open Xml</b></font>.
<hr />
Now with <font color="red"><u>HtmlToOpenXml</u></font>, it never been so easy to convert html.
<p>
If you like it, add me a rating on <a href="https://github.com/onizet/html2openxml">github</a>
</p>

simple text
<div style="page-orientation: landscape; page-break-before: always">
Hello !
je suis du texte
<span style="font-style: oblique">écrit en oblique.</span>

<pre lang="fr-FR" class="c#"> public void SetContentType(System.Web.HttpRequest request, System.Web.HttpResponse response, String reportName)
{
if (request.Browser.Browser.Contains(&quot;IE&quot;))
{
<span style="color:Green">// Replace the %20 to obtain a clean name when saving the file from Word.</span>
<span style="color:Green">// Replace the %20 to obtain a clean name when saving the file from Word.</span>
encodedFilename =
Uri.EscapeDataString(Path.GetFileNameWithoutExtension(encodedFilename)).Replace(&quot;%20&quot;, &quot; &quot;)
+ Path.GetExtension(encodedFilename);
}
}
</pre>
<hr/>
<pre>
<hr />
<pre>
Some &lt;Pre&gt; starting one
line below! </pre>

</div>

<!--<div style="page-break-before: always">

<div style='margin-top: 20px; border: 1px dashed rgba(0, 0, 0, 0.4); background: olive; color: white; display: flex; gap: 5px; padding: 6px 8px; font-size: 14px;'>
<div>
<p>Header placeholder:</p>
<ol>
<li>Item 1</li>
<li>Item 2</li>
</ol>
<p style='text-indent: 4.5em'>Footer Placeholder</p>
</div>
</div>

<div style="border: 1px dashed salmon; margin: 1em">Lorem Ipsum</div>
<!--<div style="page-break-before: always">
New page
</div>-->
</body>
Expand Down
97 changes: 0 additions & 97 deletions examples/Demo/Resources/Demo.html

This file was deleted.

Loading

0 comments on commit 2b14315

Please sign in to comment.