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

StatusAssignedTask
OpenNone
OpenNone
ResolvedNone
DuplicateNone
OpenNone
OpenNone
OpenNone
DuplicateNone
OpenNone
OpenNone
ResolvedJdlrobson
DuplicateNone
DuplicateNone
OpenNone
OpenNone
StalledNone
InvalidNone
OpenNone
OpenNone
ResolvedTheDJ
ResolvedTheDJ
InvalidNone
OpenNone
ResolvedTheDJ
OpenNone
ResolvedJdlrobson
OpenJdlrobson
OpenJdlrobson
ResolvedTgr
ResolvedAnomie

Event Timeline

Anomie created this task.Jun 7 2017, 8:18 PM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptJun 7 2017, 8:18 PM
Anomie added a comment.Jun 7 2017, 8:40 PM

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

Anomie added a comment.Jun 7 2017, 9:25 PM

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 closed this task as Resolved.Jun 14 2017, 1:44 PM
Anomie claimed this task.
ggellerman moved this task from Up next to Done on the TemplateStyles board.Nov 21 2017, 7:15 PM

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