diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4e0f4531..8cb0cc86 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,9 @@
- pdoc now skips constructors if they neither have a docstring nor any parameters. This improves display
of classes that are not meant to be instantiated manually, for example when using PyO3.
([#510](https://github.com/mitmproxy/pdoc/pull/510), @mhils)
+ - Automatically fold a variable's default value if it exceeds 100 characters.
+ Feedback on this cutoff is welcome!
+ ([#511](https://github.com/mitmproxy/pdoc/pull/511), @mhils)
- Add a workaround to support inherited TypedDicts.
([#504](https://github.com/mitmproxy/pdoc/issues/504), @mhils)
- `Variable.default_value_str` does not include the ` = ` prefix anymore. It will now emit a warning and return
diff --git a/pdoc/templates/content.css b/pdoc/templates/content.css
index 2ae7e4a7..c37bc8e8 100644
--- a/pdoc/templates/content.css
+++ b/pdoc/templates/content.css
@@ -16,6 +16,7 @@ This makes sure that the pdoc styling doesn't leak to the rest of the page when
}
.pdoc .pdoc-button {
+ cursor: pointer;
display: inline-block;
border: solid black 1px;
border-radius: 2px;
@@ -332,6 +333,33 @@ This makes sure that the pdoc styling doesn't leak to the rest of the page when
color: var(--annotation);
}
+/* Show/Hide buttons for long default values */
+.pdoc .view-value-toggle-state,
+.pdoc .view-value-toggle-state ~ .default_value {
+ display: none;
+}
+.pdoc .view-value-toggle-state:checked ~ .default_value {
+ display: inherit;
+}
+.pdoc .view-value-button {
+ font-size: .5rem;
+ vertical-align: middle;
+ border-style: dashed;
+ margin-top: -0.1rem;
+}
+.pdoc .view-value-button:hover {
+ background: white;
+}
+.pdoc .view-value-button::before {
+ content: "show";
+ text-align: center;
+ width: 2.2em;
+ display: inline-block;
+}
+.pdoc .view-value-toggle-state:checked ~ .view-value-button::before {
+ content: "hide";
+}
+
/* Inherited Members */
.pdoc .inherited {
margin-left: 2rem;
diff --git a/pdoc/templates/default/module.html.jinja2 b/pdoc/templates/default/module.html.jinja2
index 359345e9..4474dd4c 100644
--- a/pdoc/templates/default/module.html.jinja2
+++ b/pdoc/templates/default/module.html.jinja2
@@ -140,8 +140,13 @@ See https://pdoc.dev/docs/pdoc/render_helpers.html#DefaultMacroExtension for an
{%- endif -%}
{% enddefaultmacro %}
{% defaultmacro default_value(var) -%}
- {%- if var.default_value_str -%}
- = {{ var.default_value_str | escape | linkify }}
+ {%- if var.default_value_str %}
+ =
+ {% if var.default_value_str | length > 100 -%}
+
+
+ {%- endif -%}
+ {{ var.default_value_str | escape | linkify }}
{%- endif -%}
{% enddefaultmacro %}
{% defaultmacro annotation(var) %}
diff --git a/test/testdata/demo.html b/test/testdata/demo.html
index b7cdd8f8..37c45c19 100644
--- a/test/testdata/demo.html
+++ b/test/testdata/demo.html
@@ -10,7 +10,7 @@
-
+