blob: 8ac56ed31f8bb8969e4aa52c0f6f062f77760240 (
plain)
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
|
'''
markup / media -- conversion / coercion
'''
from peak.rules import abstract, when
class htmlstr(str):
pass
class uhtmlstr(unicode):
pass
@abstract()
def plain_text(s):
''' Returns the text passed as a markup free / plain text string. '''
@abstract()
def html_text(s):
''' Returns the text passed as an html marked-up text string. '''
@when(html_text, (str, unicode))
def txt2html(s):
return ''.join(['<p>', s, '</p>' ])
@when(html_text, (htmlstr, uhtmlstr))
def html2html(s):
return s
@when(plain_text, (str, unicode))
def txt2txt(s):
return s
@when(plain_text, (htmlstr, uhtmlstr))
def html2txt(s):
return re.sub(r'<[^>]*?>','',s)
|