Code

Following this thread: http://www.nabble.com/Extension-parameters-td9064285.html...
[inkscape.git] / share / extensions / text_sentencecase.py
1 import chardataeffect, inkex, string
3 class C(chardataeffect.CharDataEffect):
5   sentence_start = True
6   was_punctuation = False
8   def process_chardata(self,text, line, par):
9     r = ""
10     #inkex.debug(text+str(line)+str(par))
11     for c in text:
12       if c == '.' or c == '!' or c == '?':
13         self.was_punctuation = True
14       elif ((c.isspace() or line == True) and self.was_punctuation) or par == True:
15         self.sentence_start = True
16         self.was_punctuation = False
17       elif c == '"' or c == ')':
18         pass
19       else:
20         self.was_punctuation = False
22       if not c.isspace():
23         line = False
24         par = False
26       if self.sentence_start and c.isalpha():
27         r = r + c.upper()
28         self.sentence_start = False
29       elif not self.sentence_start and c.isalpha():
30         r = r + c.lower()
31       else:
32         r = r + c
34     return r
36 c = C()
37 c.affect()