]> git.proxmox.com Git - mirror_frr.git/commitdiff
doc: add frr.conf syntax highlighting
authorQuentin Young <qlyoung@cumulusnetworks.com>
Mon, 9 Apr 2018 20:18:05 +0000 (16:18 -0400)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Mon, 9 Apr 2018 21:30:53 +0000 (17:30 -0400)
Vincent Bernat has written a small Pygments lexer for IOS / Quagga
config files that works just as well on FRR stuff. Pulled that into our
docs with his blessing.

Also changed the background color on our code blocks away from that
kinda ugly green to gray, which looks way better with the syntax
highlighting changes that are about to happen in the next commit.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
doc/developer/_static/overrides.css
doc/developer/conf.py
doc/developer/workflow.rst
doc/extra/frrlexer.py [new file with mode: 0644]
doc/user/_static/overrides.css
doc/user/conf.py

index 1e0de66c55864032738587d0cbd8b8f5a535e477..0d871c961a898405fd9d11f1a6cdd8d713869cce 100644 (file)
@@ -2,3 +2,7 @@
 div.body {
     max-width: none;
 }
+
+pre {
+    background-color: #e2e2e2;
+}
index 9ae19918170dd11cab16ca48a6e0cd4963405ded..eecce4e908862a0b6277e4050e87d8b2b3f8e32d 100644 (file)
@@ -15,6 +15,8 @@
 import sys
 import os
 import re
+import pygments
+from sphinx.highlighting import lexers
 
 # If extensions (or modules to document with autodoc) are in another directory,
 # add these directories to sys.path here. If the directory is relative to the
@@ -341,3 +343,6 @@ def setup(app):
     app.add_object_type('clicmd', 'clicmd')
     # css overrides for HTML theme
     app.add_stylesheet('overrides.css')
+    # load FRR config lexer
+    frrlexer = pygments.lexers.load_lexer_from_file('../extra/frrlexer.py', lexername="FRRLexer")
+    lexers['frr'] = frrlexer
index 291a277c6b687746a688bfd24c383ddf0bf34724..f9613a18c2bcfcd8a7e9d635acc404ec52179ad0 100644 (file)
@@ -633,7 +633,7 @@ AddressSanitizer
    instrumentation and run through a series of tests to look for any results.
    Testing your own code with this tool before submission is encouraged. You
    can enable it by passing::
-   
+
       --enable-address-sanitizer
 
    to ``configure``.
@@ -643,7 +643,7 @@ ThreadSanitizer
    detecting data races. If you are working on or around multithreaded code,
    extensive testing with this instrumtation enabled is *highly* recommended.
    You can enable it by passing::
-   
+
       --enable-thread-sanitizer
 
    to ``configure``.
@@ -652,7 +652,7 @@ MemorySanitizer
    Similar to AddressSanitizer, this tool provides runtime instrumentation for
    detecting use of uninitialized heap memory. Testing your own code with this
    tool before submission is encouraged. You can enable it by passing::
-   
+
       --enable-memory-sanitizer
 
    to ``configure``.
@@ -740,27 +740,33 @@ FRR uses Sphinx+RST as its documentation system. The document you are currently
 reading was generated by Sphinx from RST source in
 :file:`doc/developer/workflow.rst`. The documentation is structured as follows:
 
-+-----------------------+--------------------------------------------------------------+
-| Directory             | Contents                                                     |
-+=======================+==============================================================+
-| :file:`doc/user`      | User documentation; configuration guides; protocol overviews |
-+-----------------------+--------------------------------------------------------------+
-| :file:`doc/developer` | Developer's documentation; API specs; datastructures;        |
-|                       | architecture overviews; project management procedure         |
-+-----------------------+--------------------------------------------------------------+
-| :file:`doc/manpages`  | Source for manpages                                          |
-+-----------------------+--------------------------------------------------------------+
-| :file:`doc/figures`   | Images and diagrams                                          |
-+-----------------------+--------------------------------------------------------------+
-
-Each of these directories, with the exception of :file:`doc/figures`, contains
-a Sphinx-generated Makefile and configuration script :file:`conf.py` used to
-set various document parameters. The makefile can be used for a variety of
-targets; invoke `make help` in any of these directories for a listing of
-available output formats. For convenience, there is a top-level
-:file:`Makefile.am` that has targets for PDF and HTML documentation for both
-developer and user documentation, respectively. That makefile is also
-responsible for building manual pages packed with distribution builds.
++-----------------------+-------------------------------------------+
+| Directory             | Contents                                  |
++=======================+===========================================+
+| :file:`doc/user`      | User documentation; configuration guides; |
+|                       | protocol overviews                        |
++-----------------------+-------------------------------------------+
+| :file:`doc/developer` | Developer's documentation; API specs;     |
+|                       | datastructures; architecture overviews;   |
+|                       | project management procedure              |
++-----------------------+-------------------------------------------+
+| :file:`doc/manpages`  | Source for manpages                       |
++-----------------------+-------------------------------------------+
+| :file:`doc/figures`   | Images and diagrams                       |
++-----------------------+-------------------------------------------+
+| :file:`doc/extra`     | Miscellaneous Sphinx extensions, scripts, |
+|                       | customizations, etc.                      |
++-----------------------+-------------------------------------------+
+
+Each of these directories, with the exception of :file:`doc/figures` and
+:file:`doc/extra`, contains a Sphinx-generated Makefile and configuration
+script :file:`conf.py` used to set various document parameters. The makefile
+can be used for a variety of targets; invoke `make help` in any of these
+directories for a listing of available output formats. For convenience, there
+is a top-level :file:`Makefile.am` that has targets for PDF and HTML
+documentation for both developer and user documentation, respectively. That
+makefile is also responsible for building manual pages packed with distribution
+builds.
 
 Indent and styling should follow existing conventions:
 
