8. Source Code

Due to pygments, the source code is shown very beautifully in sphinx. It can be shown with emphasis, line numbers, etc. as shown below.

8.1. Inline Python

When the write with the following reStructuredText markup / syntax:

.. code-block:: python
   :emphasize-lines: 2,4

   def myEntryPoint(myParam):
        # validate myParam
        print ("Processing myParam")
        # log the output

The |rst| text written above is generated/rendered as shown below:


def myEntryPoint(myParam):
     # validate myParam
     print ("Processing myParam")
     # log the output

8.2. Inline C

When the write with the following reStructuredText markup / syntax:

.. code-block:: c
   :emphasize-lines: 3

   int myEntryPoint(int myParam) {
        int retVal;
        /* validate myParam */
        printf("Processing myParam");
        retVal = process_theParam(myParam);
        /* log the output */
        return retVal;
   }

The |rst| text written above is generated/rendered as shown below:


int myEntryPoint(int myParam) {
     int retVal;
     /* validate myParam */
     printf("Processing myParam");
     retVal = process_theParam(myParam);
     /* log the output */
     return retVal;
}

8.3. Include external Python Script

When the write with the following reStructuredText markup / syntax:

.. literalinclude:: source-code.sample.py.txt
    :language: python

The |rst| text written above is generated/rendered as shown below:


def myEntryPoint(myParam):
    # validate myParam
    print ("Processing myParam")
    # log the output

8.4. Include external C Code

When the write with the following reStructuredText markup / syntax:

.. literalinclude:: source-code.sample.c.txt
   :language: c
   :linenos:

The |rst| text written above is generated/rendered as shown below:


1int myEntryPoint(int myParam) {
2    int retVal;
3    /* validate myParam */
4    printf("Processing myParam");
5    retVal = process_theParam(myParam);
6    /* log the output */
7    return retVal;
8}

See more at