From edfd9da42ab53b035671b256e1b76fd72fb31504 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Sun, 17 Jul 2016 11:15:37 +0200 Subject: [PATCH] Support MathML in HTML message preview (#5182) --- CHANGELOG | 1 + program/lib/Roundcube/rcube_washtml.php | 24 ++++++++++++- tests/Framework/Washtml.php | 46 ++++++++++++++++++++++++- 3 files changed, 69 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 9ca7fda9f..a6db41741 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ CHANGELOG Roundcube Webmail =========================== +- Support MathML in HTML message preview (#5182) - Rename Addressbook to Contacts (#5233) - Remove PHP mail() support, smtp_server is required now (#5340) - Display full message subject in onmouseover on truncated subject in mail view (#5346) diff --git a/program/lib/Roundcube/rcube_washtml.php b/program/lib/Roundcube/rcube_washtml.php index d03f04af4..e1058fd8d 100644 --- a/program/lib/Roundcube/rcube_washtml.php +++ b/program/lib/Roundcube/rcube_washtml.php @@ -76,7 +76,7 @@ * - base URL support * - invalid HTML comments removal before parsing * - "fixing" unitless CSS values for XHTML output - * - base url resolving + * - SVG and MathML support */ /** @@ -111,6 +111,15 @@ class rcube_washtml 'feflood', 'fefunca', 'fefuncb', 'fefuncg', 'fefuncr', 'fegaussianblur', 'feimage', 'femerge', 'femergenode', 'femorphology', 'feoffset', 'fespecularlighting', 'fetile', 'feturbulence', + // MathML + 'math', 'menclose', 'merror', 'mfenced', 'mfrac', 'mglyph', 'mi', 'mlabeledtr', + 'mmuliscripts', 'mn', 'mo', 'mover', 'mpadded', 'mphantom', 'mroot', 'mrow', + 'ms', 'mspace', 'msqrt', 'mstyle', 'msub', 'msup', 'msubsup', 'mtable', 'mtd', + 'mtext', 'mtr', 'munder', 'munderover', 'maligngroup', 'malignmark', + 'mprescripts', 'semantics', 'annotation', 'annotation-xml', 'none', + 'infinity', 'matrix', 'matrixrow', 'ci', 'cn', 'sep', 'apply', + 'plus', 'minus', 'eq', 'power', 'times', 'divide', 'csymbol', 'root', + 'bvar', 'lowlimit', 'uplimit', ); /* Ignore these HTML tags and their content */ @@ -153,11 +162,24 @@ class rcube_washtml 'visibility', 'vert-adv-y', 'version', 'vert-origin-x', 'vert-origin-y', 'word-spacing', 'wrap', 'writing-mode', 'xchannelselector', 'ychannelselector', 'x', 'x1', 'x2', 'xmlns', 'y', 'y1', 'y2', 'z', 'zoomandpan', + // MathML + 'accent', 'accentunder', 'bevelled', 'close', 'columnalign', 'columnlines', + 'columnspan', 'denomalign', 'depth', 'display', 'displaystyle', 'encoding', 'fence', + 'frame', 'largeop', 'length', 'linethickness', 'lspace', 'lquote', + 'mathbackground', 'mathcolor', 'mathsize', 'mathvariant', 'maxsize', + 'minsize', 'movablelimits', 'notation', 'numalign', 'open', 'rowalign', + 'rowlines', 'rowspacing', 'rowspan', 'rspace', 'rquote', 'scriptlevel', + 'scriptminsize', 'scriptsizemultiplier', 'selection', 'separator', + 'separators', 'stretchy', 'subscriptshift', 'supscriptshift', 'symmetric', 'voffset', + 'fontsize', 'fontweight', 'fontstyle', 'fontfamily', 'groupalign', 'edge', 'side', ); /* Elements which could be empty and be returned in short form () */ static $void_elements = array('area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr', + // MathML + 'sep', 'infinity', 'in', 'plus', 'eq', 'power', 'times', 'divide', 'root', + 'maligngroup', 'none', 'mprescripts', ); /* State for linked objects in HTML */ diff --git a/tests/Framework/Washtml.php b/tests/Framework/Washtml.php index ef4b2e9a0..18dfcab54 100644 --- a/tests/Framework/Washtml.php +++ b/tests/Framework/Washtml.php @@ -239,7 +239,7 @@ class Framework_Washtml extends PHPUnit_Framework_TestCase /** * Test SVG cleanup */ - function test_style_wash_svg() + function test_wash_svg() { $svg = ' @@ -274,4 +274,48 @@ class Framework_Washtml extends PHPUnit_Framework_TestCase $this->assertSame($washed, $exp, "SVG content"); } + + /** + * Test MathML cleanup + */ + function test_wash_mathml() + { + $mathml = ' + + + ID + = + 12 + kn + WL + ( + VGS + -Vt + )2 + + I_D = \frac{1}{2} k_n \frac{W}{L} (V_{GS}-V_t)^2 + + '; + + $exp = ' + + + ID + = + 12 + kn + WL + ( + VGS + -Vt + )2 + + I_D = \frac{1}{2} k_n \frac{W}{L} (V_{GS}-V_t)^2 + '; + + $washer = new rcube_washtml; + $washed = $washer->wash($mathml); + + $this->assertSame(trim($washed), trim($exp), "MathML content"); + } }