|
11 | 11 |
|
12 | 12 | import re |
13 | 13 |
|
| 14 | + |
14 | 15 | def yield_sphinx_only_markup(lines): |
15 | 16 | """ |
16 | 17 | :param file_inp: a `filename` or ``sys.stdin``? |
17 | 18 | :param file_out: a `filename` or ``sys.stdout`?` |
18 | 19 |
|
19 | 20 | """ |
20 | 21 | substs = [ |
21 | | - ## Selected Sphinx-only Roles. |
| 22 | + # Selected Sphinx-only Roles. |
22 | 23 | # |
23 | | - (r':abbr:`([^`]+)`', r'\1'), |
24 | | - (r':ref:`([^`]+)`', r'`\1`_'), |
25 | | - (r':term:`([^`]+)`', r'**\1**'), |
26 | | - (r':dfn:`([^`]+)`', r'**\1**'), |
27 | | - (r':(samp|guilabel|menuselection):`([^`]+)`', r'``\2``'), |
28 | | - |
29 | | - |
30 | | - ## Sphinx-only roles: |
| 24 | + (r":abbr:`([^`]+)`", r"\1"), |
| 25 | + (r":ref:`([^`]+)`", r"`\1`_"), |
| 26 | + (r":term:`([^`]+)`", r"**\1**"), |
| 27 | + (r":dfn:`([^`]+)`", r"**\1**"), |
| 28 | + (r":(samp|guilabel|menuselection):`([^`]+)`", r"``\2``"), |
| 29 | + # Sphinx-only roles: |
31 | 30 | # :foo:`bar` --> foo(``bar``) |
32 | 31 | # :a:foo:`bar` XXX afoo(``bar``) |
33 | 32 | # |
34 | | - #(r'(:(\w+))?:(\w+):`([^`]*)`', r'\2\3(``\4``)'), |
35 | | - (r':(\w+):`([^`]*)`', r'\1(``\2``)'), |
36 | | - |
37 | | - |
38 | | - ## Sphinx-only Directives. |
| 33 | + # (r'(:(\w+))?:(\w+):`([^`]*)`', r'\2\3(``\4``)'), |
| 34 | + (r":(\w+):`([^`]*)`", r"\1(``\2``)"), |
| 35 | + # Sphinx-only Directives. |
39 | 36 | # |
40 | | - (r'\.\. doctest', r'code-block'), |
41 | | - (r'\.\. plot::', r'.. '), |
42 | | - (r'\.\. seealso', r'info'), |
43 | | - (r'\.\. glossary', r'rubric'), |
44 | | - (r'\.\. figure::', r'.. '), |
45 | | - |
46 | | - |
47 | | - ## Other |
| 37 | + (r"\.\. doctest", r"code-block"), |
| 38 | + (r"\.\. plot::", r".. "), |
| 39 | + (r"\.\. seealso", r"info"), |
| 40 | + (r"\.\. glossary", r"rubric"), |
| 41 | + (r"\.\. figure::", r".. "), |
| 42 | + # Other |
48 | 43 | # |
49 | | - (r'\|version\|', r'x.x.x'), |
| 44 | + (r"\|version\|", r"x.x.x"), |
50 | 45 | ] |
51 | 46 |
|
52 | | - regex_subs = [ (re.compile(regex, re.IGNORECASE), sub) for (regex, sub) in substs ] |
| 47 | + regex_subs = [(re.compile(regex, re.IGNORECASE), sub) for (regex, sub) in substs] |
53 | 48 |
|
54 | 49 | def clean_line(line): |
55 | 50 | try: |
56 | 51 | for (regex, sub) in regex_subs: |
57 | 52 | line = regex.sub(sub, line) |
58 | 53 | except Exception as ex: |
59 | | - print("ERROR: %s, (line(%s)"%(regex, sub)) |
| 54 | + print("ERROR: %s, (line(%s)" % (regex, sub)) |
60 | 55 | raise ex |
61 | 56 |
|
62 | 57 | return line |
|
0 commit comments