The content of the comment section and feedback should not be included when printing
Closed this issue · 5 comments
Xiaokang2022 commented
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
- Reporting a bug
- https://squidfunk.github.io/mkdocs-material/setup/adding-a-comment-system/
- https://squidfunk.github.io/mkdocs-material/setup/setting-up-site-analytics/?h=feedback#custom-site-feedback
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
- I have read and followed the bug reporting guidelines.
- I have attached links to the documentation, and possibly related issues and discussions.
- I assure that I have removed all customizations before submitting this bug report.
- I have attached a .zip file with a minimal reproduction using the built-in info plugin.
Xiaokang2022 commented
Let me make sure that the feedback area also doesn't need to be displayed when printing, right?
squidfunk commented
Ah wait, forgot the feedback area 🙈