| Tor Norbye | 3a2425a | 2013-11-04 10:16:08 -0800 | [diff] [blame] | 1 | import sys |
| 2 | from epydoc.markup import DocstringLinker |
| 3 | from epydoc.markup.epytext import parse_docstring, ParseError, _colorize |
| 4 | import epydoc.markup.epytext |
| 5 | |
| 6 | def _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 | |
| 13 | epydoc.markup.epytext._add_para = _add_para |
| 14 | |
| 15 | def is_fatal(): |
| 16 | return False |
| 17 | |
| 18 | ParseError.is_fatal = is_fatal |
| 19 | |
| 20 | try: |
| 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() |
| 43 | except: |
| 44 | exc_type, exc_value, exc_traceback = sys.exc_info() |
| 45 | sys.stderr.write("Error calculating docstring: " + str(exc_value)) |
| 46 | sys.exit(1) |