summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2021-01-19 11:15:44 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2021-02-01 06:59:01 +0100
commitca6c1582afbc748ae0f02410b54039b0af36fc73 (patch)
tree1e3ddd1969e619e456ba7a06ca3845d7f926e4c2
parentspec: Add RTEMS_STATIC_ANALYSIS (diff)
downloadrtems-central-ca6c1582afbc748ae0f02410b54039b0af36fc73.tar.bz2
content: Do not warp code blocks
-rw-r--r--rtemsspec/content.py31
-rw-r--r--rtemsspec/interface.py4
-rw-r--r--rtemsspec/tests/spec-interface/func.yml5
-rw-r--r--rtemsspec/tests/test_interface.py5
-rw-r--r--rtemsspec/tests/test_interfacedoc.py5
5 files changed, 38 insertions, 12 deletions
diff --git a/rtemsspec/content.py b/rtemsspec/content.py
index cdd437a0..f3729584 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 c9b07ff0..d796e2eb 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 e5dc909b..25a23b3b 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 9cdea77e..0519eb24 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 a99e279f..3a695722 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()