christiaanderidder / QuestPDF.Markdown

QuestPDF.Markdown allows rendering markdown into a QuestPDF document
MIT License
29 stars 7 forks source link

Can't get a paragraph to allow new lines #66

Closed ryanlaclaire closed 3 months ago

ryanlaclaire commented 3 months ago

Hello,

I am running into an issue getting markdown to allow new lines within a paragraph. I created a basic C# console app. I am also using ReverseMarkdown and the QuestPdf.Previewer.

I create a simple html string like this based on your example: @"This a sample paragraph from <a href=\'http://test.com\'>my site
This is a NEW line of text!
Here's ANOTHER new line of text!";

ReverseMarkdown will generate this: This a sample paragraph from my site
This is a NEW line of text!
Here's ANOTHER new line of text!

There are two spaces at the end of the first two lines and none at the end.

After this runs through Markdown again, using your example: var document = Document.Create(container => { container.Page(page => { page.Margin(20); page.Content().Markdown(result); }); });

I get one line of text with all spaces from between lines removed. It's as if Markdown is removing what it considers excess space. Like this:

This is a sample paragraph from my siteThis is a NEW line of text!Here's ANOTHER new line of text!

Although it does show the correct bold, italics and link.

Am I doing something wrong or is markdown just not capable of allowing new lines within a paragraph?

I would like to note that if I double the
tags, it will break apart the paragraph but with an extra blank line between each new line

christiaanderidder commented 3 months ago

Hi,

I'm afraid it would be very hard to find out whether there is an issue in how QuestPdf.Markdown handles your input without having the exact and properly formatted input. Please make sure to use some code blocks (https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks) and provide the exact string that you are passing into QuestPdf.Markdown.

ryanlaclaire commented 3 months ago

Hi, Thanks for responding. My apologies, I should have thought to put it in a code block for you.

Here's the original text:

@"This is a sample <strong>paragraph</strong> from <a href=\'http://test.com\'>my site</a><br/>This is a <i>NEW</i> line of text!<br/>Here's <strong>ANOTHER</strong> new line of text!"

Here's what I get from the ReverseMarkdown converter:

This is a sample **paragraph** from [my site](\'http://test.com\')  
This is a *NEW* line of text!  
Here's **ANOTHER** new line of text!

I have also tried building it manually:

@"This is a sample **paragraph** from [my site](http::\\http://test.com)  
*This* is a *NEW* line of text!  
Here's ANOTHER new line of text!";

All I get back is one line of text, but where the
tags should be, all space is removed, both the end of line spaces and the new line.

christiaanderidder commented 3 months ago

I had a look at your examples. The markdown is parsed by the markdig library before being converted to PDF. Markdig follows the commonmark spec, which specifies that paragraphs should be separated by an empty line, see here: https://spec.commonmark.org/0.31.2/#paragraphs.

The following works as expected:

var input =
    """
    This is a sample **paragraph** from [my site]('http://test.com')

    This is a *NEW* line of text!

    Here's **ANOTHER** new line of text!
    """;

In the end it will depend on whether you can make reverse markdown produce this output, or modify it so that it matches the spec, but not something tha QuestPdf.Markdown can achieve for you.

Generally speaking I would not recommend going from HTML -> Markdown -> PDF, since HTML -> Markdown already has some challenges. The original reason for creating this library was to be able to move away from HTML -> PDF in a personal project and allow users to specify markdown directly, as this also reduces the amount of markup the users can use and keeps the PDFs simple and predictable.