11
"""qmp_lexer is a Sphinx extension that provides a QMP lexer for code blocks."""
13
from pygments.lexer import RegexLexer, DelegatingLexer
14
from pygments.lexers.data import JsonLexer
15
from pygments import token
16
from sphinx import errors
18
class QMPExampleMarkersLexer(RegexLexer):
20
QMPExampleMarkersLexer lexes QMP example annotations.
21
This lexer adds support for directionality flow and elision indicators.
25
(r'-> ', token.Generic.Prompt),
26
(r'<- ', token.Generic.Prompt),
27
(r' ?\.{3} ?', token.Generic.Prompt),
31
class QMPExampleLexer(DelegatingLexer):
32
"""QMPExampleLexer lexes annotated QMP examples."""
33
def __init__(self, **options):
34
super(QMPExampleLexer, self).__init__(JsonLexer, QMPExampleMarkersLexer,
35
token.Error, **options)
38
"""For use by the Sphinx extensions API."""
40
sphinx.require_sphinx('2.1')
41
sphinx.add_lexer('QMP', QMPExampleLexer)
42
except errors.VersionRequirementError:
43
sphinx.add_lexer('QMP', QMPExampleLexer())
46
parallel_read_safe = True,
47
parallel_write_safe = True