ThirdParty/Pygments/pygments/sphinxext.py

changeset 4697
c2e9bf425554
parent 4172
4f20dba37ab6
child 5713
6762afd9f963
equal deleted inserted replaced
4696:bf4d19a7cade 4697:c2e9bf425554
4 ~~~~~~~~~~~~~~~~~~ 4 ~~~~~~~~~~~~~~~~~~
5 5
6 Sphinx extension to generate automatic documentation of lexers, 6 Sphinx extension to generate automatic documentation of lexers,
7 formatters and filters. 7 formatters and filters.
8 8
9 :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS. 9 :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS.
10 :license: BSD, see LICENSE for details. 10 :license: BSD, see LICENSE for details.
11 """ 11 """
12 12
13 from __future__ import print_function 13 from __future__ import print_function
14 14
111 if isinstance(moddoc, bytes): 111 if isinstance(moddoc, bytes):
112 moddoc = moddoc.decode('utf8') 112 moddoc = moddoc.decode('utf8')
113 moduledocstrings[module] = moddoc 113 moduledocstrings[module] = moddoc
114 114
115 for module, lexers in sorted(modules.items(), key=lambda x: x[0]): 115 for module, lexers in sorted(modules.items(), key=lambda x: x[0]):
116 if moduledocstrings[module] is None:
117 raise Exception("Missing docstring for %s" % (module,))
116 heading = moduledocstrings[module].splitlines()[4].strip().rstrip('.') 118 heading = moduledocstrings[module].splitlines()[4].strip().rstrip('.')
117 out.append(MODULEDOC % (module, heading, '-'*len(heading))) 119 out.append(MODULEDOC % (module, heading, '-'*len(heading)))
118 for data in lexers: 120 for data in lexers:
119 out.append(LEXERDOC % data) 121 out.append(LEXERDOC % data)
120 122
131 cls = getattr(mod, classname) 133 cls = getattr(mod, classname)
132 docstring = cls.__doc__ 134 docstring = cls.__doc__
133 if isinstance(docstring, bytes): 135 if isinstance(docstring, bytes):
134 docstring = docstring.decode('utf8') 136 docstring = docstring.decode('utf8')
135 heading = cls.__name__ 137 heading = cls.__name__
136 out.append(FMTERDOC % (heading, ', '.join(data[1]) or 'None', 138 out.append(FMTERDOC % (heading, ', '.join(data[2]) or 'None',
137 ', '.join(data[2]).replace('*', '\\*') or 'None', 139 ', '.join(data[3]).replace('*', '\\*') or 'None',
138 docstring)) 140 docstring))
139 return ''.join(out) 141 return ''.join(out)
140 142
141 def document_filters(self): 143 def document_filters(self):
142 from pygments.filters import FILTERS 144 from pygments.filters import FILTERS

eric ide

mercurial