Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block elements inside list items throws exception #3

Open
benfoster opened this issue Jul 1, 2013 · 6 comments
Open

Block elements inside list items throws exception #3

benfoster opened this issue Jul 1, 2013 · 6 comments
Labels

Comments

@benfoster
Copy link
Owner

No description provided.

@BenLewies
Copy link

Good day

I have a similar issue which I think relates to this item. The following markdown causes an exception:

1. Numbered item
<br/><br/>
1. Another numbered item:<br/>
#Case number# Crim123. Occurred on 2014/04/17. Dope.
<br/>
1. Yet another numbered item

Exception details as follows:
System.InvalidCastException was caught
_HResult=-2147467262
_message=Unable to cast object of type 'MigraDoc.DocumentObjectModel.Paragraph' to type 'MigraDoc.DocumentObjectModel.Section'.
HResult=-2147467262
IsTransient=false
Message=Unable to cast object of type 'MigraDoc.DocumentObjectModel.Paragraph' to type 'MigraDoc.DocumentObjectModel.Section'.
Source=MigraDoc.Extensions.Html
StackTrace:
at MigraDoc.Extensions.Html.HtmlConverter.b__b(HtmlNode node, DocumentObject parent) in c:\Users\MyName\Dropbox\MyCompany\Active Projects\MySiteOnline\MySiteOnline\MigraDoc.Extensions\src\MigraDoc.Extensions.Html\HtmlConverter.cs:line 122
at MigraDoc.Extensions.Html.HtmlConverter.ConvertHtmlNodes(HtmlNodeCollection nodes, DocumentObject section, DocumentObject current) in c:\Users\MyName\Dropbox\MyCompany\Active Projects\MySiteOnline\MySiteOnline\MigraDoc.Extensions\src\MigraDoc.Extensions.Html\HtmlConverter.cs:line 58
at MigraDoc.Extensions.Html.HtmlConverter.ConvertHtmlNodes(HtmlNodeCollection nodes, DocumentObject section, DocumentObject current) in c:\Users\MyName\Dropbox\MyCompany\Active Projects\MySiteOnline\MySiteOnline\MigraDoc.Extensions\src\MigraDoc.Extensions.Html\HtmlConverter.cs:line 69
at MigraDoc.Extensions.Html.HtmlConverter.ConvertHtmlNodes(HtmlNodeCollection nodes, DocumentObject section, DocumentObject current) in c:\Users\MyName\Dropbox\MyCompany\Active Projects\MySiteOnline\MySiteOnline\MigraDoc.Extensions\src\MigraDoc.Extensions.Html\HtmlConverter.cs:line 62
at MigraDoc.Extensions.Html.HtmlConverter.ConvertHtmlNodes(HtmlNodeCollection nodes, DocumentObject section, DocumentObject current) in c:\Users\MyName\Dropbox\MyCompany\Active Projects\MySiteOnline\MySiteOnline\MigraDoc.Extensions\src\MigraDoc.Extensions.Html\HtmlConverter.cs:line 69
at MigraDoc.Extensions.Html.HtmlConverter.ConvertHtml(String html, Section section) in c:\Users\MyName\Dropbox\MyCompany\Active Projects\MySiteOnline\MySiteOnline\MigraDoc.Extensions\src\MigraDoc.Extensions.Html\HtmlConverter.cs:line 47
at MigraDoc.Extensions.Html.HtmlConverter.<>c__DisplayClass1.b__0(Section section) in c:\Users\MyName\Dropbox\MyCompany\Active Projects\MySiteOnline\MySiteOnline\MigraDoc.Extensions\src\MigraDoc.Extensions.Html\HtmlConverter.cs:line 30
at MigraDoc.Extensions.SectionExtensions.Add(Section section, String contents, IConverter converter) in c:\Users\MyName\Dropbox\MyCompany\Active Projects\MySiteOnline\MySiteOnline\MigraDoc.Extensions\src\MigraDoc.Extensions\SectionExtensions.cs:line 20
at MigraDoc.Extensions.Markdown.SectionExtensions.AddMarkdown(Section section, String markdown) in c:\Users\MyName\Dropbox\MyCompany\Active Projects\MySiteOnline\MySiteOnline\MigraDoc.Extensions\src\MigraDoc.Extensions.Markdown\SectionExtensions.cs:line 11
at MySiteOnline.Reporting.MotivationHelper.DefineSummary(Document document, Client client, Motivation motivation) in c:\Users\MyName\Desktop\MySiteOnline\MySiteOnline\MySiteOnline_Reporting\MotivationHelper.cs:line 496
at MySiteOnline.Reporting.MotivationHelper.CreateDocument(Client client, Motivation motivation) in c:\Users\MyName\Desktop\MySiteOnline\MySiteOnline\MySiteOnline_Reporting\MotivationHelper.cs:line 147
at MySiteOnline.Reporting.MotivationHelper.CreateMotivationDocument(Client client, Motivation motivation, String path) in c:\Users\MyName\Desktop\MySiteOnline\MySiteOnline\MySiteOnline_Reporting\MotivationHelper.cs:line 52
InnerException:

@BenLewies
Copy link

@benfoster Just want to find out if there will be a fix for this soon. I have been holding out for a fix on this issue as I like really this library - this is really good stuff! However, I can't wait much longer (this is holding back delivery of a project on my side).

If not, it's 100% OK (I understand we are all busy and this work is basically charity)... But still I thought it best to ask before implementing an alternative solution.

@BenLewies
Copy link

@benfoster Hi Ben

Going over the stacktrace, I suspect the root cause of the null reference exception might be found at Migradoc.Extensions.Html.HtmlConverter in the ConvertHtml method. I am not sure how to fix it, though.

Regards,
Ben

@benfoster
Copy link
Owner Author

Hi Ben,

The issue is not actually caused by line breaks as I'd originally thought. The way in which we convert <hX>,

and <li> tags to to the Migradoc object model is to render a paragraph with a specific style. This relies on the parent node in the model being a Section. Unfortunately when a list item contains other paragraphs or headings, the converter attempts to add another paragraph to the list item paragraph. Since nested paragraphs are not supported by Migradoc we get an exception.

To fix I think we'll need to render any container elements like list items as sections but this requires further thought. I'll hopefully get time to look into this in the next few weeks.

@benfoster benfoster changed the title Line breaks inside list items throw exception Block elements inside list items throws exception Aug 6, 2014
@BenLewies
Copy link

Thanks for the feedback. I'll give it some thought too.

@BenLewies
Copy link

Hi Ben

So, I see there is actually a pending pull request which partly solves / provides a workaround for this problem. I downloaded and compiled it, and it seems to work, at least for nested

  • items. In my own solution I just suppress any header elements which might appear within a list.

    Adding support for nested ordered and unordered lists #5

    I hope this can be of some help to you.

    Cheers

    [UPDATE]
    Nested lists does not work 100% as expected since bulleted list items spanning multiple lines are not properly indented - the text of the second and third lines etc continues right underneath the bullet.

  • Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants