Skip to content
This repository was archived by the owner on Oct 24, 2025. It is now read-only.

Commit de24b31

Browse files
committed
README preprocessor
1 parent 3146617 commit de24b31

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

setup.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import distutils.cmd
44
import os
55
import os.path
6+
import re
67
import shutil
78
import sys
89
import tempfile
@@ -71,9 +72,23 @@ def spawn(self, cmd):
7172
def readme():
7273
try:
7374
with open(os.path.join(os.path.dirname(__file__), 'README.rst')) as f:
74-
return f.read()
75+
readme = f.read()
7576
except IOError:
7677
pass
78+
return re.sub(
79+
r'''
80+
(?P<colon> : \n{2,})?
81+
\.\. [ ] code-block:: \s+ [^\n]+ \n
82+
[^ \t]* \n
83+
(?P<block>
84+
(?: (?: (?: \t | [ ]{3}) [^\n]* | [ \t]* ) \n)+
85+
)
86+
''',
87+
lambda m: (':' + m.group('colon') if m.group('colon') else '') +
88+
'\n'.join(' ' + l for l in m.group('block').splitlines()) +
89+
'\n\n',
90+
readme, 0, re.VERBOSE
91+
)
7792

7893

7994
class upload_doc(distutils.cmd.Command):

0 commit comments

Comments
 (0)