Page MenuHomePhabricator

Tidy on WMF sites removes `<style>` tags
Closed, ResolvedPublic

Description

Or at least it does on Beta Labs.

Compare the results of a call to API action=parse with and without the disabletidy option:

With disabletidy

{
    "parse": {
        "title": "API",
        "pageid": 0,
        "text": {
            "*": "<div class=\"mw-parser-output\"><p><style>.mw-parser-output .foo{color:red}</style>\n</p></div>"
        }
    }
}

Without disabletidy

{
    "parse": {
        "title": "API",
        "pageid": 0,
        "text": {
            "*": "<div class=\"mw-parser-output\">\n</div>"
        }
    }
}

Related Objects

StatusSubtypeAssignedTask
DeclinedNone
ResolvedJdlrobson
DeclinedNone
DuplicateNone
ResolvedJdlrobson
DuplicateNone
DuplicateNone
DeclinedNone
ResolvedJdlrobson
DuplicateNone
DuplicateNone
ResolvedNone
OpenNone
OpenNone
ResolvedTheDJ
DeclinedNone
InvalidNone
OpenFeatureNone
InvalidNone
ResolvedTheDJ
ResolvedTheDJ
InvalidNone
ResolvedIzno
ResolvedTheDJ
OpenNone
ResolvedJdlrobson
Openovasileva
DeclinedNone
ResolvedTgr
ResolvedAnomie

Event Timeline

FWIW, RemexHtml seems to be fine with the <style> tags.

Testing with mediawiki-vagrant, it looks like recompiling hhvm-tidy with the version of tidy in Stretch also fixes it.

RaggettWrapper has:

// Modify inline Microdata <link> and <meta> elements so they say <html-link> and <html-meta> so
// we can trick Tidy into not stripping them out by including them in tidy's new-empty-tags config
$wrappedtext = preg_replace( '!<(link|meta)([^>]*?)(/{0,1}>)!', '<html-$1$2$3', $wrappedtext );

You probably just need to add style to that tag list, and to the corresponding one in postprocess().

Except that it would probably encode bare angle brackets and otherwise mangle the stylesheet. You could wrap with <![CDATA[]]>, or stuff the element contents into an attribute.

Change 358636 had a related patch set uploaded (by Anomie; owner: Anomie):
[mediawiki/core@master] Hide <style> tags from Tidy

https://gerrit.wikimedia.org/r/358636

Change 358636 merged by jenkins-bot:
[mediawiki/core@master] Hide <style> tags from Tidy

https://gerrit.wikimedia.org/r/358636

Anomie claimed this task.

Change 452952 had a related patch set uploaded (by Arlolra; owner: Subramanya Sastry):
[mediawiki/services/parsoid@master] Treat template-styles <style> tag specially wrt p-wrapping

https://gerrit.wikimedia.org/r/452952

Change 452952 merged by jenkins-bot:
[mediawiki/services/parsoid@master] Treat template-styles <style> tag specially wrt p-wrapping

https://gerrit.wikimedia.org/r/452952