squidfunk/mkdocs-material

The content of the comment section and feedback should not be included when printing

Closed this issue · 5 comments

Context

Python: 3.13.0
OS: Windows11 23H2

Bug description

When using the print function on some browsers, the comment and feedback areas at the bottom of the article will be printed together, but it should only contain the content of the article itself, not comments and feedback.

Related links

Reproduction

Unable to create .zip file:

Because the comment section needs to be customized to do so, but the plugin info doesn't allow that.

Here are some examples of information that may be useful:

  • Directory structure:
├─docs
│   └─index.md
├─override
│   └─partials
│       └─comments.html
└─mkdocs.yml
  • mkdocs.yml:
site_name: My Docs

markdown_extensions:
  - meta

theme:
  name: material
  custom_dir: override

plugins:
  - info
  • index.md:
---
comments: true
---
  • comments.html: (Here I replace some personal information with ... finish)
{% if page.meta.comments %}
<script src="https://giscus.app/client.js" data-repo="..." data-repo-id="..."
    data-category="GitHub Pages" data-category-id="..." data-mapping="pathname" data-strict="1"
    data-reactions-enabled="1" data-emit-metadata="0" data-input-position="top" data-theme="preferred_color_scheme"
    data-lang="zh-CN" data-loading="lazy" crossorigin="anonymous" async>
    </script>

<!-- Synchronize Giscus theme with palette -->
<script>
    var giscus = document.querySelector("script[src*=giscus]")

    // Set palette on initial load
    var palette = __md_get("__palette")
    if (palette && typeof palette.color === "object") {
        var theme = palette.color.scheme === "slate"
            ? "dark"
            : "light"

        // Instruct Giscus to set theme
        giscus.setAttribute("data-theme", theme)
    }

    // Register event handlers after documented loaded
    document.addEventListener("DOMContentLoaded", function () {
        var ref = document.querySelector("[data-md-component=palette]")
        ref.addEventListener("change", function () {
            var palette = __md_get("__palette")
            if (palette && typeof palette.color === "object") {
                var theme = palette.color.scheme === "slate"
                    ? "dark"
                    : "light"

                // Instruct Giscus to change theme
                var frame = document.querySelector(".giscus-frame")
                frame.contentWindow.postMessage(
                    { giscus: { setConfig: { theme } } },
                    "https://giscus.app"
                )
            }
        })
    })
</script>
{% endif %}

Steps to reproduce

Use browser's built-in print function on any page that contains a comment or feedback area.

Browser

Edge

Before submitting

Thanks for reporting. I agree that comments should be hidden. Fixed in 39d14d5.

Let me make sure that the feedback area also doesn't need to be displayed when printing, right?

Ah wait, forgot the feedback area 🙈

Fixed in e29e124.

Released as part of 9.5.41.