diff --git a/sphinx_js/templates/common.rst b/sphinx_js/templates/common.rst index 09bbf222..5402e18b 100644 --- a/sphinx_js/templates/common.rst +++ b/sphinx_js/templates/common.rst @@ -9,14 +9,14 @@ {% macro examples(items) %} {% if items -%} -**Examples:** +.. admonition:: Example {%- if items|length > 1 -%} s {%- endif %} -{% for example in items -%} -.. code-block:: js + {% for example in items -%} + .. code-block:: js - {{ example|indent(3) }} + {{ example|indent(6) }} -{% endfor %} + {% endfor %} {%- endif %} {% endmacro %} diff --git a/tests/test_build_js/test_build_js.py b/tests/test_build_js/test_build_js.py index 7f424214..5d355d87 100644 --- a/tests/test_build_js/test_build_js.py +++ b/tests/test_build_js/test_build_js.py @@ -59,7 +59,7 @@ def test_autofunction_example(self): "autofunction_example", "exampleTag()\n\n" " JSDoc example tag\n\n" - " **Examples:**\n\n" + " Example:\n\n" " // This is the example.\n" " exampleTag();\n", ) @@ -268,7 +268,7 @@ def test_autoclass_example(self): "autoclass_example", "class ExampleClass()\n\n" " JSDoc example tag for class\n\n" - " **Examples:**\n\n" + " Example:\n\n" " // This is the example.\n" " new ExampleClass();\n", ) @@ -306,7 +306,7 @@ def test_autoattribute_example(self): "autoattribute_example", "ExampleAttribute\n\n" " JSDoc example tag for attribute\n\n" - " **Examples:**\n\n" + " Example:\n\n" " // This is the example.\n" " console.log(ExampleAttribute);\n", ) diff --git a/tests/test_renderers.py b/tests/test_renderers.py index 532a8ae8..9d6fda79 100644 --- a/tests/test_renderers.py +++ b/tests/test_renderers.py @@ -281,15 +281,15 @@ def test_func_render_callouts(function_render): ) assert function_render(examples=["ex1", "ex2"]) == DEFAULT_RESULT + setindent( """ - **Examples:** + .. admonition:: Examples - .. code-block:: js + .. code-block:: js - ex1 + ex1 - .. code-block:: js + .. code-block:: js - ex2 + ex2 """, ) assert function_render(see_alsos=["see", "this too"]) == DEFAULT_RESULT + setindent( @@ -300,3 +300,37 @@ def test_func_render_callouts(function_render): - :any:`this too` """, ) + + +def test_all(function_render): + assert function_render( + description="description", + params=[Param("a", "xx")], + deprecated=True, + exceptions=[Exc("TypeError", "")], + examples=["ex1"], + see_alsos=["see"], + ) == dedent( + """\ + .. js:function:: blah(a) + + .. note:: + + Deprecated. + + description + + :param a: xx + :throws TypeError: + + .. admonition:: Example + + .. code-block:: js + + ex1 + + .. seealso:: + + - :any:`see` + """ + )