~vovkkk/uberwriter/uberwriter_inline_preview

« back to all changes in this revision

Viewing changes to uberwriter/MarkupBuffer.py

  • Committer: Wolf Vollprecht
  • Date: 2012-09-01 04:12:12 UTC
  • Revision ID: w.vollprecht@googlemail.com-20120901041212-vznateezd3f2073e
renewed translation, ongoing changes for popup menu preview and shortcuts

Show diffs side-by-side

added added

removed removed

Lines of Context:
101
101
        self.table_env = self.TextBuffer.create_tag('table_env')
102
102
        self.table_env.set_property('wrap-mode', Gtk.WrapMode.NONE)
103
103
 
104
 
 
105
 
    # *asdasd* // _asdasd asd asd_ 
106
 
    ITALIC = re.compile(r"\*\w(.+?)\*| _\w(.+?)_ ", re.UNICODE)
107
 
    
108
 
    # **as das** // __asdasdasd asd ad a__
109
 
    STRONG = re.compile(r"\*{2}\w(.+?)\*{2}| [_]{2}\w(.+?)[_]{2} ", re.UNICODE)
110
 
    
111
 
    ITALICEMPH = re.compile(r"\*{3}\w(.+?)\*{3}| [_]{3}\w(.+?)[_]{3} ")
112
 
    
113
 
 
114
 
    BLOCKQUOTE = re.compile(r"^([\>]+ )", re.MULTILINE)
115
 
    
116
 
    STRIKETHROUGH = re.compile(r"~~[^ `~\n].+?~~")
117
 
    
118
 
    LIST = re.compile(r"^[\-\*\+] ", re.MULTILINE)
119
 
    NUMERICLIST = re.compile(r"^((\d|[a-z]|\#)+[\.\)]) ", re.MULTILINE)
120
 
    INDENTEDLIST = re.compile(r"^(\t{1,6})((\d|[a-z]|\#)+[\.\)]|[\-\*\+]) ", re.MULTILINE)
121
 
 
122
 
    HEADINDICATOR = re.compile(r"^(#{1,6}) ", re.MULTILINE)
123
 
    HEADLINE = re.compile(r"^(#{1,6} [^\n]+)", re.MULTILINE)
124
 
 
125
 
    MATH = re.compile(r"\${1,2}[^` ](.+?)[^`\\ ]\${1,2}")
126
 
 
127
 
    HORIZONTALRULE = re.compile(r"(\n\n[\*\-]{3,}\n)")
128
 
 
129
 
    TABLE = re.compile(r"^:table:\n(.+?)\n:endtable:", re.DOTALL)
130
 
 
 
104
    regex  = {
 
105
        "ITALIC": re.compile(r"\*\w(.+?)\*| _\w(.+?)_ ", re.UNICODE),     # *asdasd* // _asdasd asd asd_ 
 
106
        "STRONG": re.compile(r"\*{2}\w(.+?)\*{2}| [_]{2}\w(.+?)[_]{2} ", re.UNICODE),     # **as das** // __asdasdasd asd ad a__
 
107
        "STRONGITALIC": re.compile(r"\*{3}\w(.+?)\*{3}| [_]{3}\w(.+?)[_]{3} "),
 
108
        "BLOCKQUOTE": re.compile(r"^([\>]+ )", re.MULTILINE),
 
109
        "STRIKETHROUGH": re.compile(r"~~[^ `~\n].+?~~"),
 
110
        "LIST": re.compile(r"^[\-\*\+] ", re.MULTILINE),
 
111
        "NUMERICLIST": re.compile(r"^((\d|[a-z]|\#)+[\.\)]) ", re.MULTILINE),
 
112
        "INDENTEDLIST": re.compile(r"^(\t{1,6})((\d|[a-z]|\#)+[\.\)]|[\-\*\+]) ", re.MULTILINE),
 
113
        "HEADINDICATOR": re.compile(r"^(#{1,6}) ", re.MULTILINE),
 
114
        "HEADLINE": re.compile(r"^(#{1,6} [^\n]+)", re.MULTILINE),
 
115
        "MATH": re.compile(r"\${1,2}[^` ](.+?)[^`\\ ]\${1,2}"),
 
116
        "HORIZONTALRULE": re.compile(r"(\n\n[\*\-]{3,}\n)"),
 
117
        "TABLE": re.compile(r"^:table:\n(.+?)\n:endtable:", re.DOTALL)
 
118
    }
131
119
 
132
120
    def markup_buffer(self, mode=0):
133
121
        buf = self.TextBuffer
154
142
 
155
143
        self.TextBuffer.remove_tag(self.italic, context_start, context_end)
156
144
 
157
 
        matches = re.finditer(self.ITALIC, text)
 
145
        matches = re.finditer(self.regex["ITALIC"], text)
158
146
        for match in matches: 
159
147
            startIter = buf.get_iter_at_offset(context_offset + match.start())
160
148
            endIter = buf.get_iter_at_offset(context_offset + match.end())
162
150
        
163
151
        self.TextBuffer.remove_tag(self.emph, context_start, context_end)
164
152
 
165
 
        matches = re.finditer(self.STRONG, text)
 
153
        matches = re.finditer(self.regex["STRONG"], text)
166
154
        for match in matches:
167
155
            startIter = buf.get_iter_at_offset(context_offset + match.start())
