mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
source_parsers should fill Parser.supported attribute to let Sphinx know supported formats
This commit is contained in:
parent
dc45877d3c
commit
bece0484e5
3
CHANGES
3
CHANGES
@ -7,6 +7,9 @@ Dependencies
|
||||
Incompatible changes
|
||||
--------------------
|
||||
|
||||
* Sphinx expects source parser modules to have supported file formats as
|
||||
``Parser.supported`` attribute
|
||||
|
||||
Deprecated
|
||||
----------
|
||||
|
||||
|
@ -11,12 +11,14 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import traceback
|
||||
import warnings
|
||||
|
||||
from pkg_resources import iter_entry_points
|
||||
from six import iteritems, itervalues
|
||||
|
||||
from sphinx.errors import ExtensionError, SphinxError, VersionRequirementError
|
||||
from sphinx.extension import Extension
|
||||
from sphinx.deprecation import RemovedInSphinx30Warning
|
||||
from sphinx.domains import ObjType
|
||||
from sphinx.domains.std import GenericObject, Target
|
||||
from sphinx.locale import __
|
||||
@ -201,6 +203,12 @@ class SphinxComponentRegistry(object):
|
||||
logger.debug('[app] adding search source_parser: %r, %r', suffix, parser)
|
||||
if suffix in self.source_parsers:
|
||||
raise ExtensionError(__('source_parser for %r is already registered') % suffix)
|
||||
|
||||
if len(parser.supported) == 0:
|
||||
warnings.warn('Old source_parser has been detected. Please fill Parser.supported '
|
||||
'attribute: %s' % parser.__name__,
|
||||
RemovedInSphinx30Warning)
|
||||
|
||||
self.source_parsers[suffix] = parser
|
||||
|
||||
def get_source_parser(self, filename):
|
||||
|
@ -4,6 +4,8 @@ from docutils.parsers import Parser
|
||||
|
||||
|
||||
class DummyMarkdownParser(Parser):
|
||||
supported = ('markdown',)
|
||||
|
||||
def parse(self, inputstring, document):
|
||||
document.rawsource = inputstring
|
||||
|
||||
|
@ -13,7 +13,6 @@ templates_path = ['_templates']
|
||||
|
||||
master_doc = 'contents'
|
||||
source_suffix = ['.txt', '.add', '.foo']
|
||||
source_parsers = {'.foo': 'parsermod.Parser'}
|
||||
|
||||
project = 'Sphinx <Tests>'
|
||||
copyright = '2010-2016, Georg Brandl & Team'
|
||||
@ -106,9 +105,12 @@ class ClassDirective(Directive):
|
||||
|
||||
|
||||
def setup(app):
|
||||
import parsermod
|
||||
|
||||
app.add_config_value('value_from_conf_py', 42, False)
|
||||
app.add_directive('funcdir', functional_directive, opt=lambda x: x)
|
||||
app.add_directive('clsdir', ClassDirective)
|
||||
app.add_object_type('userdesc', 'userdescrole', '%s (userdesc)',
|
||||
userdesc_parse, objname='user desc')
|
||||
app.add_javascript('file://moo.js')
|
||||
app.add_source_parser('.foo', parsermod.Parser)
|
||||
|
@ -3,6 +3,8 @@ from docutils import nodes
|
||||
|
||||
|
||||
class Parser(Parser):
|
||||
supported = ('foo',)
|
||||
|
||||
def parse(self, input, document):
|
||||
section = nodes.section(ids=['id1'])
|
||||
section += nodes.title('Generated section', 'Generated section')
|
||||
|
Loading…
Reference in New Issue
Block a user