mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Sphinx.add_lexer() now takes a Lexer class instead of instance
This commit is contained in:
parent
5d8c25b605
commit
71842264b2
2
CHANGES
2
CHANGES
@ -13,6 +13,8 @@ Incompatible changes
|
||||
by non-ASCII characters
|
||||
* #4550: html: Centering tables by default using CSS
|
||||
* #6239: latex: xelatex and xeCJK are used for Chinese documents by default
|
||||
* ``Sphinx.add_lexer()`` now takes a Lexer class instead of instance. An
|
||||
instance of lexers are still supported until Sphinx-3.x.
|
||||
|
||||
Deprecated
|
||||
----------
|
||||
|
@ -20,6 +20,7 @@ from io import StringIO
|
||||
from os import path
|
||||
|
||||
from docutils.parsers.rst import Directive, roles
|
||||
from pygments.lexer import Lexer
|
||||
|
||||
import sphinx
|
||||
from sphinx import package_dir, locale
|
||||
@ -30,7 +31,7 @@ from sphinx.deprecation import (
|
||||
from sphinx.environment import BuildEnvironment
|
||||
from sphinx.errors import ApplicationError, ConfigError, VersionRequirementError
|
||||
from sphinx.events import EventManager
|
||||
from sphinx.highlighting import lexers
|
||||
from sphinx.highlighting import lexer_classes, lexers
|
||||
from sphinx.locale import __
|
||||
from sphinx.project import Project
|
||||
from sphinx.registry import SphinxComponentRegistry
|
||||
@ -51,7 +52,6 @@ if False:
|
||||
from docutils import nodes # NOQA
|
||||
from docutils.parsers import Parser # NOQA
|
||||
from docutils.transforms import Transform # NOQA
|
||||
from pygments.lexer import Lexer # NOQA
|
||||
from sphinx.builders import Builder # NOQA
|
||||
from sphinx.domains import Domain, Index # NOQA
|
||||
from sphinx.environment.collectors import EnvironmentCollector # NOQA
|
||||
@ -1035,16 +1035,24 @@ class Sphinx:
|
||||
self.registry.add_latex_package(packagename, options)
|
||||
|
||||
def add_lexer(self, alias, lexer):
|
||||
# type: (str, Lexer) -> None
|
||||
# type: (str, Union[Lexer, Type[Lexer]]) -> None
|
||||
"""Register a new lexer for source code.
|
||||
|
||||
Use *lexer*, which must be an instance of a Pygments lexer class, to
|
||||
highlight code blocks with the given language *alias*.
|
||||
Use *lexer* to highlight code blocks with the given language *alias*.
|
||||
|
||||
.. versionadded:: 0.6
|
||||
.. versionchanged:: 2.1
|
||||
Take a lexer class as an argument. An instance of lexers are
|
||||
still supported until Sphinx-3.x.
|
||||
"""
|
||||
logger.debug('[app] adding lexer: %r', (alias, lexer))
|
||||
lexers[alias] = lexer
|
||||
if isinstance(lexer, Lexer):
|
||||
warnings.warn('app.add_lexer() API changed; '
|
||||
'Please give lexer class instead instance',
|
||||
RemovedInSphinx40Warning)
|
||||
lexers[alias] = lexer
|
||||
else:
|
||||
lexer_classes[alias] = lexer
|
||||
|
||||
def add_autodocumenter(self, cls):
|
||||
# type: (Any) -> None
|
||||
|
Loading…
Reference in New Issue
Block a user