mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Remove unused imports and clean up
This commit is contained in:
parent
1a5f00d83c
commit
464fee8523
@ -205,14 +205,14 @@ your start-up file, ``~/.emacs.d/init.el``.
|
|||||||
activate)
|
activate)
|
||||||
"Hack to make `Info-hide-note-references' buffer-local and
|
"Hack to make `Info-hide-note-references' buffer-local and
|
||||||
automatically set to `hide' iff it can be determined that this file
|
automatically set to `hide' iff it can be determined that this file
|
||||||
was created from a Texinfo file generated by Sphinx."
|
was created from a Texinfo file generated by Docutils or Sphinx."
|
||||||
(set (make-local-variable 'Info-hide-note-references)
|
(set (make-local-variable 'Info-hide-note-references)
|
||||||
(default-value 'Info-hide-note-references))
|
(default-value 'Info-hide-note-references))
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(save-restriction
|
(save-restriction
|
||||||
(widen) (goto-char (point-min))
|
(widen) (goto-char (point-min))
|
||||||
(when (re-search-forward
|
(when (re-search-forward
|
||||||
"^Generated by Sphinx"
|
"^Generated by \\(Sphinx\\|Docutils\\)"
|
||||||
(save-excursion (search-forward "" nil t)) t)
|
(save-excursion (search-forward "" nil t)) t)
|
||||||
(set (make-local-variable 'Info-hide-note-references)
|
(set (make-local-variable 'Info-hide-note-references)
|
||||||
'hide)))))
|
'hide)))))
|
||||||
|
@ -261,9 +261,8 @@ man_pages = [
|
|||||||
# (source start file, target name, title, author,
|
# (source start file, target name, title, author,
|
||||||
# dir menu entry, description, category)
|
# dir menu entry, description, category)
|
||||||
texinfo_documents = [
|
texinfo_documents = [
|
||||||
('%(master_str)s', '%(project_fn)s', u'%(project_doc)s',
|
('%(master_str)s', '%(project_fn)s', u'%(project_doc)s', u'%(author_str)s',
|
||||||
u'%(author_str)s', '%(project_fn)s',
|
'%(project_fn)s', 'One line description of project.', 'Miscellaneous'),
|
||||||
'One line description of project.', 'Miscellaneous'),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
# Documents to append as an appendix to all manuals.
|
# Documents to append as an appendix to all manuals.
|
||||||
|
@ -9,17 +9,11 @@
|
|||||||
:license: BSD, see LICENSE for details.
|
:license: BSD, see LICENSE for details.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import re
|
|
||||||
import os.path
|
|
||||||
|
|
||||||
import docutils
|
import docutils
|
||||||
import docutils.utils
|
from docutils import nodes, writers
|
||||||
|
|
||||||
from docutils import nodes, writers, transforms
|
|
||||||
from docutils.transforms import writer_aux
|
|
||||||
|
|
||||||
from sphinx import addnodes
|
from sphinx import addnodes
|
||||||
from sphinx.locale import admonitionlabels, versionlabels
|
from sphinx.locale import versionlabels
|
||||||
|
|
||||||
|
|
||||||
TEMPLATE = """\
|
TEMPLATE = """\
|
||||||
@ -48,7 +42,7 @@ Generated by Sphinx
|
|||||||
@c %%** end of user preamble
|
@c %%** end of user preamble
|
||||||
|
|
||||||
@ifnottex
|
@ifnottex
|
||||||
@node Top,,(DIR),(DIR)
|
@node Top
|
||||||
@top %(title)s
|
@top %(title)s
|
||||||
@end ifnottex
|
@end ifnottex
|
||||||
|
|
||||||
@ -134,6 +128,7 @@ class TexinfoWriter(writers.Writer):
|
|||||||
)
|
)
|
||||||
|
|
||||||
settings_defaults = {}
|
settings_defaults = {}
|
||||||
|
settings_default_overrides = {'docinfo_xform': 0}
|
||||||
|
|
||||||
output = None
|
output = None
|
||||||
|
|
||||||
@ -143,10 +138,6 @@ class TexinfoWriter(writers.Writer):
|
|||||||
writers.Writer.__init__(self)
|
writers.Writer.__init__(self)
|
||||||
self.builder = builder
|
self.builder = builder
|
||||||
|
|
||||||
def get_transforms(self):
|
|
||||||
trans = writers.Writer.get_transforms(self)
|
|
||||||
return trans + [writer_aux.Admonitions]
|
|
||||||
|
|
||||||
def translate(self):
|
def translate(self):
|
||||||
self.visitor = visitor = TexinfoTranslator(self.document, self.builder)
|
self.visitor = visitor = TexinfoTranslator(self.document, self.builder)
|
||||||
self.document.walkabout(visitor)
|
self.document.walkabout(visitor)
|
||||||
@ -214,6 +205,7 @@ class TexinfoTranslator(nodes.NodeVisitor):
|
|||||||
# if empty, the title is set to the first section title
|
# if empty, the title is set to the first section title
|
||||||
'title': settings.title,
|
'title': settings.title,
|
||||||
'author': escape_arg(settings.author),
|
'author': escape_arg(settings.author),
|
||||||
|
# if empty, use basename of input file
|
||||||
'filename': settings.texinfo_filename,
|
'filename': settings.texinfo_filename,
|
||||||
})
|
})
|
||||||
# Title
|
# Title
|
||||||
@ -222,6 +214,12 @@ class TexinfoTranslator(nodes.NodeVisitor):
|
|||||||
title = self.document.next_node(nodes.title)
|
title = self.document.next_node(nodes.title)
|
||||||
title = (title and title.astext()) or '<untitled>'
|
title = (title and title.astext()) or '<untitled>'
|
||||||
elements['title'] = escape_id(title) or '<untitled>'
|
elements['title'] = escape_id(title) or '<untitled>'
|
||||||
|
# Filename
|
||||||
|
if not elements['filename']:
|
||||||
|
elements['filename'] = self.document.get('source') or 'untitled'
|
||||||
|
if elements['filename'][-4:] in ('.txt', '.rst'):
|
||||||
|
elements['filename'] = elements['filename'][:-4]
|
||||||
|
elements['filename'] += '.info'
|
||||||
# Direntry
|
# Direntry
|
||||||
if settings.texinfo_dir_entry:
|
if settings.texinfo_dir_entry:
|
||||||
elements['direntry'] = ('@dircategory %s\n'
|
elements['direntry'] = ('@dircategory %s\n'
|
||||||
@ -272,7 +270,8 @@ class TexinfoTranslator(nodes.NodeVisitor):
|
|||||||
# Try to find a suitable "Top" node
|
# Try to find a suitable "Top" node
|
||||||
title = self.document.next_node(nodes.title)
|
title = self.document.next_node(nodes.title)
|
||||||
top = (title and title.parent) or self.document
|
top = (title and title.parent) or self.document
|
||||||
assert isinstance(top, (nodes.document, nodes.section))
|
if not isinstance(top, (nodes.document, nodes.section)):
|
||||||
|
top = self.document
|
||||||
if top is not self.document:
|
if top is not self.document:
|
||||||
entries = node_menus[top['node_name']]
|
entries = node_menus[top['node_name']]
|
||||||
entries += node_menus['Top'][1:]
|
entries += node_menus['Top'][1:]
|
||||||
@ -831,46 +830,6 @@ class TexinfoTranslator(nodes.NodeVisitor):
|
|||||||
def depart_field_body(self, node):
|
def depart_field_body(self, node):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
## Docinfo
|
|
||||||
|
|
||||||
def visit_docinfo(self, node):
|
|
||||||
pass
|
|
||||||
def depart_docinfo(self, node):
|
|
||||||
self.add_text('\n\n')
|
|
||||||
|
|
||||||
def visit_authors(self, node):
|
|
||||||
self.author_level = 0
|
|
||||||
self.add_text('@*Authors: ', fresh=1)
|
|
||||||
def depart_authors(self, node):
|
|
||||||
self.add_text('@*\n')
|
|
||||||
|
|
||||||
def visit_author(self, node):
|
|
||||||
if isinstance(node.parent, nodes.authors):
|
|
||||||
if self.author_level > 0:
|
|
||||||
self.add_text(', ')
|
|
||||||
self.author_level += 1
|
|
||||||
else:
|
|
||||||
self.add_text('@*Author: ', fresh=1)
|
|
||||||
def depart_author(self, node):
|
|
||||||
if not isinstance(node.parent, nodes.authors):
|
|
||||||
self.add_text('\n')
|
|
||||||
|
|
||||||
def _make_visit_docinfo_field(typ):
|
|
||||||
def visit_docinfo_field(self, node):
|
|
||||||
self.add_text('@*%s: ' % typ.capitalize(), fresh=1)
|
|
||||||
return visit_docinfo_field
|
|
||||||
|
|
||||||
visit_organization = _make_visit_docinfo_field('organization')
|
|
||||||
visit_address = _make_visit_docinfo_field('address')
|
|
||||||
visit_contact = _make_visit_docinfo_field('contact')
|
|
||||||
visit_version = _make_visit_docinfo_field('version')
|
|
||||||
visit_revision = _make_visit_docinfo_field('revision')
|
|
||||||
visit_status = _make_visit_docinfo_field('status')
|
|
||||||
visit_date = _make_visit_docinfo_field('date')
|
|
||||||
|
|
||||||
visit_copyright = visit_block_quote
|
|
||||||
depart_copyright = depart_block_quote
|
|
||||||
|
|
||||||
## Admonitions
|
## Admonitions
|
||||||
|
|
||||||
def visit_admonition(self, node):
|
def visit_admonition(self, node):
|
||||||
@ -883,30 +842,37 @@ class TexinfoTranslator(nodes.NodeVisitor):
|
|||||||
'@end cartouche\n\n')
|
'@end cartouche\n\n')
|
||||||
|
|
||||||
def _make_visit_admonition(typ):
|
def _make_visit_admonition(typ):
|
||||||
def visit_admonition(self, node):
|
def visit(self, node):
|
||||||
|
title = escape(typ)
|
||||||
self.add_text('\n@cartouche\n'
|
self.add_text('\n@cartouche\n'
|
||||||
'@quotation %s\n' % escape(typ))
|
'@quotation %s\n' % title)
|
||||||
return visit_admonition
|
return visit
|
||||||
|
|
||||||
visit_attention = _make_visit_admonition('Attention')
|
visit_attention = _make_visit_admonition('Attention')
|
||||||
visit_caution = _make_visit_admonition('Caution')
|
visit_caution = _make_visit_admonition('Caution')
|
||||||
visit_danger = _make_visit_admonition('Danger')
|
visit_danger = _make_visit_admonition('Danger')
|
||||||
visit_error = _make_visit_admonition('Error')
|
visit_error = _make_visit_admonition('Error')
|
||||||
visit_important = _make_visit_admonition('Important')
|
visit_important = _make_visit_admonition('Important')
|
||||||
visit_note = _make_visit_admonition('Note')
|
visit_note = _make_visit_admonition('Note')
|
||||||
visit_tip = _make_visit_admonition('Tip')
|
visit_tip = _make_visit_admonition('Tip')
|
||||||
visit_hint = _make_visit_admonition('Hint')
|
visit_hint = _make_visit_admonition('Hint')
|
||||||
visit_warning = _make_visit_admonition('Warning')
|
visit_warning = _make_visit_admonition('Warning')
|
||||||
|
|
||||||
depart_attention = depart_admonition
|
depart_attention = depart_admonition
|
||||||
depart_caution = depart_admonition
|
depart_caution = depart_admonition
|
||||||
depart_danger = depart_admonition
|
depart_danger = depart_admonition
|
||||||
depart_error = depart_admonition
|
depart_error = depart_admonition
|
||||||
depart_important = depart_admonition
|
depart_important = depart_admonition
|
||||||
depart_note = depart_admonition
|
depart_note = depart_admonition
|
||||||
depart_tip = depart_admonition
|
depart_tip = depart_admonition
|
||||||
depart_hint = depart_admonition
|
depart_hint = depart_admonition
|
||||||
depart_warning = depart_admonition
|
depart_warning = depart_admonition
|
||||||
|
|
||||||
|
## Misc
|
||||||
|
|
||||||
|
def visit_docinfo(self, node):
|
||||||
|
# No 'docinfo_xform'
|
||||||
|
raise nodes.SkipNode
|
||||||
|
|
||||||
def visit_topic(self, node):
|
def visit_topic(self, node):
|
||||||
# Ignore TOC's since we have to have a "menu" anyway
|
# Ignore TOC's since we have to have a "menu" anyway
|
||||||
@ -1002,25 +968,15 @@ class TexinfoTranslator(nodes.NodeVisitor):
|
|||||||
'---------- SYSTEM MESSAGE -----------\n')
|
'---------- SYSTEM MESSAGE -----------\n')
|
||||||
def depart_system_message(self, node):
|
def depart_system_message(self, node):
|
||||||
self.rstrip()
|
self.rstrip()
|
||||||
if node.get('backrefs'):
|
|
||||||
ref = escape_id(node['backrefs'][0])
|
|
||||||
self.add_xref(ref, ref, node)
|
|
||||||
self.add_text('\n------------------------------------\n'
|
self.add_text('\n------------------------------------\n'
|
||||||
'@end format\n')
|
'@end format\n')
|
||||||
|
|
||||||
def visit_comment(self, node):
|
def visit_comment(self, node):
|
||||||
for line in node.astext().splitlines():
|
for line in node.astext().splitlines():
|
||||||
# Prevents unintended inclusion of `Local Variables:'
|
|
||||||
# comment blocks used by editors. No harm in leaving it
|
|
||||||
# but it can interfere with the ones we add.
|
|
||||||
if line.strip().lower() == 'local variables:':
|
|
||||||
line = '--IGNORED-- Local Variables'
|
|
||||||
self.add_text('@c %s\n' % line, fresh=1)
|
self.add_text('@c %s\n' % line, fresh=1)
|
||||||
raise nodes.SkipNode
|
raise nodes.SkipNode
|
||||||
|
|
||||||
def visit_problematic(self, node):
|
def visit_problematic(self, node):
|
||||||
if node.get('ids'):
|
|
||||||
self.add_anchor(node['ids'][0], node)
|
|
||||||
self.add_text('>')
|
self.add_text('>')
|
||||||
def depart_problematic(self, node):
|
def depart_problematic(self, node):
|
||||||
self.add_text('<')
|
self.add_text('<')
|
||||||
|
Loading…
Reference in New Issue
Block a user