SR Linux Syntax Highlighting with Pygments
For a very long time, I wanted to make a syntax highlighter for the SR Linux command-line interface mainly because I belong to a cohort of readers who appreciate visual aids in lengthy CLI snippets. Give me a piece of code that is not syntax highlighted, and my reading speed will significantly drop.
And even though the Network OS CLI snippets do not contain code per-se, they have markers (such as a current command, IP addresses, up/down statuses, etc.) that when highlighted, contribute to the clarity of the provided snippet.
So during a lazy first Thursday of 2023 I finally made myself looking into it and created the srlinux-pygments
- a Pygments lexer to highlight SR Linux CLI snippets.
--{ * candidate shared default }--[ network-instance black ]--
A:leaf1# info static-routes
static-routes {
route 192.168.18.0/24 {
admin-state enable
metric 1
preference 5
next-hop-group static-ipv4-grp
}
route 2001:1::192:168:18:0/64 {
admin-state enable
metric 1
preference 6
next-hop-group static-ipv6-grp
}
}
--{ * candidate shared default }--[ network-instance black ]--
A:leaf1# info static-routes
static-routes {
route 192.168.18.0/24 {
admin-state enable
metric 1
preference 5
next-hop-group static-ipv4-grp
}
route 2001:1::192:168:18:0/64 {
admin-state enable
metric 1
preference 6
next-hop-group static-ipv6-grp
}
}
Jump under the cut to know how to create a custom syntax highlighter based on SR Linux CLI example and integrate it with mkdocs-material doc theme.