[rtems-central commit] content: Do not warp code blocks

Sebastian Huber sebh at rtems.org
Wed Feb 3 05:28:01 UTC 2021


Module:    rtems-central
Branch:    master
Commit:    ca6c1582afbc748ae0f02410b54039b0af36fc73
Changeset: http://git.rtems.org/rtems-central/commit/?id=ca6c1582afbc748ae0f02410b54039b0af36fc73

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Tue Jan 19 11:15:44 2021 +0100

content: Do not warp code blocks

---

 rtemsspec/content.py                    | 31 +++++++++++++++++++++----------
 rtemsspec/interface.py                  |  4 ++--
 rtemsspec/tests/spec-interface/func.yml |  5 +++++
 rtemsspec/tests/test_interface.py       |  5 +++++
 rtemsspec/tests/test_interfacedoc.py    |  5 +++++
 5 files changed, 38 insertions(+), 12 deletions(-)

diff --git a/rtemsspec/content.py b/rtemsspec/content.py
index cdd437a..f372958 100644
--- a/rtemsspec/content.py
+++ b/rtemsspec/content.py
@@ -33,8 +33,8 @@ import os
 import re
 import sys
 import textwrap
-from typing import Any, Callable, ContextManager, Dict, Iterable, Iterator, \
-    List, NamedTuple, Optional, Set, Tuple, Union
+from typing import Any, Callable, ContextManager, Deque, Dict, Iterable, \
+    Iterator, List, NamedTuple, Optional, Set, Tuple, Union
 
 from rtemsspec.items import Item, ItemGetValueContext
 
@@ -235,6 +235,15 @@ class Content:
                                 self._empty_line_indent))
                 break
 
+    def _add_verbatim(self, blocks: Deque[str]) -> None:
+        while blocks:
+            block = blocks.popleft()
+            if block.startswith("    "):
+                self.add(block[4:].replace("\n    ", "\n"))
+            else:
+                blocks.appendleft(block)
+                break
+
     def wrap_text(self,
                   text: str,
                   initial_indent: str = "",
@@ -254,12 +263,20 @@ class Content:
             wrapper.initial_indent = initial_indent
             wrapper.width = 79 - len(self._indent)
             gap = []  # type: List[str]
-            for block in text.split("\n\n"):
+            blocks = collections.deque(text.split("\n\n"))
+            while blocks:
+                block = blocks.popleft()
                 match = _SPECIAL_BLOCK.search(block)
                 if match:
                     space = len(match.group(0)) * " "
                     wrapper.subsequent_indent = f"{subsequent_indent}{space}"
                     block = block.replace(f"\n{space}", "\n")
+                elif block.startswith(".. code-block"):
+                    self.add(block)
+                    with self.indent():
+                        self.gap = True
+                        self._add_verbatim(blocks)
+                    continue
                 else:
                     wrapper.subsequent_indent = subsequent_indent
                 self._lines.extend(gap)
@@ -560,13 +577,7 @@ class CContent(Content):
             if block.startswith(".. code-block"):
                 self.add("@code")
                 self.gap = False
-                while blocks:
-                    block = blocks.popleft()
-                    if block.startswith("    "):
-                        self.add(block[4:].replace("\n    ", "\n"))
-                    else:
-                        blocks.appendleft(block)
-                        break
+                self._add_verbatim(blocks)
                 self.append("@endcode")
             else:
                 self.wrap_text(block)
diff --git a/rtemsspec/interface.py b/rtemsspec/interface.py
index c9b07ff..d796e2e 100644
--- a/rtemsspec/interface.py
+++ b/rtemsspec/interface.py
@@ -408,8 +408,8 @@ class Node:
         with content.doxygen_block():
             content.add_ingroup(_get_group_identifiers(ingroups))
             content.add_brief_description(self.substitute_text(item["brief"]))
-            content.wrap(self.substitute_text(item["description"]))
-            content.wrap(self.substitute_text(item["notes"]))
+            content.doxyfy(self.substitute_text(item["description"]))
+            content.doxyfy(self.substitute_text(item["notes"]))
             if "params" in item:
                 content.add_param_description(item["params"],
                                               self.substitute_text)
diff --git a/rtemsspec/tests/spec-interface/func.yml b/rtemsspec/tests/spec-interface/func.yml
index e5dc909..25a23b3 100644
--- a/rtemsspec/tests/spec-interface/func.yml
+++ b/rtemsspec/tests/spec-interface/func.yml
@@ -18,6 +18,11 @@ description: |
   ${enum:/name}, ${define:/name}, ${macro:/name}, ${var:/name},
   ${enumerator-0:/name}, ${s:/name}, ${option:/name}, and ${option:/type}.
   Second parameter is ${.:/params[1]/name}.
+
+  .. code-block:
+
+      these two lines
+      are not wrapped
 enabled-by: true
 index-entries: []
 interface-type: function
diff --git a/rtemsspec/tests/test_interface.py b/rtemsspec/tests/test_interface.py
index 9cdea77..0519eb2 100644
--- a/rtemsspec/tests/test_interface.py
+++ b/rtemsspec/tests/test_interface.py
@@ -211,6 +211,11 @@ typedef enum EnumB {
  * #DEFINE, VERY_LONG_MACRO(), #Variable, ::ENUMERATOR_0, Struct, #a, and
  * interface. Second parameter is ``Param1``.
  *
+ * @code
+ * these two lines
+ * are not wrapped
+ * @endcode
+ *
  * @param Param0 is parameter 0.
  *
  * @param[in] Param1 is parameter 1.
diff --git a/rtemsspec/tests/test_interfacedoc.py b/rtemsspec/tests/test_interfacedoc.py
index a99e279..3a69572 100644
--- a/rtemsspec/tests/test_interfacedoc.py
+++ b/rtemsspec/tests/test_interfacedoc.py
@@ -461,5 +461,10 @@ Function description.  References to :ref:`InterfaceVeryLongFunction`,
 :c:type:`Integer`, :c:type:`Enum`, :c:macro:`DEFINE`,
 :ref:`InterfaceVERYLONGMACRO`, Variable, :c:macro:`ENUMERATOR_0`,
 :c:type:`Struct`, :ref:`a`, and interface. Second parameter is ``Param1``.
+
+.. code-block:
+
+    these two lines
+    are not wrapped
 """
         assert content == src.read()



More information about the vc mailing list