Changeset 1987:1667a5143bec
- Timestamp:
- 11/30/06 07:22:55 (6 years ago)
- Branch:
- default
- Children:
- 1988:ddf9c7f711c3, 2008:60f08a540628
- Location:
- sage/server/notebook
- Files:
-
- 5 edited
-
cell.py (modified) (5 diffs)
-
css.py (modified) (3 diffs)
-
notebook.py (modified) (2 diffs)
-
server.py (modified) (6 diffs)
-
worksheet.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sage/server/notebook/cell.py
r1985 r1987 112 112 s += pr + v + '\n' 113 113 else: 114 s += self.__in.strip() + '\n///\n'114 s += self.__in.strip() 115 115 116 116 if prompts: … … 127 127 out = self.output_text(ncols, html=False) 128 128 else: 129 out = self.output_text(ncols, html=False).split('\n')130 if len(out) > 0:131 if wiki_out:132 out = '///\n' + '\n'.join(out)133 else:134 out = '#out: ' + '\n'.join(out)135 else:136 out = ''137 129 out = self.output_text(ncols, html=False) 130 if wiki_out and len(out) > 0: 131 out = '///\n' + out 138 132 139 133 if not max_out is None and len(out) > max_out: … … 149 143 return s 150 144 151 def wiki_text(self, ncols=0, prompts=False, max_out=None):145 def edit_text(self, ncols=0, prompts=False, max_out=None): 152 146 s = self.plain_text(ncols,prompts,max_out,wiki_out=True) 153 #return '{{{#!sage[%s]\n'%self.id() + s + '\n}}}'154 #return '{{{[%s]\n'%self.id() + s + '\n}}}'155 147 return '{{{\n%s\n}}}'%s 156 148 … … 284 276 s = s[j+7:] 285 277 s = t 286 if not self.is_html() and len(s.strip()) > 0:287 s = '<pre class="shrunk">' + s.strip('\n') + '</pre>'288 289 278 # if there is an error in the output, 290 279 # specially format it. 291 280 s = format_exception(s, ncols) 281 if not self.is_html() and len(s.strip()) > 0: 282 s = '<pre class="shrunk">' + s.strip('\n') + '</pre>' 283 292 284 293 285 return s.strip('\n') … … 500 492 501 493 def format_exception(s, ncols): 502 if not ('Traceback (most recent call last):' in s): 494 m = 'Traceback (most recent call last):' 495 s = s.lstrip() 496 if s[:len(m)] != m: 503 497 return s 504 498 if ncols > 0: -
sage/server/notebook/css.py
r1986 r1987 1047 1047 margin:0px; 1048 1048 padding-left:0px; 1049 color:#0000 cc;1049 color:#0000aa; 1050 1050 } 1051 1051 … … 1054 1054 margin:0px; 1055 1055 padding:0px; 1056 color:#0000 cc;1056 color:#0000aa; 1057 1057 } 1058 1058 span.cell_output_nowrap { … … 1071 1071 margin:0px; 1072 1072 padding:0px; 1073 color:#0000 cc;1073 color:#0000aa; 1074 1074 } 1075 1075 span.cell_output_nowrap_hidden { -
sage/server/notebook/notebook.py
r1986 r1987 835 835 #body += ' <a class="plain_text" onClick="worksheet_text_window(\'%s\')">Text</a>'%worksheet.filename() + vbar 836 836 body += ' <a class="doctest_text" onClick="doctest_window(\'%s\')">Text</a>'%worksheet.filename() + vbar 837 body += ' <a class="plain_text" href="%s __edit__.html">Edit</a>'%worksheet.filename() + vbar837 body += ' <a class="plain_text" href="%s?edit">Edit</a>'%worksheet.filename() + vbar 838 838 #body += ' <a class="plain_text" onClick="show_wiki_window(\'%s\')">Wiki-form</a>'%worksheet.filename() + vbar 839 839 body += ' <a class="doctest_text" onClick="print_window(\'%s\')">Print</a>'%worksheet.filename() + vbar … … 935 935 body_html = '' 936 936 body_html += '<h1 class="edit">SAGE Notebook: Editing Worksheet "%s"</h1>\n'%worksheet.name() 937 body_html += '<form method="post" action="/%s/edit" enctype="multipart/form-data">\n'%worksheet.name() 937 body_html += "<b>Warnings:</b> You cannot undo after you save changes (yet). All graphics will be deleted when you save -- preserving images not yet implemented. No markup not in {{{}}}'s is preserved.<br><br>" 938 body_html += '<form method="post" action="%s?edit" enctype="multipart/form-data">\n'%worksheet.filename() 938 939 body_html += '<input type="submit" value="Save Changes" name="button_save"/>\n' 939 body_html += '<input type="submit" value="Preview" name="button_preview"/>\n'940 #body_html += '<input type="submit" value="Preview" name="button_preview"/>\n' 940 941 body_html += '<input type="submit" value="Cancel" name="button_cancel"/>\n' 941 942 body_html += '<textarea class="edit" id="cell_intext" rows="30" name="textfield">'+t+'</textarea>' -
sage/server/notebook/server.py
r1985 r1987 459 459 def edit_save(self, filename, newtext): 460 460 W = notebook.get_worksheet_with_filename(filename) 461 W.edit_save(newtext) 462 return self.show_page(worksheet_id=W.id()) 463 464 def edit_preview(self): 461 465 raise NotImplementedError 462 463 def edit_preview(self):464 print "edit_preview"465 466 466 def edit_cancel(self ):467 print "edit_ancel"468 467 def edit_cancel(self, filename): 468 W = notebook.get_worksheet_with_filename(filename) 469 return self.show_page(worksheet_id=W.id()) 469 470 470 471 … … 534 535 self.wfile.write(notebook.upload_window()) 535 536 536 def insert_wiki_cells(self):537 C = self.get_postvars()538 W = notebook.get_worksheet_with_id(int(C['worksheet_id'][0]))539 W.insert_wiki_cells(C['text'][0])540 response = C['eval'][0] + SEP541 response+= "%r"%W.cell_id_list() + SEP542 response+= SEP.join([c.html(div_wrap=False) for c in W[:-1]])543 self.wfile.write(response)537 ## def insert_wiki_cells(self): 538 ## C = self.get_postvars() 539 ## W = notebook.get_worksheet_with_id(int(C['worksheet_id'][0])) 540 ## W.insert_wiki_cells(C['text'][0]) 541 ## response = C['eval'][0] + SEP 542 ## response+= "%r"%W.cell_id_list() + SEP 543 ## response+= SEP.join([c.html(div_wrap=False) for c in W[:-1]]) 544 ## self.wfile.write(response) 544 545 545 546 def download_worksheet(self, filename): … … 590 591 elif worksheet_filename == '__license__': 591 592 self.license_window() 592 elif worksheet_filename[-8:] == '__edit__':593 self.edit_text(worksheet_filename[:-8],prompts=False)594 593 elif worksheet_filename[-7:] == '__doc__': 595 594 self.plain_text_worksheet(worksheet_filename[:-7], prompts=True) … … 603 602 self.html_worksheet(worksheet_filename, do_print=False) 604 603 return 605 604 606 605 elif path[-4:] == '.sws': 607 606 … … 703 702 i = self.path.rfind('?') 704 703 if i != -1: 705 if 'debug' in self.path[i:]:704 if self.path[i+1:i+6] == 'debug': 706 705 show_debug = True 706 elif self.path[i+1:i+5] == 'edit': 707 j = self.path.rfind('/') 708 worksheet_filename = self.path[j+1:i] 709 self.edit_text(worksheet_filename,prompts=False) 710 return 707 711 self.path = self.path[:i] 708 712 709 713 #verbose(self.path) 710 711 714 if self.path[-4:] in ['.eps', '.pdf', '.png', '.bmp', '.svg', '.tex', \ 712 715 '.dvi', '.log', '.css',\ … … 785 788 M = cgi.parse_multipart(self.rfile, post_dict); 786 789 787 if self.path[-5:] == '/edit' and self.path != '/edit': 788 # i.e., this "/edit" after a longer name, not a worksheet named /edit 789 filename = self.path[:-5].strip('/') 790 if self.path[-5:] == '?edit' and self.path != '?edit': 791 filename = self.path[1:-5] 790 792 if M.has_key('button_save'): 791 793 self.edit_save(filename, M['textfield'][0]) 794 elif M.has_key('button_cancel'): 795 self.edit_cancel(filename) 792 796 return 793 797 -
sage/server/notebook/worksheet.py
r1986 r1987 162 162 suitable for hand editing. 163 163 """ 164 s = '#'*80 + '\n' 165 s += '# Wiki form for worksheet: %s'%self.name() + '\n' 166 s += '#'*80+'\n\n' 164 #s = '#'*80 + '\n' 165 #s += '# Worksheet: %s'%self.name() + '\n' 166 #s += '#'*80+'\n\n' 167 s = ' == %s =='%self.name() + '\n\n' 167 168 for C in self.__cells: 168 t = C. wiki_text(prompts=prompts).strip()169 t = C.edit_text(prompts=prompts).strip() 169 170 if t != '': 170 171 s += '\n\n' + t 171 172 return s 172 173 173 def insert_wiki_cells(self,text):174 def edit_save(self,text): 174 175 text.replace('\r\n','\n') 175 lines = text.split('\n') 176 input = "" 177 output = "" 178 in_cell = False 179 in_output = False 180 old_first = self.__cells[0].id() 181 for line in lines: 182 if not in_cell: 183 if line[:3] == '{{{': 184 in_cell = True 185 elif line != '}}}': 186 if not in_output: 187 if line == '///': 188 in_output = True 189 else: 190 input += line+'\n' 191 else: 192 output += line+'\n' 193 else: 194 C = self.new_cell_before(old_first) 195 C.set_input_text(input) 196 C.set_output_text(output,output) 197 C.set_cell_output_type() 198 input = "" 199 output = "" 200 in_cell = False 201 in_output = False 176 # This is where we would save the last version in a history. 177 cells = [] 178 while True: 179 try: 180 input, output, graphics, i = extract_first_text_cell(text) 181 except EOFError: 182 break 183 text = text[i:] 184 C = self._new_cell() 185 C.set_input_text(input) 186 C.set_output_text(output, '') 187 cells.append(C) 188 self.__cells = cells 189 190 ## lines = text.split('\n') 191 ## input = "" 192 ## output = "" 193 ## in_cell = False 194 ## in_output = False 195 ## old_first = self.__cells[0].id() 196 ## for line in lines: 197 ## if not in_cell: 198 ## if line[:3] == '{{{': 199 ## in_cell = True 200 ## elif line != '}}}': 201 ## if not in_output: 202 ## if line == '///': 203 ## in_output = True 204 ## else: 205 ## input += line+'\n' 206 ## else: 207 ## output += line+'\n' 208 ## else: 209 ## C = self.new_cell_before(old_first) 210 ## C.set_input_text(input) 211 ## C.set_output_text(output,output) 212 ## C.set_cell_output_type() 213 ## input = "" 214 ## output = "" 215 ## in_cell = False 216 ## in_output = False 202 217 203 218 def input_text(self): … … 369 384 370 385 def _new_cell(self, id=None): 371 D = self.__notebook.defaults()372 386 if id is None: 373 387 id = self.__next_id … … 1229 1243 return s 1230 1244 1245 1246 1247 def extract_first_text_cell(text): 1248 """ 1249 INPUT: 1250 a block of wiki-like marked up text 1251 OUTPUT: 1252 input -- string, the input text 1253 output -- string, the output text 1254 graphics -- string, text that describes any embedded graphics 1255 end -- integer, first position after }}} in text. 1256 """ 1257 # Find the input block 1258 i = text.find('{{{') 1259 if i == -1: 1260 raise EOFError 1261 j = text.find('}}}') 1262 if j <= i: 1263 j = len(text) 1264 k = text.find('///') 1265 if k == -1 or k > j: 1266 input = text[i+3:j] 1267 output = '' 1268 graphics = '' 1269 else: 1270 input = text[i+3:k].strip() 1271 # Find the graphics block, if there is one. 1272 l = text[k+3:].find('///') 1273 if l != -1 and l+k+3 < j: 1274 graphics = text[l+k+3+3:j] 1275 else: 1276 graphics = '' 1277 l = j 1278 output = text[k+3:l].strip() 1279 return input, output, graphics, j+3 1280
Note: See TracChangeset
for help on using the changeset viewer.
