From 77d5081a9d71b0e89fdf3b5f7c5edbd61e0b74a0 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Sun, 19 Feb 2023 13:31:57 +0100 Subject: [PATCH 1/2] fold long variable default values, fix #507 --- CHANGELOG.md | 2 ++ pdoc/templates/content.css | 28 +++++++++++++++++++++++ pdoc/templates/default/module.html.jinja2 | 9 ++++++-- test/testdata/demo.html | 2 +- test/testdata/demo_eager.html | 2 +- test/testdata/demo_long.html | 26 +++++++++++++-------- test/testdata/demopackage.html | 2 +- test/testdata/demopackage_dir.html | 12 +++++----- test/testdata/example_customtemplate.html | 2 +- test/testdata/example_darkmode.html | 2 +- test/testdata/example_mkdocs.html | 2 +- test/testdata/flavors_google.html | 5 ++-- test/testdata/flavors_numpy.html | 5 ++-- test/testdata/flavors_rst.html | 2 +- test/testdata/math_demo.html | 2 +- test/testdata/misc.html | 17 +++++++++----- test/testdata/misc_py310.html | 8 ++++--- test/testdata/misc_py311.html | 2 +- test/testdata/misc_py39.html | 2 +- test/testdata/render_options.html | 6 ++--- test/testdata/top_level_reimports.html | 2 +- test/testdata/type_checking_imports.html | 5 ++-- test/testdata/type_stub.html | 11 +++++---- 23 files changed, 106 insertions(+), 50 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e0f4531..50fe810f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ - 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! - 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 @@ - +