To reproduce the bug:
1. in a course, create a resource of type "Display Folder"
2. in the Summary field enter a simple text, WITHOUT formatting it by the HTML editor
3. select any folder to display
3. save the resource
4. try validating the page: the pages validates correctly
5. Now, edit the above resource and using the HTML editor, format the summary text using Heading 1 or Heading 2, thus adding h1 or h2 HTML tags.
6. save the resource
7. try validating the page: the page fails validation, due to h1 or h2 tags contained inside an opened <p> tag.
The problem seems to be related to the presence of an open <p> tag inserted by the PHP code just before printing the summary HTML. The problem affects any resource containing an HTML formatted summary: for example, if creating a web page resource with HTML formatted summary, the Resource page list (the page where all the course resources are listed) does not validate; removing any HTML format from teh summaries, the page validates.
manually add a closing </p> tag on top of summary HTML and a opening <p> tag on bottom of summary HTML. This workaround is really error prone.
remove the opening <p> and closing </p> form the php code