After spending a week trying to workout why Drupal was rendering my Mathml (www.mathforall.co.za) all wrong I have some answers . Getting it to work was not that hard. All I had to do was change functions in the common.inc file. It's really and ugly solution for now, but it works. As soon as I get some time I will tidy it up.

Here is what I did:

1) Drupal sends content=\"text/html mime type out be default. I think they do this so that M$ IE (a primitive browser) will not explode when it visits a Drupal site. So I changed Drupal to send application/xhtml+xml mime type to some browsers. I added the broken_browser() function based on code I found at:
http://hacks.oreilly.com/pub/h/2916

function broken_browser()
{
$agent = $_SERVER['HTTP_USER_AGENT'];
$broken = FALSE;
$broken = $broken || (stristr($agent, "msie") && !stristr($agent, "opera"));
$broken = $broken || stristr($agent, "microsoft internet explorer");
$broken = $broken || stristr($agent, "mspie");
$broken = $broken || stristr($agent, "pocket");

if ( $broken ) {
$head = "\n";
}
else {
$head = "\n";
}
return $head;
}

2) I changed drupal_get_html_head() to send a mime type determined by broken_browser().

/**
* Retrieve output to be displayed in the head tag of the HTML page.
*//**
* Retrieve output to be displayed in the head tag of the HTML page.
*/
function drupal_get_html_head() {

$output = broken_browser();
// $output = "\n";
$output .= theme('stylesheet_import', base_path() .'misc/drupal.css');
return $output . drupal_set_html_head();
}

3) This is the REALLY ugly part as it duplicates the same thing in a diffrent way. I added
broken_header() to the common.inc file.

function broken_header()
{
$agent = $_SERVER['HTTP_USER_AGENT'];
$broken = FALSE;
$broken = $broken || (stristr($agent, "msie") && !stristr($agent, "opera"));
$broken = $broken || stristr($agent, "microsoft internet explorer");
$broken = $broken || stristr($agent, "mspie");
$broken = $broken || stristr($agent, "pocket");
if ( $broken ) {
$head = "Content-Type: text/html; charset=utf-8";
}
else {
$head = "Content-Type: application/xhtml+xml; charset=utf-8";
}
return $head;
}

4) I changed drupal_set_header() to get its Content-Type from broken_header().

// Emit the correct charset HTTP header.
// drupal_set_header('Content-Type: text/html; charset=utf-8');
drupal_set_header(broken_header());

5) I changed my page.tpl template file like so :
(I use the box Grey template)

xml version="1.0" encoding="UTF-8"
DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN"
"http://www.w3.org/Math/DTD/mathml2/xhtml-math11-f.dtd"

html xmlns="http://www.w3.org/1999/xhtml

The downside:

1) Google adds broke for application/xhtml+xml compliant browsers. But it is still worth it.
2) Logged in as the admin user when I click on administer, Firefox throws an XML parser error. Looks to me like the problem is an em tag that's not closed.

Comments

stokito’s picture

Thanks!