From: Kevin A. <al...@se...> - 2005-12-20 06:55:54
|
On Dec 19, 2005, at 5:14 PM, Alex Tweedly wrote: > Kevin Altis wrote: > >> I'm sending this message to the general list rather than the >> pythoncard-devel list in hopes that some HTML/CSS expert will have a >> suggestion for how we can clean up our Python example code in the >> documentation so it can be copied and pasted. >> >> ka >> >> --- >> >> It was pointed out to me by Don Taylor that source examples in the >> docs can't be copied and pasted and run correctly. He specifically >> mentioned this code block in walkthrough2.html which you can see >> here: >> >> http://pythoncard.sourceforge.net/walkthrough2.html >> >> <p class="code"> def >> on_incrBtn_mouseClick(self, event):<br /> >> startValue = >> int(self.components.field1.text)<br /> >> endValue = startValue >> + 1<br /> >> >> self.components.field1.text >> = str(endValue)</p> >> >> The code looks fine displayed in the browser, but if someone tries to >> copy, paste, and then run it then the messes it up. Since >> this isn't an old-style <pre></pre> block you can't simply use >> spaces in the code to get the desired effect. The CSS we have >> defined for the style is: >> > The shouldn't mess it up - the browser should copy that as > spaces. > And indeed that's what it does for me : > > WinXP > copy from : Firefox 1.0.4 and IE 6.0 > paste into : Emacs, Notepad and tabcodeEditor > > > > -- > Alex Tweedly http://www.tweedly.net > Hmm, pasting the second line of the code into the tabCodeEditor and turning on show invisibles I could see that all was not well. Investigating in the shell I got: >>> self.currentDocument.text ' \xca\xca\xca\xca\xca\xca\xca\xcastartValue = int(self.components.field1.text)\n' >>> s = self.currentDocument.text >>> s[0] ' ' >>> ord(s[0]) 32 >>> ord(s[1]) 202 So there is a space at the beginning, followed by the eight non-breaking spaces. The copy/paste was done from Safari to the tabCodeEditor, so platform differences could be at fault here. Anyway, I did try just junking the <p class="code"> and non-breaking spaces and just using a <pre> block and that seemed to look fine and gave me exactly what I expected (i.e. just spaces). As long as <pre> is still valid I lean toward just falling back to that. Harold Marshall sent me a message that makes me think <pre> is still okay. Howard said: Two good howto's are: "CSS Tip: Adding Whitespace To Text" ( http://www.netmechanic.com/news/vol6/css_no9.htm )and "Making preformated <pre> text wrap in CSS3, Mozilla, Opera and IE" ( http://myy.helia.fi/~karte/pre-wrap-css3-mozilla-opera-ie.html ) which also addresses "code snippets". In our case we shouldn't be concerned about wrapping, adding color to the text, etc. BTW, have I mentioned lately how much I still love having a Python shell available in my Python editor with access to the guts of the application! ;-) ka |