From: tjhunt Date: Tue, 17 Feb 2009 05:24:41 +0000 (+0000) Subject: tex filter: MDL-18230 ensure we always generate valid XHTML. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=c1d9eeb920dc2b950902e8c966b3997330db1a95;p=moodle.git tex filter: MDL-18230 ensure we always generate valid XHTML. --- diff --git a/filter/tex/filter.php b/filter/tex/filter.php index 54cbe8acc0..01ee633d77 100644 --- a/filter/tex/filter.php +++ b/filter/tex/filter.php @@ -37,27 +37,30 @@ ///////////////////////////////////////////////////////////////////////////// function string_file_picture_tex($imagefile, $tex= "", $height="", $width="", $align="middle", $alt='') { - if($alt==='') { - $alt=s($tex); - } - // Given the path to a picture file in a course, or a URL, - // this function includes the picture in the page. global $CFG; - $output = ""; - $origtex = $tex; + if ($alt==='') { + $alt = s($tex); + } + + // Work out any necessary inline style. + $rules = array(); if ($align !== 'middle') { - $style = ' style="vertical-align:'.$align.';'; - } else { - $style = ''; + $rules[] = 'vertical-align:' . $align . ';'; } if ($height) { - $style .= " height:{$height}px;"; + $rules[] = 'height:' . $height . 'px;'; } if ($width) { - $style .= " width:{$width}px;"; + $rules[] = 'width:' . $width . 'px;'; } - $style .= '"'; + if (!empty($rules)) { + $style = ' style="' . implode('', $rules) . '" '; + } else { + $style = ''; + } + + // Prepare the title attribute. if ($tex) { $tex = str_replace('&','&',$tex); $tex = str_replace('<','<',$tex); @@ -71,6 +74,9 @@ function string_file_picture_tex($imagefile, $tex= "", $height="", $width="", $a // code. $title = "title=\"$tex\""; } + + // Build the output. + $output = ""; if ($imagefile) { if (!file_exists("$CFG->dataroot/filter/tex/$imagefile") && has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) { $output .= "wwwroot/filter/tex/texdebug.php\">"; @@ -87,7 +93,7 @@ function string_file_picture_tex($imagefile, $tex= "", $height="", $width="", $a } else { $output .= "$CFG->wwwroot/filter/tex/pix.php?file=$imagefile"; } - $output .= "\" $style />"; + $output .= "\" $style/>"; $output .= ""; } else { $output .= "Error: must pass URL or course";