168
156
            endIter = buf.get_iter_at_offset(context_offset + match.end())
169
157
            self.TextBuffer.apply_tag(self.emph, startIter, endIter)
170
158
 
171
 
        matches = re.finditer(self.ITALICEMPH, text)
 
159
        matches = re.finditer(self.regex["STRONGITALIC"], text)
172
160
        for match in matches:
173
161
            startIter = buf.get_iter_at_offset(context_offset + match.start())
174
162
            endIter = buf.get_iter_at_offset(context_offset + match.end())
177
165
 
178
166
        self.TextBuffer.remove_tag(self.strikethrough, context_start, context_end)
179
167
 
180
 
        matches = re.finditer(self.STRIKETHROUGH, text)
 
168
        matches = re.finditer(self.regex["STRIKETHROUGH"], text)
181
169
        for match in matches:
182
170
            startIter = buf.get_iter_at_offset(context_offset + match.start())
183
171
            endIter = buf.get_iter_at_offset(context_offset + match.end())
185
173
 
186
174
        self.TextBuffer.remove_tag(self.green_text, context_start, context_end)
187
175
 
188
 
        matches = re.finditer(self.MATH, text) 
 
176
        matches = re.finditer(self.regex["MATH"], text) 
189
177
        for match in matches:
190
178
            startIter = buf.get_iter_at_offset(context_offset + match.start())
191
179
            endIter = buf.get_iter_at_offset(context_offset + match.end())
194
182
        for margin in self.rev_leftmargin:
195
183
            self.TextBuffer.remove_tag(margin, context_start, context_end)
196
184
 
197
 
        matches = re.finditer(self.LIST, text) 
 
185
        matches = re.finditer(self.regex["LIST"], text) 
198
186
        for match in matches:
199
187
            startIter = buf.get_iter_at_offset(context_offset + match.start())
200
188
            endIter = buf.get_iter_at_offset(context_offset + match.end())
201
189
            self.TextBuffer.apply_tag(self.rev_leftmargin[0], startIter, endIter)
202
190
   
203
 
        matches = re.finditer(self.NUMERICLIST, text)
 
191
        matches = re.finditer(self.regex["NUMERICLIST"], text)
204
192
        for match in matches:
205
193
            startIter = buf.get_iter_at_offset(context_offset + match.start())
206
194
            endIter = buf.get_iter_at_offset(context_offset + match.end())
209
197
                margin = self.rev_leftmargin[index]
210
198
                self.TextBuffer.apply_tag(margin, startIter, endIter)
211
199
 
212
 
        matches = re.finditer(self.BLOCKQUOTE, text) 
 
200
        matches = re.finditer(self.regex["BLOCKQUOTE"], text) 
213
201
        for match in matches:
214
202
            startIter = buf.get_iter_at_offset(context_offset + match.start())
215
203
            endIter = buf.get_iter_at_offset(context_offset + match.end())
220
208
        for leftindent in self.leftindent:
221
209
            self.TextBuffer.remove_tag(leftindent, context_start, context_end)
222
210
 
223
 
        matches = re.finditer(self.INDENTEDLIST, text)
 
211
        matches = re.finditer(self.regex["INDENTEDLIST"], text)
224
212
        for match in matches:
225
213
            startIter = buf.get_iter_at_offset(context_offset + match.start())
226
214
            endIter = buf.get_iter_at_offset(context_offset + match.end())
228
216
            if index < len(self.leftindent):
229
217
                self.TextBuffer.apply_tag(self.leftindent[index], startIter, endIter)
230
218
 
231
 
        matches = re.finditer(self.HEADINDICATOR, text) 
 
219
        matches = re.finditer(self.regex["HEADINDICATOR"], text) 
232
220
        for match in matches:
233
221
            startIter = buf.get_iter_at_offset(context_offset + match.start())
234
222
            endIter = buf.get_iter_at_offset(context_offset + match.end())
237
225
                margin = self.rev_leftmargin[index]
238
226
                self.TextBuffer.apply_tag(margin, startIter, endIter)
239
227
 
240
 
        matches = re.finditer(self.HORIZONTALRULE, text)
 
228
        matches = re.finditer(self.regex["HORIZONTALRULE"], text)
241
229
        rulecontext = context_start.copy()
242
230
        rulecontext.forward_lines(3)
243
231
        self.TextBuffer.remove_tag(self.centertext, rulecontext, context_end)
248
236
            endIter = buf.get_iter_at_offset(context_offset + match.end())
249
237
            self.TextBuffer.apply_tag(self.centertext, startIter, endIter)
250
238
 
251
 
        matches = re.finditer(self.HEADLINE, text) 
 
239
        matches = re.finditer(self.regex["HEADLINE"], text) 
252
240
        for match in matches:
253
241
            startIter = buf.get_iter_at_offset(context_offset + match.start())
254
242
            endIter = buf.get_iter_at_offset(context_offset + match.end())
255
243
            self.TextBuffer.apply_tag(self.emph, startIter, endIter)
256
244
        
257
245
 
258
 
        matches = re.finditer(self.TABLE, text) 
 
246
        matches = re.finditer(self.regex["TABLE"], text) 
259
247
        for match in matches:
260
248
            startIter = buf.get_iter_at_offset(context_offset + match.start())
261
249
            endIter = buf.get_iter_at_offset(context_offset + match.end())