.. include:: /Includes.rst.txt .. _Codeblocks: ========== Codeblocks ========== .. contents:: This page :local: Basic examples ============== .. code-block:: shell ls -al Code-block with line numbers ============================ .. code-block:: rst :caption: Example of 'contents' directive :linenos: :emphasize-lines: 2,3 :force: This is an example block. Next two line have 'emphasis' background color. With another line. And a third one. .. code-block:: rst :caption: Example of 'contents' directive :linenos: :emphasize-lines: 2,3 :force: This is an example block. With another line. And a third one. PHP === .. code-block:: php :caption: vendor/myvendor/myextension/Classes/NameSpace/SubNamespace/CustomCategoryProcessor.php checkIf($processorConfiguration['if.'])) { return $processedData; } // categories by comma separated list $categoryIdList = $cObj->stdWrapValue('categoryList', $processorConfiguration ?? []); $categories = []; if ($categoryIdList) { $categoryIdList = GeneralUtility::intExplode(',', (string)$categoryIdList, true); /** @var CategoryRepository $categoryRepository */ $categoryRepository = GeneralUtility::makeInstance(CategoryRepository::class); foreach ($categoryIdList as $categoryId) { $categories[] = $categoryRepository->findByUid($categoryId); } // set the categories into a variable, default "categories" $targetVariableName = $cObj->stdWrapValue('as', $processorConfiguration, 'categories'); $processedData[$targetVariableName] = $categories; } return $processedData; } } JavaScript ========== .. code-block:: javascript var makeNoise = function() { console.log("Pling!"); }; makeNoise(); // → Pling! var power = function(base, exponent) { var result = 1; for (var count = 0; count < exponent; count++) result *= base; return result; }; console.log(power(2, 10)); // → 1024 JSON ==== .. code-block:: json [ { "title": "apples", "count": [12000, 20000], "description": {"text": "...", "sensitive": false} }, { "title": "oranges", "count": [17500, null], "description": {"text": "...", "sensitive": false} } ] Makefile ======== .. code-block:: makefile # Makefile BUILDDIR = _build EXTRAS ?= $(BUILDDIR)/extras .PHONY: main clean main: @echo "Building main facility..." build_main $(BUILDDIR) clean: rm -rf $(BUILDDIR)/* Markdown ======== .. code-block:: markdown # hello world you can write text [with links](https://example.org) inline or [link references][1]. * one _thing_ has *em*phasis * two __things__ are **bold** [1]: https://example.org SQL === .. code-block:: sql BEGIN; CREATE TABLE "topic" ( -- This is the greatest table of all time "id" serial NOT NULL PRIMARY KEY, "forum_id" integer NOT NULL, "subject" varchar(255) NOT NULL -- Because nobody likes an empty subject ); ALTER TABLE "topic" ADD CONSTRAINT forum_id FOREIGN KEY ("forum_id") REFERENCES "forum" ("id"); -- Initials insert into "topic" ("forum_id", "subject") values (2, 'D''artagnian'); select /* comment */ count(*) from cicero_forum; -- this line lacks ; at the end to allow people to be sloppy and omit it in one-liners /* but who cares? */ COMMIT HTML ==== .. code-block:: html
Title
XML === .. code-block:: xml