File: ISO2HTML.py

package info (click to toggle)
glimmer 1.1.12-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 3,864 kB
  • ctags: 2,900
  • sloc: ansic: 31,674; sh: 6,687; python: 646; makefile: 510; sed: 93
file content (62 lines) | stat: -rw-r--r-- 3,298 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# iso_to_html.py
# (C) 2000 Pablo De Napoli
# This python script translates iso-8859-1 characters 
# to html characters
# Based on Bluefish Copyright (C) 2000 Olivier Sessink
#
#  This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU Library General Public License for more details.
#
#  You should have received a copy of the GNU Library General Public License
#   along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#

import glimmer

html_char_table = {34:""",	38:"&"   ,     60:"<",          62: ">",
	              160: " ",	161:"¡" ,    162: "¢",   163:"£",
		         164:"¤" , 165:"¥" ,     166:"¦", 167:"§",
		         168:"¨",      169:"©",     170:"ª",    171:"«",
		         172:"¬",       173: "­",      174:"®",     175:"¯",
		         176:"°",      177: "±", 178:"²",   179:"³",
		         180: "´",   181: "µ",   182:"¶",    183:"·",
			    184: "¸",    185: "¹",    186: "º",  187:"»",
		         188: "¼",  189: "½",  190:"¾", 191:"¿",
			    192:"À",  193:"Á",  194:"Â",  195:"Ã",
		         196: "Ä",    197:"Å",     198: "Æ",  199:"Ç",
		   	 200:"È",  201: "É",   202:"Ê", 203:"Ë",
		         204:"Ì",   205: "Í" ,    206: "Î" , 207:"Ï",
		         208:"Ð",      209: "Ñ",     210:"Ò" , 211:"Ó",
		         212:"Ô",    213: "Õ",     214:"Ö",     215:"×",
		         216: "Ø", 217:"Ù",    218:"Ú", 219:"Û",
		         220: "Ü",    221:"Ý",    222: "Þ", 223:"ß",
		         224: "à", 225:"á",    226:"â",  227:"ã",
		         228:"ä" ,    229:"å",       230: "æ", 231:"ç",
		         232:"è", 233: "é",    234: "ê", 235:"ë",
		         236:"ì",  237: "í",     238:"î",   239:"ï",
		         240:"ð",       241:"ñ" ,     242:"ò", 243:"ó",
                   244:"ô",    245:"õ",      246: "ö" ,  247:"÷",
		         248:"ø",  249: "ù",  250: "ú", 251:"û",
		         252:"ü",     253:"ý",   254:"þ",  255:"ÿ" }

def iso_to_html():
	import struct
	glimmer.move_to(0)
	end_of_text = 0
   glimmer.freeze()
	while not(end_of_text):
		c=glimmer.get_next_char()
		char_code=struct.unpack("B",c)[0]
		if html_char_table.has_key(char_code):
			glimmer.backward_delete(1)
			glimmer.insert(html_char_table[char_code])
		end_of_text =  glimmer.current_position() == glimmer.buffer_size()
   glimmer.thaw()