mirror of
https://github.com/dart-lang/sdk
synced 2024-11-05 18:22:09 +00:00
[runtime/docs] Add custom lexer for shell sessions in runtime wiki.
This was missing from the previous wiki related commit. TBR=aam@google.com Change-Id: Ib68ead3bab2841bb8e02cb93fd71bce7515ff335 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134285 Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
This commit is contained in:
parent
857b911f3b
commit
ab56c2f841
4 changed files with 76 additions and 2 deletions
|
@ -0,0 +1,5 @@
|
|||
#
|
||||
# Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
|
||||
# for details. All rights reserved. Use of this source code is governed by a
|
||||
# BSD-style license that can be found in the LICENSE file.
|
||||
#
|
|
@ -0,0 +1,49 @@
|
|||
#
|
||||
# Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
|
||||
# for details. All rights reserved. Use of this source code is governed by a
|
||||
# BSD-style license that can be found in the LICENSE file.
|
||||
#
|
||||
"""Simple lexer for shell sessions.
|
||||
|
||||
Highlights command lines (lines starting with $ prompt) and comments starting
|
||||
with #. For example:
|
||||
|
||||
# This is a comment
|
||||
$ this-is-a-command
|
||||
This is output of the command
|
||||
|
||||
$ this-is-a-multiline-command with-some-arguments \
|
||||
and more arguments \
|
||||
and more arguments
|
||||
And some output.
|
||||
|
||||
"""
|
||||
|
||||
from pygments.lexer import RegexLexer, words
|
||||
from pygments.token import Comment, Generic, Keyword
|
||||
|
||||
_comment_style = Comment
|
||||
# Note: there is a slight inversion of styles to make it easier to read.
|
||||
# We highlight output with Prompt style and command as a normal text.
|
||||
_output_style = Generic.Prompt
|
||||
_command_style = Generic.Text
|
||||
_prompt_style = Keyword
|
||||
|
||||
|
||||
class CustomShellSessionLexer(RegexLexer):
|
||||
name = 'CustomShellSession'
|
||||
aliases = ['custom-shell-session']
|
||||
filenames = ['*.log']
|
||||
tokens = {
|
||||
'root': [
|
||||
(r'#.*\n', _comment_style),
|
||||
(r'^\$', _prompt_style, 'command'),
|
||||
(r'.', _output_style),
|
||||
],
|
||||
'command': [
|
||||
(r'\\\n', _command_style), # Continue in 'command' state.
|
||||
(r'$', _command_style, '#pop'), # End of line without escape.
|
||||
(r'.',
|
||||
_command_style), # Anything else continue in 'command' state.
|
||||
]
|
||||
}
|
15
runtime/tools/wiki/CustomShellSessionPygmentsLexer/setup.py
Normal file
15
runtime/tools/wiki/CustomShellSessionPygmentsLexer/setup.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
#
|
||||
# Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
|
||||
# for details. All rights reserved. Use of this source code is governed by a
|
||||
# BSD-style license that can be found in the LICENSE file.
|
||||
#
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
setup(
|
||||
name='custom-shell-session',
|
||||
packages=find_packages(),
|
||||
entry_points="""
|
||||
[pygments.lexers]
|
||||
custom-shell-session = custom_shell_session.lexer:CustomShellSessionLexer
|
||||
""",
|
||||
)
|
|
@ -32,6 +32,11 @@ the given C++ symbol.
|
|||
```console
|
||||
$ pip3 install coloredlogs jinja2 markdown aiohttp watchdog pymdown-extensions pygments
|
||||
```
|
||||
2. Install SASS compiler (make sure that SASS binary is in your path).
|
||||
3. Generate `xref.json` file following instructions in
|
||||
2. Install the custom pygments lexer we use for shell session examples:
|
||||
```
|
||||
$ cd runtime/tools/wiki/CustomShellSessionPygmentsLexer
|
||||
$ python3 setup.py develop
|
||||
```
|
||||
3. Install SASS compiler (make sure that SASS binary is in your path).
|
||||
4. Generate `xref.json` file following instructions in
|
||||
`xref_extractor/README.md`.
|
Loading…
Reference in a new issue