From patchwork Wed Apr 21 09:11:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Conor Walsh X-Patchwork-Id: 91945 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 10252A0548; Wed, 21 Apr 2021 11:12:06 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8FB5E419EC; Wed, 21 Apr 2021 11:12:05 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mails.dpdk.org (Postfix) with ESMTP id 083BD419D3 for ; Wed, 21 Apr 2021 11:12:03 +0200 (CEST) IronPort-SDR: h/wBA8KDj7JVfQI+cqXkpkilza5kOzgKRzKpyo5lP1R3JwVGJPLyr5r6EAqwzpxSx0zIFO3jlG QSV3ToQhP0Kw== X-IronPort-AV: E=McAfee;i="6200,9189,9960"; a="195222731" X-IronPort-AV: E=Sophos;i="5.82,238,1613462400"; d="scan'208";a="195222731" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Apr 2021 02:12:03 -0700 IronPort-SDR: MzAH4ncdwX6pEpV+uzbxi+W4G+D7qZnbaMQ7Al9UW2GzrslCFZ2u2I5PmudhsqpUkh/5jEKn/t HYcLPdTcBPWg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,238,1613462400"; d="scan'208";a="423481714" Received: from silpixa00400466.ir.intel.com ([10.237.213.210]) by orsmga007.jf.intel.com with ESMTP; 21 Apr 2021 02:12:00 -0700 From: Conor Walsh To: john.mcnamara@intel.com, thomas@monjalon.net, david.marchand@redhat.com, ferruh.yigit@intel.com, bruce.richardson@intel.com, anatoly.burakov@intel.com Cc: dev@dpdk.org, Conor Walsh Date: Wed, 21 Apr 2021 09:11:46 +0000 Message-Id: <20210421091146.1384708-1-conor.walsh@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH] doc/contributing/documentation: add info about including code X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Currently the documentation describes how to add code snippets to the docs using code blocks. This can be problematic as the code snippets in the docs may fall out of sync with the actual code it is referencing within DPDK. This patch adds instructions to the contribution guide about how to include code in the docs using literalinclude which will dynamically get the code from source when the docs are generated. This will help to ensure that the code within the docs is up to date and not out of sync with the actual code. Signed-off-by: Conor Walsh Acked-by: John McNamara Acked-by: David Marchand --- doc/guides/contributing/documentation.rst | 45 +++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/doc/guides/contributing/documentation.rst b/doc/guides/contributing/documentation.rst index a4e6be6aca..d5dd119a9a 100644 --- a/doc/guides/contributing/documentation.rst +++ b/doc/guides/contributing/documentation.rst @@ -433,6 +433,51 @@ Code and Literal block sections return 0; } +* Code snippets can also be included directly from the code using the ``literalinclude`` block. + Using this block instead of a code block will ensure that the code snippets shown in the + documentation are always up to date with the code. + + The following will include a snippet from the skeleton sample app:: + + .. literalinclude:: ../../../examples/skeleton/basicfwd.c + :language: c + :start-after: Display the port MAC address. + :end-before: Enable RX in promiscuous mode for the Ethernet device. + :dedent: 1 + + This would be rendered as: + + .. literalinclude:: ../../../examples/skeleton/basicfwd.c + :language: c + :start-after: Display the port MAC address. + :end-before: Enable RX in promiscuous mode for the Ethernet device. + :dedent: 1 + + Specifying ``:language:`` will enable syntax highlighting for the specified language. + ``:dedent:`` is used in this example to remove 1 leading tab from each line of the snippet. + +* ``start-after`` and ``end-before`` can use any text within a given file, + however it may be difficult to find unique text within your code to mark the + start and end of your snippets. In these cases, it is recommended to include + explicit tags in your code to denote these locations for documentation purposes. + + This can be done as follows: + + .. code-block:: c + + /* #guide_doc: Example feature being documented. */ + ... + /* #guide_doc: End of example feature being documented. */ + + ``...`` could then be included in the docs using:: + + .. literalinclude:: ../../../examples/sample_app/main.c + :language: c + :start-after: #guide_doc: Example feature being documented. + :end-before: #guide_doc: End of example feature being documented. + +* More information about the ``literalinclude`` block can be found within the + `Sphinx Documentation `_. * The default encoding for a literal block using the simplified ``::`` directive is ``none``.