diff --git a/GlobalAssemblyInfo.cs b/GlobalAssemblyInfo.cs new file mode 100644 index 0000000..16f5c63 --- /dev/null +++ b/GlobalAssemblyInfo.cs @@ -0,0 +1,28 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("MigraDoc.Extensions")] +[assembly: AssemblyCopyright("Copyright © 2013")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.1.0")] +[assembly: AssemblyFileVersion("1.0.1.0")] + +//will set the "ProductVersion" value displayed by Windows Explorer +[assembly: AssemblyInformationalVersion("1.0.1.0")] \ No newline at end of file diff --git a/MigraDoc.Extensions.sln b/MigraDoc.Extensions.sln index 5c99bcc..5dc1cc0 100644 --- a/MigraDoc.Extensions.sln +++ b/MigraDoc.Extensions.sln @@ -22,6 +22,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MigraDoc.Extensions.Markdow EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MigraDoc.Extensions", "src\MigraDoc.Extensions\MigraDoc.Extensions.csproj", "{1863068F-975C-4F5B-ABA7-FBA344709A48}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solutions Items", "Solutions Items", "{199219F5-41E8-45D6-A267-E38242F50253}" + ProjectSection(SolutionItems) = preProject + GlobalAssemblyInfo.cs = GlobalAssemblyInfo.cs + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/README.md b/README.md index 6df0aa5..24196e1 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,12 @@ Extensions for [MigraDoc/PDFSharp](http://www.pdfsharp.net/Overview.ashx). +## Remark +The tests are not updated to include the new support for html nested lists! +Use on your own risk! + +The included example project is updated to have different example of nested lists. + ## Quick Start The biggest feature provided by this library is the ability to convert from HTML and Markdown to PDF, via MigraDoc's Document Object Model. diff --git a/src/MigraDoc.Extensions.Html/HtmlConverter.cs b/src/MigraDoc.Extensions.Html/HtmlConverter.cs index 94a6a86..aec6d40 100644 --- a/src/MigraDoc.Extensions.Html/HtmlConverter.cs +++ b/src/MigraDoc.Extensions.Html/HtmlConverter.cs @@ -9,15 +9,18 @@ namespace MigraDoc.Extensions.Html { public class HtmlConverter : IConverter { - private IDictionary> nodeHandlers - = new Dictionary>(); + private IDictionary> nodeHandlers + = new Dictionary>(); - public HtmlConverter() + private readonly double _nestedListStartingLeftIndent = 1.0; + + public HtmlConverter(double nestedListStartingLeftIndent) { + _nestedListStartingLeftIndent = nestedListStartingLeftIndent; AddDefaultNodeHandlers(); } - public IDictionary> NodeHandlers + public IDictionary> NodeHandlers { get { @@ -51,11 +54,11 @@ private void ConvertHtmlNodes(HtmlNodeCollection nodes, DocumentObject section, { foreach (var node in nodes) { - Func nodeHandler; + Func nodeHandler; if (nodeHandlers.TryGetValue(node.Name, out nodeHandler)) { // pass the current container or section - var result = nodeHandler(node, current ?? section); + var result = nodeHandler(node, current ?? section, section); if (node.HasChildNodes) { @@ -84,23 +87,24 @@ private void AddDefaultNodeHandlers() nodeHandlers.Add("h5", AddHeading); nodeHandlers.Add("h6", AddHeading); - nodeHandlers.Add("p", (node, parent) => + nodeHandlers.Add("p", (node, parent, parentSection) => { return ((Section)parent).AddParagraph(); }); // Inline Elements - nodeHandlers.Add("strong", (node, parent) => AddFormattedText(node, parent, TextFormat.Bold)); - nodeHandlers.Add("i", (node, parent) => AddFormattedText(node, parent, TextFormat.Italic)); - nodeHandlers.Add("em", (node, parent) => AddFormattedText(node, parent, TextFormat.Italic)); - nodeHandlers.Add("u", (node, parent) => AddFormattedText(node, parent, TextFormat.Underline)); - nodeHandlers.Add("a", (node, parent) => + nodeHandlers.Add("strong", (node, parent, parentSection) => AddFormattedText(node, parent, TextFormat.Bold)); + nodeHandlers.Add("i", (node, parent, parentSection) => AddFormattedText(node, parent, TextFormat.Italic)); + nodeHandlers.Add("em", (node, parent, parentSection) => AddFormattedText(node, parent, TextFormat.Italic)); + nodeHandlers.Add("u", (node, parent, parentSection) => AddFormattedText(node, parent, TextFormat.Underline)); + nodeHandlers.Add("a", (node, parent, parentSection) => { return GetParagraph(parent).AddHyperlink(node.GetAttributeValue("href", ""), HyperlinkType.Web); }); - nodeHandlers.Add("hr", (node, parent) => GetParagraph(parent).SetStyle("HorizontalRule")); - nodeHandlers.Add("br", (node, parent) => { + nodeHandlers.Add("hr", (node, parent, parentSection) => GetParagraph(parent).SetStyle("HorizontalRule")); + nodeHandlers.Add("br", (node, parent, parentSection) => + { if (parent is FormattedText) { // inline elements can contain line breaks @@ -113,13 +117,28 @@ private void AddDefaultNodeHandlers() return paragraph; }); - nodeHandlers.Add("li", (node, parent) => + nodeHandlers.Add("li", (node, parent, parentSection) => { var listStyle = node.ParentNode.Name == "ul" - ? "UnorderedList" - : "OrderedList"; + ? "UnorderedList{0}" + : "OrderedList{0}"; + + var section = parent as Section; + int nestedLevelSameType = 1; + int nestedLevel = 1; + // if section == null then nested lists + if (section == null) + { + section = (Section) parentSection; + + // get the nested level for the parent type + nestedLevelSameType = (node.Ancestors().Count(a => a.Name.Equals(node.ParentNode.Name))) + 1; + // get the nested level for all the types (ol or ul) + nestedLevel = (node.Ancestors().Count(a => a.Name.Equals("ol") || a.Name.Equals("ul"))) + 1; + // limit the levels to 3 because no more possible in MigraDoc + if (nestedLevelSameType > 3) nestedLevelSameType = 3; + } - var section = (Section)parent; var isFirst = node.ParentNode.Elements("li").First() == node; var isLast = node.ParentNode.Elements("li").Last() == node; @@ -129,7 +148,13 @@ private void AddDefaultNodeHandlers() section.AddParagraph().SetStyle("ListStart"); } - var listItem = section.AddParagraph().SetStyle(listStyle); + Paragraph listItem = section.AddParagraph().SetStyle(string.Format(listStyle, nestedLevelSameType)); + // adapt indent if nested lists + if (nestedLevel > 0) + { + double leftIndent = _nestedListStartingLeftIndent + System.Convert.ToDouble(nestedLevel) / 2; + listItem.Format.LeftIndent = new Unit(leftIndent, UnitType.Centimeter); + } // disable continuation if this is the first list item listItem.Format.ListInfo.ContinuePreviousList = !isFirst; @@ -139,11 +164,40 @@ private void AddDefaultNodeHandlers() { section.AddParagraph().SetStyle("ListEnd"); } - return listItem; }); - nodeHandlers.Add("#text", (node, parent) => + //nodeHandlers.Add("li", (node, parent) => + //{ + // var listStyle = node.ParentNode.Name == "ul" + // ? "UnorderedList" + // : "OrderedList"; + + // var section = (Section)parent; + // var isFirst = node.ParentNode.Elements("li").First() == node; + // var isLast = node.ParentNode.Elements("li").Last() == node; + + // // if this is the first item add the ListStart paragraph + // if (isFirst) + // { + // section.AddParagraph().SetStyle("ListStart"); + // } + + // var listItem = section.AddParagraph().SetStyle(listStyle); + + // // disable continuation if this is the first list item + // listItem.Format.ListInfo.ContinuePreviousList = !isFirst; + + // // if the this is the last item add the ListEnd paragraph + // if (isLast) + // { + // section.AddParagraph().SetStyle("ListEnd"); + // } + + // return listItem; + //}); + + nodeHandlers.Add("#text", (node, parent, parentSection) => { // remove line breaks var innerText = node.InnerText.Replace("\r", "").Replace("\n", ""); @@ -184,7 +238,7 @@ private static DocumentObject AddFormattedText(HtmlNode node, DocumentObject par return GetParagraph(parent).AddFormattedText(format); } - private static DocumentObject AddHeading(HtmlNode node, DocumentObject parent) + private static DocumentObject AddHeading(HtmlNode node, DocumentObject parent, DocumentObject parentSection = null) { return ((Section)parent).AddParagraph().SetStyle("Heading" + node.Name[1]); } diff --git a/src/MigraDoc.Extensions.Html/MigraDoc.Extensions.Html.csproj b/src/MigraDoc.Extensions.Html/MigraDoc.Extensions.Html.csproj index 7ccb4ab..c6357ad 100644 --- a/src/MigraDoc.Extensions.Html/MigraDoc.Extensions.Html.csproj +++ b/src/MigraDoc.Extensions.Html/MigraDoc.Extensions.Html.csproj @@ -36,20 +36,25 @@ ..\..\packages\HtmlAgilityPack.1.4.6\lib\Net40\HtmlAgilityPack.dll - - ..\..\packages\PDFsharp-MigraDoc-GDI.1.32.3879.0\lib\net20\MigraDoc.DocumentObjectModel.dll + + False + ..\..\packages\PDFsharp-MigraDoc-GDI.1.32.4334.0\lib\net20\MigraDoc.DocumentObjectModel.dll - - ..\..\packages\PDFsharp-MigraDoc-GDI.1.32.3879.0\lib\net20\MigraDoc.Rendering.dll + + False + ..\..\packages\PDFsharp-MigraDoc-GDI.1.32.4334.0\lib\net20\MigraDoc.Rendering.dll - - ..\..\packages\PDFsharp-MigraDoc-GDI.1.32.3879.0\lib\net20\MigraDoc.RtfRendering.dll + + False + ..\..\packages\PDFsharp-MigraDoc-GDI.1.32.4334.0\lib\net20\MigraDoc.RtfRendering.dll - - ..\..\packages\PDFsharp-MigraDoc-GDI.1.32.3879.0\lib\net20\PdfSharp.dll + + False + ..\..\packages\PDFsharp-MigraDoc-GDI.1.32.4334.0\lib\net20\PdfSharp.dll - - ..\..\packages\PDFsharp-MigraDoc-GDI.1.32.3879.0\lib\net20\PdfSharp.Charting.dll + + False + ..\..\packages\PDFsharp-MigraDoc-GDI.1.32.4334.0\lib\net20\PdfSharp.Charting.dll @@ -61,6 +66,9 @@ + + GlobalAssemblyInfo.cs + diff --git a/src/MigraDoc.Extensions.Html/Properties/AssemblyInfo.cs b/src/MigraDoc.Extensions.Html/Properties/AssemblyInfo.cs index ab2cd1a..837a319 100644 --- a/src/MigraDoc.Extensions.Html/Properties/AssemblyInfo.cs +++ b/src/MigraDoc.Extensions.Html/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following @@ -8,11 +7,6 @@ [assembly: AssemblyTitle("MigraDoc.Extensions.Html")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("MigraDoc.Extensions.Html")] -[assembly: AssemblyCopyright("Copyright © 2013")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from @@ -21,16 +15,3 @@ // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("666a8f9c-11cc-41b6-a709-57a5beb2df69")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/MigraDoc.Extensions.Html/SectionExtensions.cs b/src/MigraDoc.Extensions.Html/SectionExtensions.cs index 5f24a16..b39cd31 100644 --- a/src/MigraDoc.Extensions.Html/SectionExtensions.cs +++ b/src/MigraDoc.Extensions.Html/SectionExtensions.cs @@ -1,14 +1,12 @@ using MigraDoc.DocumentObjectModel; -using MigraDoc.Extensions.Html; -using System; namespace MigraDoc.Extensions.Html { public static class SectionExtensions { - public static Section AddHtml(this Section section, string html) + public static Section AddHtml(this Section section, string html, double nestedListStartingLeftIndent = 1.0) { - return section.Add(html, new HtmlConverter()); + return section.Add(html, new HtmlConverter(nestedListStartingLeftIndent)); } } } diff --git a/src/MigraDoc.Extensions.Html/packages.config b/src/MigraDoc.Extensions.Html/packages.config index 203b032..92ce45f 100644 --- a/src/MigraDoc.Extensions.Html/packages.config +++ b/src/MigraDoc.Extensions.Html/packages.config @@ -1,5 +1,5 @@  - + \ No newline at end of file diff --git a/src/MigraDoc.Extensions.Markdown/MarkdownConverter.cs b/src/MigraDoc.Extensions.Markdown/MarkdownConverter.cs index 78eaf31..f347615 100644 --- a/src/MigraDoc.Extensions.Markdown/MarkdownConverter.cs +++ b/src/MigraDoc.Extensions.Markdown/MarkdownConverter.cs @@ -7,32 +7,35 @@ namespace MigraDoc.Extensions.Markdown { public class MarkdownConverter : IConverter { - private readonly MarkdownOptions options; + private readonly MarkdownOptions _options; + private readonly double _nestedListStartingLeftIndent = 1.0; - public MarkdownConverter() + public MarkdownConverter(double nestedListStartingLeftIndent) { - options = new MarkdownOptions + _options = new MarkdownOptions { LinkEmails = true }; + _nestedListStartingLeftIndent = nestedListStartingLeftIndent; } - public MarkdownConverter(MarkdownOptions options) + public MarkdownConverter(MarkdownOptions options, double nestedListStartingLeftIndent) { if (options == null) { throw new ArgumentNullException("options"); } - this.options = options; + this._options = options; + _nestedListStartingLeftIndent = nestedListStartingLeftIndent; } public Action
Convert(string contents) { - var converter = new MarkdownSharp.Markdown(options); + var converter = new MarkdownSharp.Markdown(_options); var html = converter.Transform(contents); - var htmlConverter = new HtmlConverter(); + var htmlConverter = new HtmlConverter(_nestedListStartingLeftIndent); return htmlConverter.Convert(html); } } diff --git a/src/MigraDoc.Extensions.Markdown/MigraDoc.Extensions.Markdown.csproj b/src/MigraDoc.Extensions.Markdown/MigraDoc.Extensions.Markdown.csproj index ebd37a4..edd827c 100644 --- a/src/MigraDoc.Extensions.Markdown/MigraDoc.Extensions.Markdown.csproj +++ b/src/MigraDoc.Extensions.Markdown/MigraDoc.Extensions.Markdown.csproj @@ -36,21 +36,25 @@ ..\..\packages\MarkdownSharp.1.13.0.0\lib\35\MarkdownSharp.dll - + False - ..\..\packages\PDFsharp-MigraDoc-GDI.1.32.3879.0\lib\net20\MigraDoc.DocumentObjectModel.dll + ..\..\packages\PDFsharp-MigraDoc-GDI.1.32.4334.0\lib\net20\MigraDoc.DocumentObjectModel.dll - - ..\..\packages\PDFsharp-MigraDoc-GDI.1.32.3879.0\lib\net20\MigraDoc.Rendering.dll + + False + ..\..\packages\PDFsharp-MigraDoc-GDI.1.32.4334.0\lib\net20\MigraDoc.Rendering.dll - - ..\..\packages\PDFsharp-MigraDoc-GDI.1.32.3879.0\lib\net20\MigraDoc.RtfRendering.dll + + False + ..\..\packages\PDFsharp-MigraDoc-GDI.1.32.4334.0\lib\net20\MigraDoc.RtfRendering.dll - - ..\..\packages\PDFsharp-MigraDoc-GDI.1.32.3879.0\lib\net20\PdfSharp.dll + + False + ..\..\packages\PDFsharp-MigraDoc-GDI.1.32.4334.0\lib\net20\PdfSharp.dll - - ..\..\packages\PDFsharp-MigraDoc-GDI.1.32.3879.0\lib\net20\PdfSharp.Charting.dll + + False + ..\..\packages\PDFsharp-MigraDoc-GDI.1.32.4334.0\lib\net20\PdfSharp.Charting.dll @@ -62,6 +66,9 @@ + + GlobalAssemblyInfo.cs + diff --git a/src/MigraDoc.Extensions.Markdown/Properties/AssemblyInfo.cs b/src/MigraDoc.Extensions.Markdown/Properties/AssemblyInfo.cs index d1fde05..f4053f4 100644 --- a/src/MigraDoc.Extensions.Markdown/Properties/AssemblyInfo.cs +++ b/src/MigraDoc.Extensions.Markdown/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following @@ -8,11 +7,6 @@ [assembly: AssemblyTitle("MigraDoc.Extensions.Markdown")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("MigraDoc.Extensions.Markdown")] -[assembly: AssemblyCopyright("Copyright © 2013")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from @@ -21,16 +15,3 @@ // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("4cfa7343-7e37-4b98-a989-1d74db70107d")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/MigraDoc.Extensions.Markdown/SectionExtensions.cs b/src/MigraDoc.Extensions.Markdown/SectionExtensions.cs index 056acb6..0ec89d6 100644 --- a/src/MigraDoc.Extensions.Markdown/SectionExtensions.cs +++ b/src/MigraDoc.Extensions.Markdown/SectionExtensions.cs @@ -1,14 +1,12 @@ using MigraDoc.DocumentObjectModel; -using MigraDoc.Extensions.Html; -using System; namespace MigraDoc.Extensions.Markdown { public static class SectionExtensions { - public static Section AddMarkdown(this Section section, string markdown) + public static Section AddMarkdown(this Section section, string markdown, double nestedListStartingLeftIndent = 1.0) { - return section.Add(markdown, new MarkdownConverter()); + return section.Add(markdown, new MarkdownConverter(nestedListStartingLeftIndent)); } } } diff --git a/src/MigraDoc.Extensions.Markdown/packages.config b/src/MigraDoc.Extensions.Markdown/packages.config index afb0ea3..cd51603 100644 --- a/src/MigraDoc.Extensions.Markdown/packages.config +++ b/src/MigraDoc.Extensions.Markdown/packages.config @@ -1,5 +1,5 @@  - + \ No newline at end of file diff --git a/src/MigraDoc.Extensions/MigraDoc.Extensions.csproj b/src/MigraDoc.Extensions/MigraDoc.Extensions.csproj index d3f25bd..4205cf2 100644 --- a/src/MigraDoc.Extensions/MigraDoc.Extensions.csproj +++ b/src/MigraDoc.Extensions/MigraDoc.Extensions.csproj @@ -33,20 +33,25 @@ 4 - - ..\..\packages\PDFsharp-MigraDoc-GDI.1.32.3879.0\lib\net20\MigraDoc.DocumentObjectModel.dll + + False + ..\..\packages\PDFsharp-MigraDoc-GDI.1.32.4334.0\lib\net20\MigraDoc.DocumentObjectModel.dll - - ..\..\packages\PDFsharp-MigraDoc-GDI.1.32.3879.0\lib\net20\MigraDoc.Rendering.dll + + False + ..\..\packages\PDFsharp-MigraDoc-GDI.1.32.4334.0\lib\net20\MigraDoc.Rendering.dll - - ..\..\packages\PDFsharp-MigraDoc-GDI.1.32.3879.0\lib\net20\MigraDoc.RtfRendering.dll + + False + ..\..\packages\PDFsharp-MigraDoc-GDI.1.32.4334.0\lib\net20\MigraDoc.RtfRendering.dll - - ..\..\packages\PDFsharp-MigraDoc-GDI.1.32.3879.0\lib\net20\PdfSharp.dll + + False + ..\..\packages\PDFsharp-MigraDoc-GDI.1.32.4334.0\lib\net20\PdfSharp.dll - - ..\..\packages\PDFsharp-MigraDoc-GDI.1.32.3879.0\lib\net20\PdfSharp.Charting.dll + + False + ..\..\packages\PDFsharp-MigraDoc-GDI.1.32.4334.0\lib\net20\PdfSharp.Charting.dll @@ -58,6 +63,9 @@ + + GlobalAssemblyInfo.cs + diff --git a/src/MigraDoc.Extensions/Properties/AssemblyInfo.cs b/src/MigraDoc.Extensions/Properties/AssemblyInfo.cs index 6c0d5ee..df59dfa 100644 --- a/src/MigraDoc.Extensions/Properties/AssemblyInfo.cs +++ b/src/MigraDoc.Extensions/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following @@ -8,11 +7,6 @@ [assembly: AssemblyTitle("MigraDoc.Extensions")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("MigraDoc.Extensions")] -[assembly: AssemblyCopyright("Copyright © 2013")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from @@ -21,16 +15,3 @@ // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("65c350e6-85a0-4da2-9182-26287195266c")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/MigraDoc.Extensions/packages.config b/src/MigraDoc.Extensions/packages.config index ccc059e..92bab68 100644 --- a/src/MigraDoc.Extensions/packages.config +++ b/src/MigraDoc.Extensions/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/src/examples/MigraDoc.Extensions.Html.Example/Example.html b/src/examples/MigraDoc.Extensions.Html.Example/Example.html index bc2e816..5253d8e 100644 --- a/src/examples/MigraDoc.Extensions.Html.Example/Example.html +++ b/src/examples/MigraDoc.Extensions.Html.Example/Example.html @@ -1,32 +1,133 @@ 

This is a heading 1

-

- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin dapibus convallis nisi quis volutpat. In in felis id felis venenatis venenatis.
- Mauris sit amet consequat mi. Proin gravida gravida tellus, eget tristique leo pharetra sed. Proin nec quam at ligula viverra sollicitudin. Donec sit amet neque ac nisi adipiscing porta. Suspendisse mollis mi id nulla condimentum lobortis. -

-

- Etiam sem arcu, imperdiet sed rhoncus in, rhoncus posuere nulla. Pellentesque sit amet urna non elit suscipit imperdiet. Ut at auctor felis. -

+

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin dapibus convallis nisi quis volutpat. In in felis id felis venenatis venenatis.
+ Mauris sit amet consequat mi. Proin gravida gravida tellus, eget tristique leo pharetra sed. Proin nec quam at ligula viverra sollicitudin. Donec sit amet neque ac nisi adipiscing porta. Suspendisse mollis mi id nulla condimentum lobortis. +

+

+ Etiam sem arcu, imperdiet sed rhoncus in, rhoncus posuere nulla. Pellentesque sit amet urna non elit suscipit imperdiet. Ut at auctor felis. +

+ +

This is a heading 2

+

+ Fusce augue turpis, convallis eget facilisis eget, scelerisque in odio. Sed in suscipit elit. Morbi ipsum tortor, aliquam sit amet mattis sit amet, ullamcorper vitae eros. Proin ut enim a eros dignissim iaculis. +

+
    +
  • Strong
  • +
  • Italic
  • +
  • Underline
  • +
  • Strong Italic
  • +
  • Strong Underline
  • +
  • All the styles
  • +
+
+

This is a heading 3

+

+ Fusce augue turpis, convallis eget facilisis eget, scelerisque in odio. Sed in suscipit elit. Morbi ipsum tortor, aliquam sit amet mattis sit amet, ullamcorper vitae eros. Proin ut enim a eros dignissim iaculis. +

+ +
    +
  • One
  • +
  • Two
  • +
  • Three
  • +
  • Four
  • +
  • Five
  • +
-

This is a heading 2

+
    +
  1. One +
      +
    1. One +
        +
      1. One
      2. +
      3. Two
      4. +
      5. Three
      6. +
      7. Four
      8. +
      9. Five
      10. +
      +
    2. +
    3. Two
    4. +
    5. Three
    6. +
    7. Four
    8. +
    9. Five
    10. +
    +
  2. +
  3. Two
  4. +
  5. Three
  6. +
  7. Four
  8. +
  9. Five
  10. +

Fusce augue turpis, convallis eget facilisis eget, scelerisque in odio. Sed in suscipit elit. Morbi ipsum tortor, aliquam sit amet mattis sit amet, ullamcorper vitae eros. Proin ut enim a eros dignissim iaculis.

    -
  • Strong
  • -
  • Italic
  • -
  • Underline
  • -
  • Strong Italic
  • -
  • Strong Underline
  • -
  • All the styles
  • +
  • One +
      +
    • One +
        +
      • One
      • +
      • Two
      • +
      • Three
      • +
      • Four
      • +
      • Five
      • +
      +
    • +
    • Two
    • +
    • Three
    • +
    • Four
    • +
    • Five
    • +
    +
  • +
  • Two
  • +
  • Three
  • +
  • Four
  • +
  • Five
-
-

This is a heading 3

Fusce augue turpis, convallis eget facilisis eget, scelerisque in odio. Sed in suscipit elit. Morbi ipsum tortor, aliquam sit amet mattis sit amet, ullamcorper vitae eros. Proin ut enim a eros dignissim iaculis. -

+

    -
  1. One
  2. +
  3. One +
      +
    1. One +
        +
      1. One +
          +
        • One +
            +
          • One +
              +
            • One
            • +
            • Two
            • +
            • Three
            • +
            • Four
            • +
            • Five
            • +
            +
          • +
          • Two
          • +
          • Three
          • +
          • Four
          • +
          • Five
          • +
          +
        • +
        • Two
        • +
        • Three
        • +
        • Four
        • +
        • Five
        • +
        +
      2. +
      3. Two
      4. +
      5. Three
      6. +
      7. Four
      8. +
      9. Five
      10. +
      +
    2. +
    3. Two
    4. +
    5. Three
    6. +
    7. Four
    8. +
    9. Five
    10. +
    +
  4. Two
  5. Three
  6. Four
  7. @@ -34,12 +135,85 @@

    This is a heading 3

Fusce augue turpis, convallis eget facilisis eget, scelerisque in odio. Sed in suscipit elit. Morbi ipsum tortor, aliquam sit amet mattis sit amet, ullamcorper vitae eros. Proin ut enim a eros dignissim iaculis. -

-
    -
  1. One
  2. +

    +
      +
    • One +
        +
      • One +
          +
        • One +
            +
          1. One +
              +
            1. One +
                +
              1. One
              2. +
              3. Two
              4. +
              5. Three
              6. +
              7. Four
              8. +
              9. Five
              10. +
              +
            2. +
            3. Two
            4. +
            5. Three
            6. +
            7. Four
            8. +
            9. Five
            10. +
            +
          2. +
          3. Two
          4. +
          5. Three
          6. +
          7. Four
          8. +
          9. Five
          10. +
          +
        • +
        • Two
        • +
        • Three
        • +
        • Four
        • +
        • Five
        • +
        +
      • +
      • Two
      • +
      • Three
      • +
      • Four
      • +
      • Five
      • +
      +
    • Two
    • Three
    • Four
    • Five
    • -
+ + +

+ Fusce augue turpis, convallis eget facilisis eget, scelerisque in odio. Sed in suscipit elit. Morbi ipsum tortor, aliquam sit amet mattis sit amet, ullamcorper vitae eros. Proin ut enim a eros dignissim iaculis. +

+
    +
  • One +
      +
    1. One +
        +
      • One +
          +
        1. One +
            +
          • One +
              +
            1. One
            2. +
            3. Two
            4. +
            +
          • +
          • Two
          • +
          +
        2. +
        3. Two
        4. +
        +
      • +
      • Two
      • +
      +
    2. +
    3. Two
    4. +
    +
  • +
  • Two
  • +
diff --git a/src/examples/MigraDoc.Extensions.Html.Example/Example.md b/src/examples/MigraDoc.Extensions.Html.Example/Example.md index b7c63a8..d4dc650 100644 --- a/src/examples/MigraDoc.Extensions.Html.Example/Example.md +++ b/src/examples/MigraDoc.Extensions.Html.Example/Example.md @@ -23,6 +23,8 @@ Sed non eros metus, in posuere dui. Nunc lobortis tellus vitae dolor sodales qui Curabitur fringilla rhoncus pellentesque. Morbi at diam metus. Sed ac ultricies orci. Sed eu felis enim. Integer molestie libero elementum ligula hendrerit eleifend. 1. One + - one a + - one b 2. Two 3. Three 4. Four diff --git a/src/examples/MigraDoc.Extensions.Html.Example/MigraDoc.Extensions.Html.Example.csproj b/src/examples/MigraDoc.Extensions.Html.Example/MigraDoc.Extensions.Html.Example.csproj index d7b7177..23021c5 100644 --- a/src/examples/MigraDoc.Extensions.Html.Example/MigraDoc.Extensions.Html.Example.csproj +++ b/src/examples/MigraDoc.Extensions.Html.Example/MigraDoc.Extensions.Html.Example.csproj @@ -34,20 +34,25 @@ 4 - - ..\..\..\packages\PDFsharp-MigraDoc-GDI.1.32.3879.0\lib\net20\MigraDoc.DocumentObjectModel.dll + + False + ..\..\..\packages\PDFsharp-MigraDoc-GDI.1.32.4334.0\lib\net20\MigraDoc.DocumentObjectModel.dll - - ..\..\..\packages\PDFsharp-MigraDoc-GDI.1.32.3879.0\lib\net20\MigraDoc.Rendering.dll + + False + ..\..\..\packages\PDFsharp-MigraDoc-GDI.1.32.4334.0\lib\net20\MigraDoc.Rendering.dll - - ..\..\..\packages\PDFsharp-MigraDoc-GDI.1.32.3879.0\lib\net20\MigraDoc.RtfRendering.dll + + False + ..\..\..\packages\PDFsharp-MigraDoc-GDI.1.32.4334.0\lib\net20\MigraDoc.RtfRendering.dll - - ..\..\..\packages\PDFsharp-MigraDoc-GDI.1.32.3879.0\lib\net20\PdfSharp.dll + + False + ..\..\..\packages\PDFsharp-MigraDoc-GDI.1.32.4334.0\lib\net20\PdfSharp.dll - - ..\..\..\packages\PDFsharp-MigraDoc-GDI.1.32.3879.0\lib\net20\PdfSharp.Charting.dll + + False + ..\..\..\packages\PDFsharp-MigraDoc-GDI.1.32.4334.0\lib\net20\PdfSharp.Charting.dll diff --git a/src/examples/MigraDoc.Extensions.Html.Example/Program.cs b/src/examples/MigraDoc.Extensions.Html.Example/Program.cs index cdbbd33..75196af 100644 --- a/src/examples/MigraDoc.Extensions.Html.Example/Program.cs +++ b/src/examples/MigraDoc.Extensions.Html.Example/Program.cs @@ -1,4 +1,5 @@ using MigraDoc.DocumentObjectModel; +using MigraDoc.DocumentObjectModel.IO; using MigraDoc.Extensions.Markdown; using MigraDoc.Rendering; using System.Diagnostics; @@ -35,6 +36,11 @@ void Run() var renderer = new PdfDocumentRenderer(); renderer.Document = doc; +#if DEBUG + DdlWriter dw = new DdlWriter(@"output.mdddl"); + dw.WriteDocument(doc); + dw.Close(); +#endif renderer.RenderDocument(); renderer.Save(outputName); @@ -78,16 +84,25 @@ private void StyleDoc(Document doc) var links = doc.Styles["Hyperlink"]; links.Font.Color = green; - var unorderedlist = doc.AddStyle("UnorderedList", "Normal"); + var unorderedlist1 = doc.AddStyle("UnorderedList1", "Normal"); var listInfo = new ListInfo(); listInfo.ListType = ListType.BulletList1; - unorderedlist.ParagraphFormat.ListInfo = listInfo; - unorderedlist.ParagraphFormat.LeftIndent = "1cm"; - unorderedlist.ParagraphFormat.FirstLineIndent = "-0.5cm"; - unorderedlist.ParagraphFormat.SpaceAfter = 0; + unorderedlist1.ParagraphFormat.ListInfo = listInfo; + unorderedlist1.ParagraphFormat.LeftIndent = "1cm"; + unorderedlist1.ParagraphFormat.FirstLineIndent = "-0.5cm"; + unorderedlist1.ParagraphFormat.SpaceAfter = 0; - var orderedlist = doc.AddStyle("OrderedList", "UnorderedList"); + var unorderedlist2 = doc.AddStyle("UnorderedList2", "UnorderedList1"); + unorderedlist2.ParagraphFormat.ListInfo.ListType = ListType.BulletList2; + var unorderedlist3 = doc.AddStyle("UnorderedList3", "UnorderedList1"); + unorderedlist3.ParagraphFormat.ListInfo.ListType = ListType.BulletList3; + + var orderedlist = doc.AddStyle("OrderedList1", "UnorderedList1"); orderedlist.ParagraphFormat.ListInfo.ListType = ListType.NumberList1; + var orderedlist2 = doc.AddStyle("OrderedList2", "UnorderedList1"); + orderedlist2.ParagraphFormat.ListInfo.ListType = ListType.NumberList2; + var orderedlist3 = doc.AddStyle("OrderedList3", "UnorderedList1"); + orderedlist3.ParagraphFormat.ListInfo.ListType = ListType.NumberList3; // for list spacing (since MigraDoc doesn't provide a list object that we can target) var listStart = doc.AddStyle("ListStart", "Normal"); diff --git a/src/examples/MigraDoc.Extensions.Html.Example/packages.config b/src/examples/MigraDoc.Extensions.Html.Example/packages.config index ccc059e..50ba0f8 100644 --- a/src/examples/MigraDoc.Extensions.Html.Example/packages.config +++ b/src/examples/MigraDoc.Extensions.Html.Example/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/src/specs/MigraDoc.Extensions.Html.Specs/MigraDoc.Extensions.Html.Specs.csproj b/src/specs/MigraDoc.Extensions.Html.Specs/MigraDoc.Extensions.Html.Specs.csproj index 883af38..65d38ba 100644 --- a/src/specs/MigraDoc.Extensions.Html.Specs/MigraDoc.Extensions.Html.Specs.csproj +++ b/src/specs/MigraDoc.Extensions.Html.Specs/MigraDoc.Extensions.Html.Specs.csproj @@ -36,14 +36,17 @@ False ..\..\..\packages\HtmlAgilityPack.1.4.6\lib\Net45\HtmlAgilityPack.dll - - ..\..\..\packages\PDFsharp-MigraDoc-GDI.1.32.3879.0\lib\net20\MigraDoc.DocumentObjectModel.dll + + False + ..\..\..\packages\PDFsharp-MigraDoc-GDI.1.32.4334.0\lib\net20\MigraDoc.DocumentObjectModel.dll - - ..\..\..\packages\PDFsharp-MigraDoc-GDI.1.32.3879.0\lib\net20\MigraDoc.Rendering.dll + + False + ..\..\..\packages\PDFsharp-MigraDoc-GDI.1.32.4334.0\lib\net20\MigraDoc.Rendering.dll - - ..\..\..\packages\PDFsharp-MigraDoc-GDI.1.32.3879.0\lib\net20\MigraDoc.RtfRendering.dll + + False + ..\..\..\packages\PDFsharp-MigraDoc-GDI.1.32.4334.0\lib\net20\MigraDoc.RtfRendering.dll False @@ -52,11 +55,13 @@ ..\..\..\packages\NUnit.2.6.2\lib\nunit.framework.dll - - ..\..\..\packages\PDFsharp-MigraDoc-GDI.1.32.3879.0\lib\net20\PdfSharp.dll + + False + ..\..\..\packages\PDFsharp-MigraDoc-GDI.1.32.4334.0\lib\net20\PdfSharp.dll - - ..\..\..\packages\PDFsharp-MigraDoc-GDI.1.32.3879.0\lib\net20\PdfSharp.Charting.dll + + False + ..\..\..\packages\PDFsharp-MigraDoc-GDI.1.32.4334.0\lib\net20\PdfSharp.Charting.dll diff --git a/src/specs/MigraDoc.Extensions.Html.Specs/define_htmlconverter.cs b/src/specs/MigraDoc.Extensions.Html.Specs/define_htmlconverter.cs index 07b975f..14468c9 100644 --- a/src/specs/MigraDoc.Extensions.Html.Specs/define_htmlconverter.cs +++ b/src/specs/MigraDoc.Extensions.Html.Specs/define_htmlconverter.cs @@ -10,14 +10,14 @@ class define_htmlconverter : nspec void before_each() { - converter = new HtmlConverter(); + converter = new HtmlConverter(1.0); pdf = new Section(); } void adding_custom_handlers() { before = () => converter.NodeHandlers.Add( - "img", (node, parent) => ((Section)parent).AddParagraph() + "img", (node, parent, parentSection) => ((Section)parent).AddParagraph() ); act = () => pdf.Add("", converter); diff --git a/src/specs/MigraDoc.Extensions.Html.Specs/packages.config b/src/specs/MigraDoc.Extensions.Html.Specs/packages.config index 0571187..81af315 100644 --- a/src/specs/MigraDoc.Extensions.Html.Specs/packages.config +++ b/src/specs/MigraDoc.Extensions.Html.Specs/packages.config @@ -3,5 +3,5 @@ - + \ No newline at end of file