Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<xmp class="prettyprint"> not styled by CSS #47

Closed
GoogleCodeExporter opened this issue Apr 19, 2016 · 2 comments
Closed

<xmp class="prettyprint"> not styled by CSS #47

GoogleCodeExporter opened this issue Apr 19, 2016 · 2 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1. Edit prettify_test.html to add a new test (see [TEST_PATCH]):
a) add a function to display the classname(s) of element with id='htmlXmp'.
b) modify <body onload=""> to show htmXmp's classname(s) before and after
prettyPrint() is called.
2. Open prettify_test.html in IE6.

(Please include HTML, not just your source code)
What is the expected output?  What do you see instead?

[Expected Output]
The classname of 'htmlXmp' should be same before and after prettyPrint() is
called.
1st AlertBox: "before - prettyprint"
2nd AlertBox: "after - prettyprint"

[Actual Output]
The classname of 'htmlXmp' is not set after prettyPrint() is called.
1st AlertBox: "before - prettyprint"
2nd AlertBox: "after - "

What version are you using?  On what browser?
Prettify revision 39, on IE6.

Please provide any additional information below.

It happens that, in IE, 
  pre.setAttribute('class', ..);
does not work, but 
  pre.className = 'classnames'; 
works on IE, and other browsers as well (as discussed in [1]).

[1]
http://www.quirksmode.org/bugreports/archives/2005/03/setAttribute_does_not_work
_in_IE_when_used_with_th.html

So, here's a patch to resolve the issue:

--- prettify.js (revision 39)
+++ prettify.js (working copy)
@@ -1136,6 +1136,9 @@
                 var a = cs.attributes[i];
                 if (a.specified) {
                   pre.setAttribute(a.name, a.value);
+                  if (a.name.toLowerCase() === 'class') {
+                    pre.className = a.value;
+                  }
                 }
               }
               pre.innerHTML = newContent;

============
[TEST_PATCH]
--- ../tests/prettify_test.html (revision 39)
+++ ../tests/prettify_test.html (working copy)
@@ -8,6 +8,9 @@
 // get accurate timing
 PR_SHOULD_USE_CONTINUATION = false;
 function pr_isIE6() { return false; }  // Ensure consistent output.
+function showClass(prefix) {
+  alert(prefix+' - '+document.getElementById('htmlXmp').className);
+}
 </script>
 <link rel="stylesheet" type="text/css" href="../src/prettify.css" />
 <style type="text/css">
@@ -16,7 +19,7 @@
 </head>

 <body
- onload="startClock(); prettyPrint(function () { stopClock(); runTests(); })"
+ onload="showClass('before'); startClock(); prettyPrint(function () {
stopClock(); runTests(); }); showClass('after')"
  bgcolor="white">
 <div id="timing"></div>
 <div id="errorReport" style="white-space: pre"></div>

Original issue reported on code.google.com by teohuiming on 6 Jul 2008 at 2:34

@GoogleCodeExporter
Copy link
Author

Original comment by mikesamuel@gmail.com on 7 Jul 2008 at 5:48

  • Changed state: Accepted

@GoogleCodeExporter
Copy link
Author

Original comment by mikesamuel@gmail.com on 13 Jul 2008 at 10:54

  • Changed state: Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant