nea / MarkdownViewerPlusPlus

A Notepad++ Plugin to view a Markdown file rendered on-the-fly
MIT License
1.17k stars 143 forks source link

unnecessary <p> tags inside list items if a list follows directly to another list #25

Closed raffaelj closed 7 years ago

raffaelj commented 7 years ago

At first: Thank you for this great plugin. It's that thing I needed since I write everything in markdown and sometimes want to export HTML or PDFs.

But I discovered a bug. If I just write some list items without headlines or text between two or more lists the plugin creates p tags inside the list items. Also all list items from different lists are in one list.

system: Win 7 64 bit, Notepad++ 7.3.3 MarkdownViewer++ 0.7.1

works like expected:

2017-03-22_113031

with p inside li:

2017-03-22_112915

HTML output:

    <ul>
      <li>
        <p>list item</p>
      </li>
      <!-- ... -->
      <li>
        <p>list item</p>
        <ul>
          <li>nested list</li>
        </ul>
      </li>
      <li>
        <p>another list</p>
      </li>
      <!-- ... -->
      <li>
        <p>another list</p>
      </li>
    </ul>
nea commented 7 years ago

Hi @raffaelj

Glad to hear somebody else find it useful :) Always good to know.

Regarding the <p>: That's not really a bug but just how it works by specification. You can checkout http://spec.commonmark.org/0.27/#list-items and the follow-up chapter. The <p> element is only present if you look at your second example, not in the first. And there it has to be, because the line breaks are iterpreted as part of the list, therefore they get encapsulated in paragraphs. And to stay consistent, the whole list is treated like that.

Regarding the "separate lists": That does work as intended, too. You can checkout http://spec.commonmark.org/0.27/#lists. If you do not start a new paragraph the second list is just the ability to add more text, line breaks etc. The specification states:

To separate consecutive lists of the same type, or to separate a list from an indented code block that would otherwise be parsed as a subparagraph of the final list item, you can insert a blank HTML comment

So, it is a matter of interpreting and using the CommonMark specification. I just encapsulate CommonMark/Markdig and they conform to the specification. Therefore, you would have to adapt your case to a specification fitting text, by e.g. adding an intermediate headline or description. As mentioned, look at the spec, as it provides many helpful examples.

I hope this helps ^^

Cheers

raffaelj commented 7 years ago

Thank you. I never noticed this behavior. Normally I use github flavoured markdown with jekyll and I write notes in Notepad++ with a custom language file for markdown.

I tested it with a jekyll website from me and noticed that there is only one <p> element inside the last list element before the linebreaks and both list are inside one long list. It's a bit different and I learned something new.

I also noticed that I used li p{display:inline} to prevent line breaks inside lists with more content. I added this custom css into your plugin and now it looks like expected. Problem solved.

nea commented 7 years ago

Awesome. Thanks for the background and custom CSS for future occurrences. :)