Skip to content

Commit

Permalink
Removed needles line endings
Browse files Browse the repository at this point in the history
  • Loading branch information
twenzel committed Sep 5, 2017
1 parent 8ce2294 commit 91a5be8
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/Cake.MarkdownToPdf/MarkdownToPdfAliases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.IO;
using MigraDoc.DocumentObjectModel;
using System.Text.RegularExpressions;

namespace Cake.MarkdownToPdf
{
Expand Down Expand Up @@ -98,7 +99,9 @@ private static void ConvertTextToPdf(string markdownText, string outputFile)
var d = new MigraDoc.DocumentObjectModel.Document();
var section = d.AddSection();

MarkdownPdf.AddMarkdown(d, section, FSharp.Markdown.Markdown.Parse(markdownText, Environment.NewLine));
markdownText = RemoveSpareLineEndings(markdownText);

MarkdownPdf.AddMarkdown(d, section, markdownText);
ReplaceHtmlEntities(section.Elements);
ApplyDefaultStyle(d, section);

Expand All @@ -110,6 +113,17 @@ private static void ConvertTextToPdf(string markdownText, string outputFile)
r.PdfDocument.Save(outputFile);
}

private static string RemoveSpareLineEndings(string markdownText)
{
markdownText = markdownText.Replace(Environment.NewLine + Environment.NewLine, "\n\n\n\n");

markdownText = Regex.Replace(markdownText, "(\\r\\n(\\w))", " $2");

markdownText = markdownText.Replace("\n\n\n\n", Environment.NewLine + Environment.NewLine);

return markdownText;
}

private static void ReplaceHtmlEntities(DocumentObjectCollection elements)
{
foreach (var element in elements)
Expand Down

0 comments on commit 91a5be8

Please sign in to comment.