210 inStyleSpan = True |
210 inStyleSpan = True |
211 |
211 |
212 column = 0 |
212 column = 0 |
213 pos = 0 |
213 pos = 0 |
214 utf8 = self.editor.isUtf8() |
214 utf8 = self.editor.isUtf8() |
215 utf8Ch = "" |
215 utf8Ch = b"" |
216 utf8Len = 0 |
216 utf8Len = 0 |
217 |
217 |
218 while pos < lengthDoc: |
218 while pos < lengthDoc: |
219 ch = self.editor.rawCharAt(pos) |
219 ch = self.editor.byteAt(pos) |
220 style = self.editor.styleAt(pos) |
220 style = self.editor.styleAt(pos) |
221 if style != styleCurrent: |
221 if style != styleCurrent: |
222 if inStyleSpan: |
222 if inStyleSpan: |
223 f.write('''</span>''') |
223 f.write('''</span>''') |
224 inStyleSpan = False |
224 inStyleSpan = False |
225 if ch not in ['\r', '\n']: # no need of a span for the EOL |
225 if ch not in [b'\r', b'\n']: # no need of a span for the EOL |
226 if styleIsUsed[style]: |
226 if styleIsUsed[style]: |
227 f.write('''<span class="S%d">''' % style) |
227 f.write('''<span class="S%d">''' % style) |
228 inStyleSpan = True |
228 inStyleSpan = True |
229 styleCurrent = style |
229 styleCurrent = style |
230 |
230 |
231 if ch == ' ': |
231 if ch == b' ': |
232 if wysiwyg: |
232 if wysiwyg: |
233 prevCh = '' |
233 prevCh = b'' |
234 if column == 0: |
234 if column == 0: |
235 # at start of line, must put a |
235 # at start of line, must put a |
236 # because regular space will be collapsed |
236 # because regular space will be collapsed |
237 prevCh = ' ' |
237 prevCh = b' ' |
238 while pos < lengthDoc and self.editor.rawCharAt(pos) == ' ': |
238 while pos < lengthDoc and self.editor.byteAt(pos) == b' ': |
239 if prevCh != ' ': |
239 if prevCh != b' ': |
240 f.write(' ') |
240 f.write(' ') |
241 else: |
241 else: |
242 f.write(''' ''') |
242 f.write(''' ''') |
243 prevCh = self.editor.rawCharAt(pos) |
243 prevCh = self.editor.byteAt(pos) |
244 pos += 1 |
244 pos += 1 |
245 column += 1 |
245 column += 1 |
246 pos -= 1 |
246 pos -= 1 |
247 # the last incrementation will be done by the outer loop |
247 # the last incrementation will be done by the outer loop |
248 else: |
248 else: |
249 f.write(' ') |
249 f.write(' ') |
250 column += 1 |
250 column += 1 |
251 elif ch == '\t': |
251 elif ch == b'\t': |
252 ts = tabSize - (column % tabSize) |
252 ts = tabSize - (column % tabSize) |
253 if wysiwyg: |
253 if wysiwyg: |
254 f.write(''' ''' * ts) |
254 f.write(''' ''' * ts) |
255 column += ts |
255 column += ts |
256 else: |
256 else: |
257 if tabs: |
257 if tabs: |
258 f.write(ch) |
258 f.write('\t') |
259 column += 1 |
259 column += 1 |
260 else: |
260 else: |
261 f.write(' ' * ts) |
261 f.write(' ' * ts) |
262 column += ts |
262 column += ts |
263 elif ch in ['\r', '\n']: |
263 elif ch in [b'\r', b'\n']: |
264 if inStyleSpan: |
264 if inStyleSpan: |
265 f.write('''</span>''') |
265 f.write('''</span>''') |
266 inStyleSpan = False |
266 inStyleSpan = False |
267 if inFoldSpan: |
267 if inFoldSpan: |
268 f.write('''</span>''') |
268 f.write('''</span>''') |
269 inFoldSpan = False |
269 inFoldSpan = False |
270 if ch == '\r' and self.editor.rawCharAt(pos + 1) == '\n': |
270 if ch == b'\r' and self.editor.byteAt(pos + 1) == b'\n': |
271 pos += 1 # CR+LF line ending, skip the "extra" EOL char |
271 pos += 1 # CR+LF line ending, skip the "extra" EOL char |
272 column = 0 |
272 column = 0 |
273 if wysiwyg: |
273 if wysiwyg: |
274 f.write('''<br />''') |
274 f.write('''<br />''') |
275 |
275 |
297 level = newLevel |
297 level = newLevel |
298 else: |
298 else: |
299 f.write('\n') |
299 f.write('\n') |
300 |
300 |
301 if styleIsUsed[styleCurrent] and \ |
301 if styleIsUsed[styleCurrent] and \ |
302 self.editor.rawCharAt(pos + 1) not in ['\r', '\n']: |
302 self.editor.byteAt(pos + 1) not in [b'\r', b'\n']: |
303 # We know it's the correct next style, |
303 # We know it's the correct next style, |
304 # but no (empty) span for an empty line |
304 # but no (empty) span for an empty line |
305 f.write('''<span class="S%0d">''' % styleCurrent) |
305 f.write('''<span class="S%0d">''' % styleCurrent) |
306 inStyleSpan = True |
306 inStyleSpan = True |
307 else: |
307 else: |
308 if ch == '<': |
308 if ch == b'<': |
309 f.write('''<''') |
309 f.write('''<''') |
310 elif ch == '>': |
310 elif ch == b'>': |
311 f.write('''>''') |
311 f.write('''>''') |
312 elif ch == '&': |
312 elif ch == b'&': |
313 f.write('''&''') |
313 f.write('''&''') |
314 else: |
314 else: |
315 if ord(ch) > 127 and utf8: |
315 if ord(ch) > 127 and utf8: |
316 utf8Ch += ch |
316 utf8Ch += ch |
317 if utf8Len == 0: |
317 if utf8Len == 0: |
318 if (ord(utf8Ch[0]) & 0xF0) == 0xF0: |
318 if (utf8Ch[0] & 0xF0) == 0xF0: |
319 utf8Len = 4 |
319 utf8Len = 4 |
320 elif (ord(utf8Ch[0]) & 0xE0) == 0xE0: |
320 elif (utf8Ch[0] & 0xE0) == 0xE0: |
321 utf8Len = 3 |
321 utf8Len = 3 |
322 elif (ord(utf8Ch[0]) & 0xC0) == 0xC0: |
322 elif (utf8Ch[0] & 0xC0) == 0xC0: |
323 utf8Len = 2 |
323 utf8Len = 2 |
324 column -= 1 # will be incremented again later |
324 column -= 1 # will be incremented again later |
325 elif len(utf8Ch) == utf8Len: |
325 elif len(utf8Ch) == utf8Len: |
326 ch = utf8Ch.decode('utf8') |
326 ch = utf8Ch.decode('utf8') |
327 f.write(Utilities.html_encode(ch)) |
327 f.write(Utilities.html_encode(ch)) |
328 utf8Ch = "" |
328 utf8Ch = b"" |
329 utf8Len = 0 |
329 utf8Len = 0 |
330 else: |
330 else: |
331 column -= 1 # will be incremented again later |
331 column -= 1 # will be incremented again later |
332 else: |
332 else: |
333 f.write(ch) |
333 f.write(ch.decode()) |
334 column += 1 |
334 column += 1 |
335 |
335 |
336 pos += 1 |
336 pos += 1 |
337 |
337 |
338 if inStyleSpan: |
338 if inStyleSpan: |