blob: 043c99d53bfa1e75216d7380e0e92e44c76943da (
about) (
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
37
38
39
40
41
42
43
44
45
46
47
48
|
"""
Org-mode inline markup parser.
"""
import re
def to_plain_text(org_text):
"""
Convert an org-mode text into a plain text.
>>> to_plain_text('there is a [[link]] in text')
'there is a link in text'
>>> to_plain_text('some [[link][more complex link]] here')
'some more complex link here'
>>> print(to_plain_text('''It can handle
... [[link][multi
... line
... link]].
... See also: [[info:org#Link%20format][info:org#Link format]]'''))
It can handle
multi
line
link.
See also: info:org#Link format
"""
return RE_LINK.sub(
lambda m: m.group('desc0') or m.group('desc1'),
org_text)
RE_LINK = re.compile(
r"""
(?:
\[ \[
(?P<desc0> [^\]]+)
\] \]
) |
(?:
\[ \[
(?P<link1> [^\]]+)
\] \[
(?P<desc1> [^\]]+)
\] \]
)
""",
re.VERBOSE)
|