From: Kevin A. <al...@se...> - 2005-12-19 23:49:05
|
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: code, tt { font-family: Courier, monospace } A friend of mine suggested that you might simply change the CSS to: code, tt { text-indent: -1em; font-family: Courier, monospace } and then remove all the and wrap all the code in: <div style='padding:10px'> He said, "you are essentially negative indenting the first line but you have to move all of it over far enough so that it doesn't go off the page." I no longer have any HTML chops, but this seems like a hack. Surely there is a cleaner and simpler way we can adopt that other web sites, wikis, whatever are using for Python code so that it will look right and people will be able to copy and paste it? ka |
From: Alex T. <al...@tw...> - 2005-12-20 01:14:31
|
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 -- No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.1.371 / Virus Database: 267.14.1/206 - Release Date: 16/12/2005 |
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 |
From: Andy T. <an...@ha...> - 2005-12-22 10:36:36
|
Kevin Altis wrote: > 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 > On my Mac with the documentation displayed in Safari copying and pasting into both Vim and Aquamacs appears to be fine. Having said that I've got no objections to changing the code samples to use <pre> blocks instead of the "code" class. Any volunteers? Regards, Andy -- -------------------------------------------------------------------------------- From the desk of Andrew J Todd esq - http://www.halfcooked.com/ |
From: Alex T. <al...@tw...> - 2005-12-22 12:39:47
|
Andy Todd wrote: > > > On my Mac with the documentation displayed in Safari copying and > pasting into both Vim and Aquamacs appears to be fine. > > Having said that I've got no objections to changing the code samples > to use <pre> blocks instead of the "code" class. > > Any volunteers? > If someone (e.g. you or Kevin) who can verify the results does the first one and commits it into CVS, I'll be happy to go through and do all the others (may take me a few days - still have to do my Xmas shopping :-) -- Alex Tweedly http://www.tweedly.net -- No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.1.371 / Virus Database: 267.14.3/209 - Release Date: 21/12/2005 |