moodle-an-hochschulen / moodle-local_staticpage

Moodle plugin which displays static information pages which exist outside any course, imprint or faq pages for example, complete with Moodle navigation and theme
GNU General Public License v3.0
46 stars 28 forks source link

Parsing error because of missing style class in body #64

Closed mrkskwsnck closed 2 years ago

mrkskwsnck commented 2 years ago

According to the example at Creating static page documents I encountered a bug regarding a missing CSS class of the body tag, mentioned at Styling static pages.

TL;DR

With declared but missing CSS class a corrupt document declaration gets rendered!

image


In more detail

Document foo.html

<html>
<head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Foo</title>
</head>
<body>
        <h1>Foo</h1>
        [Your content goes here]
</body>
</html>

Rendered document OK

image

Document bar.html

¡With declared CSS class not being defined anywhere!

<html>
<head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Bar</title>
</head>
<body class="local-staticpage-bar">
        <h1>Bar</h1>
        [Your content goes here]
</body>
</html>

Rendered document FAIL

image

Rendered html output


</header>

        <div id="page-content" class="row pb-3 d-print-block">
            <div id="region-main-box" class="col-12">

                <section id="region-main"  aria-label="Content">

                    <span class="notifications" id="user-notifications"></span>
                    <div role="main"><span id="maincontent"></span>YPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"&gt;
Bar<h1>Bar</h1>
        [Your content goes here]
</div>```
abias commented 2 years ago

Thanks @mrkskwsnck ,

after reading through your explanations (and as several issues like this have been reported throughout the last years), I had a closer look at what is happening here.

I finally saw that there was a really old bug which assumed that the document has a plain document tag without any classes or other attributes. If this was not the case, the extraction of the document content failed in the way how you saw it.

I have now modified these old content extraction lines and have changed them so that they use the DOMDocument API as well. This was done in f7db89c7c78fafebca2fc22dbddefaf9fb2e765a for 3.11 and backported to 3.10 and 3.9.

I will release a new version on moodle.org shortly.