Skip to content

Commit

Permalink
used escaped xml contents already
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaspie committed Feb 12, 2025
1 parent 52d06be commit e6b6831
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 52 deletions.
28 changes: 1 addition & 27 deletions dev_tools/docs/xsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,29 +252,6 @@ def print_docs(self, parent, indentLevel=0):
self._print(self._indent(indentLevel) + "\n")

def get_doc_from_node(self, node, retval=None):
def handle_code_and_literals(self, text):
"""
This function ensures inline code (``code``) and code blocks (.. code-block::) are correctly handled for reStructuredText.
"""
lines = text.splitlines()
self._print(text, lines)
result_lines = []

for line in lines:
# Check for inline code (e.g., ``code``)
if "``" in line:
line = self.handle_inline_code(line)

# Check for code blocks (i.e., .. code-block::)
if line.strip().startswith(".. code-block"):
# We assume the block is correctly formatted, so leave it as is
result_lines.append(f"{line.strip()}")

else:
result_lines.append(line)

return "\n".join(result_lines)

annotation_node = node.find("xs:annotation", self.ns)
if annotation_node is None:
return retval
Expand Down Expand Up @@ -302,10 +279,7 @@ def handle_code_and_literals(self, text):
htmlparser = HTMLParser.HTMLParser()
text = htmlparser.unescape(text)

# Handle potential inline code and code blocks
text = self.handle_code_and_literals(text)

return text.lstrip()
return text.lstrip()

def add_figure(self, name, indentLevel=0):
imageFile = f"img/nxdl/nxdl_{name}.png"
Expand Down
40 changes: 15 additions & 25 deletions nxdl.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -971,34 +971,24 @@ https://stackoverflow.com/a/48980995/1046449 -->
in the inheritance. At the moment, this is only the case for the
``AXISNAME`` and ``DATA`` fields in ``NXdata``, which are both of
type ``NX_NUMBER``. Thus, when specializing ``NXdata`` in an application
definition, the ``extends`` attribute allows to specify whether a field
definition, the ``extends`` attribute allows to specify whether a field
in the specialized ``NXdata`` is an ``AXISNAME`` and ``DATA``.

For example, consider the following NXDL snippet:
For example, consider the following NXDL snippet::

.. code-block:: xml
:linenos:

<definition xmlns="http://definition.nexusformat.org/nxdl/3.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
category="application"
name="NXexample"
extends="NXobject"
type="group"
xsi:schemaLocation="http://definition.nexusformat.org/nxdl/3.1 ../nxdl.xsd">
<doc>Example application definition.</doc>
<group type="NXentry">
<group type="NXdata">
<doc>
This NXdata contains multiple fields. ``temperature`` and ``voltage``
specialize ``AXISNAME``, whereas ``current`` specializes ``DATA``.
</doc>
<field name="temperature" type="NX_NUMBER" extends="/NXdata/AXISNAME"/>
<field name="voltage" type="NX_NUMBER" extends="/NXdata/AXISNAME"/>
<field name="current" type="NX_NUMBER" extends="/NXdata/DATA"/>
</group>
</group>
</definition>
&lt;definition xmlns=&quot;http://definition.nexusformat.org/nxdl/3.1&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; category=&quot;application&quot; name=&quot;NXexample&quot; extends=&quot;NXobject&quot; type=&quot;group&quot; xsi:schemaLocation=&quot;http://definition.nexusformat.org/nxdl/3.1 ../nxdl.xsd&quot;&gt;
&lt;doc&gt;Example application definition.&lt;/doc&gt;
&lt;group type=&quot;NXentry&quot;&gt;
&lt;group type=&quot;NXdata&quot;&gt;
&lt;doc&gt;
This NXdata contains multiple fields. ``temperature`` and ``voltage``specialize ``AXISNAME``, whereas ``current`` specializes ``DATA``.
&lt;/doc&gt;
&lt;field name=&quot;temperature&quot; type=&quot;NX_NUMBER&quot; extends=&quot;/NXdata/AXISNAME&quot;/&gt;
&lt;field name=&quot;voltage&quot; type=&quot;NX_NUMBER&quot; extends=&quot;/NXdata/AXISNAME&quot;/&gt;
&lt;field name=&quot;current&quot; type=&quot;NX_NUMBER&quot; extends=&quot;/NXdata/DATA&quot;/&gt;
&lt;/group&gt;
&lt;/group&gt;
&lt;/definition&gt;

Here, the ``extends`` attribute is used to specify that the ``temperature`` and ``voltage`` fields are specializations
of the ``AXISNAME`` field, whereas the ``current`` field is a specialization of the ``DATA`` field.
Expand Down

0 comments on commit e6b6831

Please sign in to comment.