{"id":499,"date":"2009-07-10T19:37:49","date_gmt":"2009-07-10T23:37:49","guid":{"rendered":"http:\/\/www.outofwhatbox.com\/blog\/?p=499"},"modified":"2009-07-27T16:22:14","modified_gmt":"2009-07-27T20:22:14","slug":"dumping-hack-flash-its-a-class-class-class","status":"publish","type":"post","link":"https:\/\/www.outofwhatbox.com\/blog\/2009\/07\/dumping-hack-flash-its-a-class-class-class\/","title":{"rendered":"Dumping Hack Flash, It&#8217;s a Class, Class, Class"},"content":{"rendered":"<div class=\"oowbbtw\">The <strong>latest<\/strong> posted version of SyntaxHighlighter is <a href=\"http:\/\/static.outofwhatbox.com\/downloads\/SyntaxHighlighter\/syntaxhighlighter.zip\">here<\/a>. For the change history, or to download older versions from this site, see the <a href=\"http:\/\/www.outofwhatbox.com\/blog\/syntaxhighlighter-downloads\/\">downloads page<\/a>.<\/div>\n<p>Well, that was&#8230; interesting.<\/p>\n<p>I&#8217;ve been working on improvements in <a href=\"http:\/\/alexgorbatchev.com\/wiki\/SyntaxHighlighter\">SyntaxHighlighter<\/a>&#8216;s whitespace handling. My goal was to have whitespace presented exactly as it&#8217;s supplied within the original HTML. I thought this would be helpful on two fronts: First, it might fix a few minor display formatting issues that I&#8217;d found. Second, and of greater concern to me, I figured that if SyntaxHighlighter preserved whitespace well enough, then it would be OK to remove the Flash-based &#8220;Copy&#8221; applet from the toolbar. (I&#8217;m not sure, but my guess is that the Flash app was added <em>because<\/em> copying the code to the clipboard has been so problematic.)<\/p>\n<p>I&#8217;ll admit that its removal is a mixed blessing: It&#8217;s not like it&#8217;s a bad thing, to be able to copy the code to the clipboard with one click of the mouse. But the Flash applet carries some baggage, too: It requires Flash (well, yeah); it adds to the overall footprint consumed by SyntaxHighlighter (especially when using Internet Explorer); and it doesn&#8217;t always work.<\/p>\n<p>I don&#8217;t have a lot of details on that last one; then again, I haven&#8217;t sought details. But the problem could simply be that <a href=\"http:\/\/www.adobe.com\/devnet\/flashplayer\/articles\/fplayer10_uia_requirements.html\">Flash 10 added new restrictions<\/a> on the application&#8217;s access to the Clipboard, thereby breaking it for SyntaxHighlighter.<\/p>\n<p>Maybe, maybe not. But if the traditional select-and-copy operation worked as expected, without loss of newlines or other whitespace, would there really be any further <strong>need<\/strong> to keep the Flash script? I didn&#8217;t think so either.<\/p>\n<p>I think I can hear some of you snickering. No, I hadn&#8217;t ever gone down this road before. So, I&#8217;ve discovered that perfect whitespace preservation in HTML is not easy. It may not even be <strong>possible<\/strong>, even setting tab characters aside.<\/p>\n<p>I&#8217;d hoped to come up with a broadly cross-browser-compatible scheme for preserving whitespace in the display and in the paste buffer. What I have is a combination of JavaScript and CSS classes that fake it pretty well (I think.) The key, of course, lies in using the CSS <code>whitespace=\"pre\"<\/code> and <code>whitespace=\"pre-wrap\"<\/code> directives in the appropriate classes. JavaScript is needed, among other things, to ensure that line breaks come through correctly. And yes, I did have to break into browser-specfic code at times.<\/p>\n<p>Surprising things can happen to space characters &#8216;twixt the HTTP stack and the paste buffer. Throw in newlines and tabs <em>(On second thought: no, don&#8217;t throw in tabs; <a href=\"http:\/\/www.w3.org\/TR\/html401\/struct\/text.html#idx-text-1\">throw them out<\/a>)<\/em>, and life gets very interesting indeed.<\/p>\n<p>While the resulting release doesn&#8217;t quite fit the criteria for being <a href=\"http:\/\/en.wikipedia.org\/wiki\/WYSIWYG\">WYSIWYG<\/a>, I&#8217;d say it does at least satisfy <a href=\"http:\/\/en.wikipedia.org\/wiki\/You_can%27t_always_get_what_you_want\">YCAGWYWBIYTSYJMFYGWYN<\/a>. Tab characters are converted to spaces, and there are often one or two spaces added at the ends of lines. I&#8217;m guessing that this will be close enough for most uses. For those cases where exactness is required, there&#8217;s still the toolbar command for view the original source as plain text. The popped-up text preserves the original whitespace, and a &#8220;copy&#8221; works just fine there. Putting this all together, it did seem to me that the Flash app could now be dropped, and so I&#8217;ve done so.<\/p>\n<p>I&#8217;ve also added some tentative support for titles. Unfortunately, I can&#8217;t show an example in this post, because the <a href=\"http:\/\/www.viper007bond.com\/category\/wordpress\/my-wp-plugins\/syntaxhighlighter\/\">WordPress Plugin<\/a> doesn&#8217;t support the option yet; but you can see an example <a href=\"http:\/\/static.outofwhatbox.com\/shWhitespace\/testTitle.html\">here<\/a>. (I&#8217;d thought about adding this previously, then discarded it as creeping featurism, and then re-considered it when I realized that it might be of use for the visually disabled.)<\/p>\n<p>And there are a lot of changes under the hood; I&#8217;ll write about these in separate posts. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>SyntaxHighlighter now preserves whitespace. Kind of. It&#8217;s not pure WYSIWYG, but it&#8217;s YCAGWYWBIYTSYJMFYGWYN. It&#8217;s good enough that we can stop using Flash to access the clipboard.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3,20],"tags":[22,21,23,24],"_links":{"self":[{"href":"https:\/\/www.outofwhatbox.com\/blog\/wp-json\/wp\/v2\/posts\/499"}],"collection":[{"href":"https:\/\/www.outofwhatbox.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.outofwhatbox.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.outofwhatbox.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.outofwhatbox.com\/blog\/wp-json\/wp\/v2\/comments?post=499"}],"version-history":[{"count":16,"href":"https:\/\/www.outofwhatbox.com\/blog\/wp-json\/wp\/v2\/posts\/499\/revisions"}],"predecessor-version":[{"id":512,"href":"https:\/\/www.outofwhatbox.com\/blog\/wp-json\/wp\/v2\/posts\/499\/revisions\/512"}],"wp:attachment":[{"href":"https:\/\/www.outofwhatbox.com\/blog\/wp-json\/wp\/v2\/media?parent=499"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.outofwhatbox.com\/blog\/wp-json\/wp\/v2\/categories?post=499"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.outofwhatbox.com\/blog\/wp-json\/wp\/v2\/tags?post=499"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}