MDL-12039 Added ability to configure alt text when using TeX filter

This commit is contained in:
sam_marshall
2007-11-06 15:49:03 +00:00
parent 8ba59d07d7
commit f5ceb06a32
+16 -7
View File
@@ -38,9 +38,11 @@
$CFG->texfilterdir = "filter/tex";
function string_file_picture_tex($imagefile, $tex= "", $height="", $width="", $align="middle") {
// Given the path to a picture file in a course, or a URL,
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;
@@ -53,6 +55,11 @@ function string_file_picture_tex($imagefile, $tex= "", $height="", $width="", $a
$tex = str_replace('>','>',$tex);
$tex = str_replace('"','"',$tex);
$tex = str_replace("\'",''',$tex);
// Note that we retain the title tag as TeX format rather than using
// the alt text, even if supplied. The alt text is intended for blind
// users (to provide a text equivalent to the equation) while the title
// is there as a convenience for sighted users who want to see the TeX
// code.
$title = "title=\"$tex\"";
}
if ($height) {
@@ -72,7 +79,7 @@ function string_file_picture_tex($imagefile, $tex= "", $height="", $width="", $a
$output .= urlencode($tex) . "', 'popup', 'menubar=0,location=0,scrollbars,";
$output .= "resizable,width=300,height=240', 0);\">";
}
$output .= "<img class=\"texrender\" $title alt=\"".s($origtex)."\" src=\"";
$output .= "<img class=\"texrender\" $title alt=\"$alt\" src=\"";
if ($CFG->slasharguments) { // Use this method if possible for better caching
$output .= "$CFG->wwwroot/$CFG->texfilterdir/pix.php/$imagefile";
} else {
@@ -119,12 +126,14 @@ function tex_filter ($courseid, $text) {
}
// <tex> TeX expression </tex>
// or <tex alt="My alternative text to be used instead of the TeX form"> TeX expression </tex>
// or $$ TeX expression $$
// or \[ TeX expression \] // original tag of MathType and TeXaide (dlnsk)
// or [tex] TeX expression [/tex] // somtime it's more comfortable than <tex> (dlnsk)
preg_match_all('/<tex>(.+?)<\/tex>|\$\$(.+?)\$\$|\\\\\[(.+?)\\\\\]|\\[tex\\](.+?)\\[\/tex\\]/is', $text, $matches);
preg_match_all('/<tex(?:\s+alt=["\'](.*?)["\'])?>(.+?)<\/tex>|\$\$(.+?)\$\$|\\\\\[(.+?)\\\\\]|\\[tex\\](.+?)\\[\/tex\\]/is', $text, $matches);
for ($i=0; $i<count($matches[0]); $i++) {
$texexp = $matches[1][$i] . $matches[2][$i] . $matches[3][$i] . $matches[4][$i];
$texexp = $matches[2][$i] . $matches[3][$i] . $matches[4][$i] . $matches[5][$i];
$alt = $matches[1][$i];
$texexp = str_replace('<nolink>','',$texexp);
$texexp = str_replace('</nolink>','',$texexp);
$texexp = str_replace('<span class="nolink">','',$texexp);
@@ -148,7 +157,7 @@ function tex_filter ($courseid, $text) {
insert_record("cache_filters",$texcache, false);
}
$filename = $md5 . ".gif";
$text = str_replace( $matches[0][$i], string_file_picture_tex($filename, $texexp, '', '', $align), $text);
$text = str_replace( $matches[0][$i], string_file_picture_tex($filename, $texexp, '', '', $align, $alt), $text);
}
return $text;
}