--- format.php.orig	2007-01-09 16:42:53.000000000 -0500
+++ format.php	2007-01-09 16:45:21.000000000 -0500
@@ -10,6 +10,7 @@
 // Based on default.php, included by ../import.php
 
 require_once ("$CFG->libdir/xmlize.php");
+require_once ("$CFG->libdir/tcpdf/html_entity_decode_php4.php");
 
 class qformat_blackboard extends qformat_default {
 
@@ -136,27 +137,52 @@
         $question->single = 1; // Only one answer is allowed
 
         $thisquestion = $mcquestions[$i];
+
+        // determine if the question is already escaped html
+        $ishtml = $thisquestion["#"]["BODY"][0]["#"]["FLAGS"][0]["#"]["ISHTML"][0]["@"]["value"];
+
         // put questiontext in question object
-        $question->questiontext = addslashes(trim($thisquestion["#"]["BODY"][0]["#"]["TEXT"][0]["#"]));
-        // put name of question in question object
-        $question->name = $question->questiontext;
+        if ($ishtml) {
+            $question->questiontext = html_entity_decode_php4(trim($thisquestion["#"]["BODY"][0]["#"]["TEXT"][0]["#"]));
+        }
+        else {
+            $question->questiontext = addslashes(trim($thisquestion["#"]["BODY"][0]["#"]["TEXT"][0]["#"]));
+        }
+
+        // put name of question in question object, careful of length
+        $question->name = substr($question->questiontext, 0, 254);
 
         $choices = $thisquestion["#"]["ANSWER"];
         for ($j = 0; $j < sizeof ($choices); $j++) {
 
             $choice = trim($choices[$j]["#"]["TEXT"][0]["#"]);
             // put this choice in the question object.
-            $question->answer[$j] = addslashes($choice);
+            if ($ishtml) {
+                $question->answer[$j] = html_entity_decode_php4($choice);
+            }
+            else {
+                $question->answer[$j] = addslashes($choice);
+            }
 
             $id = $choices[$j]["@"]["id"];
             $correct_answer_id = $thisquestion["#"]["GRADABLE"][0]["#"]["CORRECTANSWER"][0]["@"]["answer_id"];
             // if choice is the answer, give 100%, otherwise give 0%
             if (strcmp ($id, $correct_answer_id) == 0) {
                 $question->fraction[$j] = 1;
-                $question->feedback[$j] = addslashes(trim(@$thisquestion["#"]["GRADABLE"][0]["#"]["FEEDBACK_WHEN_CORRECT"][0]["#"]));
+                if ($ishtml) {
+                    $question->feedback[$j] = html_entity_decode_php4(trim(@$thisquestion["#"]["GRADABLE"][0]["#"]["FEEDBACK_WHEN_CORRECT"][0]["#"]));
+                }
+                else {
+                    $question->feedback[$j] = addslashes(trim(@$thisquestion["#"]["GRADABLE"][0]["#"]["FEEDBACK_WHEN_CORRECT"][0]["#"]));
+                }
             } else {
                 $question->fraction[$j] = 0;
-                $question->feedback[$j] = addslashes(trim(@$thisquestion["#"]["GRADABLE"][0]["#"]["FEEDBACK_WHEN_INCORRECT"][0]["#"]));
+                if ($ishtml) {
+                    $question->feedback[$j] = html_entity_decode_php4(trim(@$thisquestion["#"]["GRADABLE"][0]["#"]["FEEDBACK_WHEN_INCORRECT"][0]["#"]));
+                }
+                else {
+                    $question->feedback[$j] = addslashes(trim(@$thisquestion["#"]["GRADABLE"][0]["#"]["FEEDBACK_WHEN_INCORRECT"][0]["#"]));
+                }
             }
         }
         $questions[] = $question;
