|
13 | 13 |
|
14 | 14 | import sys |
15 | 15 | from datetime import date |
| 16 | +from sphinx.highlighting import lexers |
16 | 17 |
|
17 | 18 | # If extensions (or modules to document with autodoc) are in another directory, |
18 | 19 | # add these directories to sys.path here. If the directory is relative to the |
|
263 | 264 | # Enable this if you want TODOs to show up in the generated documentation. |
264 | 265 | todo_include_todos = True |
265 | 266 |
|
266 | | -# |
267 | | -# Monkeypatch pygments so it will know about the Swift lexers |
268 | | -# |
| 267 | +# -- Patch pygments so it will know about the Swift lexers --------------- |
269 | 268 |
|
270 | 269 | # Pull in the Swift lexers |
271 | 270 | from os.path import abspath, dirname, join as join_paths # noqa (E402) |
|
277 | 276 |
|
278 | 277 | sys.path.pop(0) |
279 | 278 |
|
280 | | -# Monkeypatch pygments.lexers.get_lexer_by_name to return our lexers. The |
281 | | -# ordering required to allow for monkeypatching causes the warning |
282 | | -# "I100 Import statements are in the wrong order." when linting using |
283 | | -# flake8-import-order. "noqa" is used to suppress this warning. |
284 | | -from pygments.lexers import get_lexer_by_name as original_get_lexer_by_name # noqa (E402) |
285 | | - |
286 | | - |
287 | | -def swift_get_lexer_by_name(_alias, *args, **kw): |
288 | | - if _alias == 'swift': |
289 | | - return swift_pygments_lexers.SwiftLexer() |
290 | | - elif _alias == 'sil': |
291 | | - return swift_pygments_lexers.SILLexer() |
292 | | - elif _alias == 'swift-console': |
293 | | - return swift_pygments_lexers.SwiftConsoleLexer() |
294 | | - else: |
295 | | - return original_get_lexer_by_name(_alias, *args, **kw) |
296 | | - |
297 | | -import pygments.lexers # noqa (I100 Import statements are in the wrong order.) |
298 | | -pygments.lexers.get_lexer_by_name = swift_get_lexer_by_name |
| 279 | +lexers['swift'] = swift_pygments_lexers.SwiftLexer() |
| 280 | +lexers['sil'] = swift_pygments_lexers.SILLexer() |
| 281 | +lexers['swift-console'] = swift_pygments_lexers.SwiftConsoleLexer() |
0 commit comments