blob: 3d30e1ee3ba43762832e014d437f40962e2846ee [file] [log] [blame]
Tor Norbye3a2425a2013-11-04 10:16:08 -08001import sys
2from epydoc.markup import DocstringLinker
3from epydoc.markup.epytext import parse_docstring, ParseError, _colorize
4import epydoc.markup.epytext
5
6def _add_para(doc, para_token, stack, indent_stack, errors):
7 """Colorize the given paragraph, and add it to the DOM tree."""
8 para = _colorize(doc, para_token, errors)
9 if para_token.inline:
10 para.attribs['inline'] = True
11 stack[-1].children.append(para)
12
13epydoc.markup.epytext._add_para = _add_para
14
15def is_fatal():
16 return False
17
18ParseError.is_fatal = is_fatal
19
20try:
21 src = sys.stdin.read()
22 errors = []
23
24 class EmptyLinker(DocstringLinker):
25 def translate_indexterm(self, indexterm):
26 return ""
27
28 def translate_identifier_xref(self, identifier, label=None):
29 return identifier
30
31 docstring = parse_docstring(src, errors)
32 docstring, fields = docstring.split_fields()
33 html = docstring.to_html(EmptyLinker())
34
35 if errors and not html:
36 sys.stderr.write("Error parsing docstring:\n")
37 for error in errors:
38 sys.stderr.write(str(error) + "\n")
39 sys.exit(1)
40
41 sys.stdout.write(html)
42 sys.stdout.flush()
43except:
44 exc_type, exc_value, exc_traceback = sys.exc_info()
45 sys.stderr.write("Error calculating docstring: " + str(exc_value))
46 sys.exit(1)