@@ -855,6 +861,15 @@ your implementation of a new BGP draft should go in the BGP chapter instead of
 being its own chapter. If you are adding a new protocol daemon, please create a
 new chapter.
 
+FRR Specific Markup
+-------------------
+
+FRR has some customizations applied to the Sphinx markup that go a long way
+towards making documentation easier to use, write and maintain.
+
+CLI Commands
+^^^^^^^^^^^^
+
 When documenting CLI please use a combination of the ``.. index::`` and
 ``.. clicmd::`` directives. For example, the command :clicmd:`show pony` would
 be documented as follows:
@@ -888,5 +903,28 @@ When documented this way, CLI commands can be cross referenced with the
 This is very helpful for users who want to quickly remind themselves what a
 particular command does.
 
+Configuration Snippets
+^^^^^^^^^^^^^^^^^^^^^^
+
+When putting blocks of example configuration please use the
+``.. code-block::`` directive and specify ``frr`` as the highlighting language,
+as in the following example. This will tell Sphinx to use a custom Pygments
+lexer to highlight FRR configuration syntax.
+
+.. code-block:: rest
+
+   .. code-block:: frr
+
+      !
+      ! Example configuration file.
+      !
+      log file /tmp/log.log
+      service integrated-vtysh-config
+      !
+      ip route 1.2.3.0/24 reject
+      ipv6 route de:ea:db:ee:ff::/64 reject
+      !
+
+
 .. _GitHub: https://github.com/frrouting/frr
 .. _GitHub issues: https://github.com/frrouting/frr/issues
diff --git a/doc/extra/frrlexer.py b/doc/extra/frrlexer.py
new file mode 100644 (file)
index 0000000..528bec9
--- /dev/null
@@ -0,0 +1,38 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2017 Vincent Bernat <bernat@luffy.cx>
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+from pygments.lexer import RegexLexer, bygroups
+from pygments.token import Text, Comment, Keyword
+from pygments.token import String, Number, Name
+
+
+class FRRLexer(RegexLexer):
+    name = "frr"
+    aliases = ["frr"]
+    tokens = {
+        'root': [
+            (r'^[ \t]*!.*?\n', Comment.Singleline),
+            (r'"(\\\\|\\"|[^"])*"', String.Double),
+            (r'[a-f0-9]*:[a-f0-9]*:[a-f0-9:]*(:\d+\.\d+\.\d+\.\d+)?(/\d+)?',
+             Number),  # IPv6
+            (r'\d+\.\d+\.\d+\.\d+(/\d+)?', Number),  # IPv4
+            (r'^([ \t]*)(no[ \t]+)?([-\w]+)',
+             bygroups(Text, Keyword, Name.Function)),
+            (r'[ \t]+', Text),
+            (r'\n', Text),
+            (r'\d+', Number),
+            (r'\S+', Text),
+        ],
+    }
index 1e0de66c55864032738587d0cbd8b8f5a535e477..0d871c961a898405fd9d11f1a6cdd8d713869cce 100644 (file)
@@ -2,3 +2,7 @@
 div.body {
     max-width: none;
 }
+
+pre {
+    background-color: #e2e2e2;
+}
index 7a77e492ce4bdef0b8284b9a1145a3b0c0da47a7..389af4c82f5e7baf671d2eea4acb5bed43d49234 100644 (file)
@@ -15,6 +15,8 @@
 import sys
 import os
 import re
+import pygments
+from sphinx.highlighting import lexers
 
 # If extensions (or modules to document with autodoc) are in another directory,
 # add these directories to sys.path here. If the directory is relative to the
@@ -341,3 +343,6 @@ def setup(app):
     app.add_object_type('clicmd', 'clicmd')
     # css overrides for HTML theme
     app.add_stylesheet('overrides.css')
+    # load FRR config lexer
+    frrlexer = pygments.lexers.load_lexer_from_file('../extra/frrlexer.py', lexername="FRRLexer")
+    lexers['frr'] = frrlexer