@@ -9,34 +9,34 @@ class AtWikiStripper(object):
99 COMMENT = re .compile (r'^//' )
1010
1111 # Inline annotation: `&color(#999999){text}`, `&nicovideo(url)`
12- INLINE_ANN = re .compile (r'&[a-z_]+\(([^()]*?)\)({([^{}]+?)})?' ), r'\3'
12+ INLINE_ANN = re .compile (r'&[a-z_]+\(([^()]*?)\)({([^{}]+?)})?' ), 3
1313
1414 # Inline links: `[[page]]`, `[[alias>URL]]`
15- INLINE_LINK = re .compile (r'\[\[(.+?)((>|>>)(.+?))?\]\]' ), r'\1'
15+ INLINE_LINK = re .compile (r'\[\[(.+?)((>|>>)(.+?))?\]\]' ), 1
1616
1717 # Inline italic: `'''text'''`
18- INLINE_ITALIC = re .compile (r'\'\'\'(.+?)\'\'\'' ), r'\1'
18+ INLINE_ITALIC = re .compile (r'\'\'\'(.+?)\'\'\'' ), 1
1919
2020 # Inline bold: `''text''`
21- INLINE_BOLD = re .compile (r'\'\'(.+?)\'\'' ), r'\1'
21+ INLINE_BOLD = re .compile (r'\'\'(.+?)\'\'' ), 1
2222
2323 # Inline del: `%%text%%`
24- INLINE_DEL = re .compile (r'%%(.+?)%%' ), r'\1'
24+ INLINE_DEL = re .compile (r'%%(.+?)%%' ), 1
2525
2626 # Line annotation: `#right(){text}`, `#comment()`, `#region`
27- LINE_ANN = re .compile (r'^#[a-z_]+(\(([^()]*?)\)({([^{}]+?)})?)?\s*$' ), r'\4'
27+ LINE_ANN = re .compile (r'^#[a-z_]+(\(([^()]*?)\)({([^{}]+?)})?)?\s*$' ), 4
2828
2929 # Line horizontal line: `----`
30- LINE_HR = re .compile (r'^----\s*()$' ), r'\1'
30+ LINE_HR = re .compile (r'^----\s*()$' ), 1
3131
3232 # Line item list and heading: `+foo`, `-foo`, `*foo`
33- LINE_ITEMLIST = re .compile (r'^(\*+|\++|-+)(.+)$' ), r'\2'
33+ LINE_ITEMLIST = re .compile (r'^(\*+|\++|-+)(.+)$' ), 2
3434
3535 # Line quote: `>text`
36- LINE_QUOTE = re .compile (r'^>+(.+)$' ), r'\1'
36+ LINE_QUOTE = re .compile (r'^>+(.+)$' ), 1
3737
3838 # Line formatted: ` text`
39- LINE_PRE = re .compile (r'^ (.+)$' ), r'\1'
39+ LINE_PRE = re .compile (r'^ (.+)$' ), 1
4040
4141 # Block annotation: `#exk(){{{` ... `}}}`
4242 BLOCK_BEGIN_ANN = re .compile (r'^#[a-z_]+\(([^{}()]*?)\)({+)\s*$' )
@@ -45,15 +45,17 @@ class AtWikiStripper(object):
4545 def __init__ (self , source ):
4646 self ._source = source
4747
48- def _inline_strip (self , line , pattern , repl ):
48+ def _inline_strip (self , line , pattern , group ):
4949 while True :
5050 prev = line
51- line = pattern .sub (repl , line )
51+ # Note: prior to Python 3.5, use of backreference of nonmatching group
52+ # in replacement string raises exception.
53+ line = pattern .sub (lambda m : m .group (group ), line )
5254 if prev == line : return line
5355
54- def _line_process (self , buf , line , pattern , repl ):
56+ def _line_process (self , buf , line , pattern , group ):
5557 prev = line
56- line = pattern .sub (repl , line )
58+ line = pattern .sub (lambda m : m . group ( group ) , line )
5759 if prev == line : return False
5860 buf .append (line )
5961 return True
0 commit comments