egv / zapys-maemo

maemo fork of zapys lj client

This URL has Read+Write access

zapys-maemo / replacements.py
100644 33 lines (26 sloc) 1.061 kb
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
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
 
import re
 
lj_username = '[a-zA-Z0-9_]+'
url_regexp = r'(\s|^)(https?:\/\/)([^\s\"\<\>]+)(\s|$)'
 
# replaced on the fly
inline = [
('(\s+|^)"([^"]+?)"(\s+|$|\.|\,)', r"\1«\2»\3"), # russian quotes
#('(\s+|^)"([^"]+?)"(\s+|$|\.|\,)', r"\1“\2”\3"), # english quotes
 
(u"\((tm|тм|TM|ТМ)\)", "™"), # ™
(u"\([cсCС]\)", "©"), # ©
(u"\([rRрР]\)", "®"), # ®
('(\s+|^)-(\s+)', r"\1—\2"), # m-dash
('(\s+)(\d+)-(\d+)(\s+)', r"\1\2–\3\4"), # n-dash
('\.\.\.', "…"), # …
('(\s+|^)1/2(\s+|$)', r"\1½\2"), # ½
('(\s+|^)1/4(\s+|$)', r"\1¼\2"), # ¼
(u'([а-яА-я])\*([а-яА-я])', r"\1’\2") # ukrainian apostrope
]
 
publish = [
(url_regexp, r'\1<a href="\2\3">\3</a>\4'), # clickable urls
('LJ:('+lj_username+')', r'<lj user="\1"/>'), # LJ:username to <lj user="">
('([^\!]|^)-{2}([^-]+?)-{2}', r'\1<s>\2</s>') # --text-- to <s>text</s>
]
 
inline = [(re.compile(search), repl) for (search, repl) in inline]
publish = [(re.compile(search), repl) for (search, repl) in publish]