RickStrahl / MarkdownMonster

An extensible Markdown Editor, Viewer and Weblog Publisher for Windows
https://markdownmonster.west-wind.com
Other
1.59k stars 235 forks source link

Extraneous trailing text when saving to PDF (also Alt-F misbehavior) #1025

Closed bcmadsen closed 1 year ago

bcmadsen commented 1 year ago

I notice a bug that didn't appear on March 24th but started appearing on April 1st. I wonder if it was introduced with version 2.8.11.

I have been using MM to keep minutes for a non-profit I volunteer for. In an effort to find the minimal case that demonstrates the bug, I've whittled my minutes down to something that will reproduce it reliably. See below.

<div style="text-align:center">
Board of Directors Meeting Minutes<br/>
Meeting conducted electronically via Zoom<br/>
March 4<sup>th</sup>, 2023<br/>
</div>

Woo shared a spreadsheet showing income and expenses for the period May 1, 2022 to February 28, 2023, attached to these minutes as [Feb 2023 IE.xlsx](Feb%202023%20IE.xlsx).

Now, I won't be surprised if you respond that I'm doing Markdown wrong, and if so, I welcome feedback on how to do it better. However, this worked on March 24th and causes problems today.

The problem is this: although this looks perfectly fine in the preview window, when I Save To PDF, using the Westwind theme (and I am telling you which theme I'm using because I also notice similar but not identical trailing text with other themes; still, Westwind is the one I like to use, given a choice), the PDF file ends with extraneous text. It looks to me like part of the tag \</body>, but that's a guess. Whatever it is, I would love to find a way to make that extraneous trailing text go away. It was not there before April, like I say.

The problem, whatever it is, is a weird combination of the use of \<div> and \<br/> tags in the header and the link to the external file in the paragraph. If I continue whittling down my minutes by removing those items, I quickly get to a point where I don't see the extraneous trailing text in the PDF.

Oh, by the way, while I'm here, I am noticing another problem in recent builds. I have a muscle-memory reflex to press Alt-F when I want to bring up the File menu. I know that doesn't work with MM -- that is, when I'm thinking carefully, I know you need me to bring up that menu with the mouse, not the keyboard -- but still, when I absent-mindedly try to invoke Alt-F, I get the "Yikes! Something went wrong! Do you want to continue?" error popup, and I get it consistently, every time. (Until recently, doing so just did nothing at all, and didn't generate this error.) As long as I'm here reporting an error, is that something you can fix?

bcmadsen commented 1 year ago

By the way, I have confirmed that the problem goes away if I uninstall MM 2.8.12, and instead install MM 2.8.7.

RickStrahl commented 1 year ago

Thanks for catching this.

Turns out this is caused by a bug related to a recent fix for link embedding in PDF files. That fix modified the original HTML output to remove URL encoding and then wrote the file back with the updated links if any links changed. Well, the 'overwrite' operation wasn't working correctly and the file was literally overwriting only the parts that were changed, but leaving part of the old file behind. Since the adjusted file was smaller what you see is the extra HTML from the old document.

The fix is to delete the file first then create a new one. This is a bug in HtmlAgility pack as there appears to be no option to completely overwrite a file using the Save method - it only 're-writes' the file. The delete/create combo works.

This will be fixed in the next update.

Thanks for your help.