futureext.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # -*- coding: utf-8 -*-
  2. """
  3. Python-Future Documentation Extensions
  4. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5. Support for automatically documenting filters and tests.
  6. Based on the Jinja2 documentation extensions.
  7. :copyright: Copyright 2008 by Armin Ronacher.
  8. :license: BSD.
  9. """
  10. import collections
  11. import os
  12. import re
  13. import inspect
  14. from itertools import islice
  15. from types import BuiltinFunctionType
  16. from docutils import nodes
  17. from docutils.statemachine import ViewList
  18. from sphinx.ext.autodoc import prepare_docstring
  19. from sphinx.application import TemplateBridge
  20. from pygments.style import Style
  21. from pygments.token import Keyword, Name, Comment, String, Error, \
  22. Number, Operator, Generic
  23. def parse_rst(state, content_offset, doc):
  24. node = nodes.section()
  25. # hack around title style bookkeeping
  26. surrounding_title_styles = state.memo.title_styles
  27. surrounding_section_level = state.memo.section_level
  28. state.memo.title_styles = []
  29. state.memo.section_level = 0
  30. state.nested_parse(doc, content_offset, node, match_titles=1)
  31. state.memo.title_styles = surrounding_title_styles
  32. state.memo.section_level = surrounding_section_level
  33. return node.children
  34. class FutureStyle(Style):
  35. title = 'Future Style'
  36. default_style = ""
  37. styles = {
  38. Comment: 'italic #0B6A94', # was: #0066ff',
  39. Comment.Preproc: 'noitalic #B11414',
  40. Comment.Special: 'italic #505050',
  41. Keyword: 'bold #D15E27',
  42. Keyword.Type: '#D15E27',
  43. Operator.Word: 'bold #B80000',
  44. Name.Builtin: '#333333',
  45. Name.Function: '#333333',
  46. Name.Class: 'bold #333333',
  47. Name.Namespace: 'bold #333333',
  48. Name.Entity: 'bold #363636',
  49. Name.Attribute: '#686868',
  50. Name.Tag: 'bold #686868',
  51. Name.Decorator: '#686868',
  52. String: '#AA891C',
  53. Number: '#444444',
  54. Generic.Heading: 'bold #000080',
  55. Generic.Subheading: 'bold #800080',
  56. Generic.Deleted: '#aa0000',
  57. Generic.Inserted: '#00aa00',
  58. Generic.Error: '#aa0000',
  59. Generic.Emph: 'italic',
  60. Generic.Strong: 'bold',
  61. Generic.Prompt: '#555555',
  62. Generic.Output: '#888888',
  63. Generic.Traceback: '#aa0000',
  64. Error: '#F00 bg:#FAA'
  65. }
  66. def setup(app):
  67. pass
  68. # uncomment for inline toc. links are broken unfortunately
  69. ##app.connect('doctree-resolved', inject_toc)