8000 Better support for printing from dark mode · Issue #1973 · squidfunk/mkdocs-material · GitHub
[go: up one dir, main page]

Skip to content

Better support for printing from dark mode #1973

@timvink

Description

@timvink

I checked that...

  • ... the documentation does not mention anything about my idea
  • ... to my best knowledge, my idea wouldn't break something for other users
  • ... there are no open or closed issues that are related to my idea

Description

When using dark mode, printing a page results in barely readable text:

image

instead, when printing, mkdocs-material could temporarily switch to light mode, and then back.

Use Cases

well, printing obviously.

Screenshots / Mockups

Here is some javascript I adapted from https://stackoverflow.com/a/11060206/5525118 to make it work for mkdocs-material

function change_material_theme(to="default") {

  body = document.getElementsByTagName('body')[0];
  var current_color_theme = body.getAttribute('data-md-color-scheme')
  
  var beforePrint = function() {
      console.log('Functionality to run before printing.');
      body.setAttribute("data-md-color-scheme", to);
  };
  var afterPrint = function() {
      console.log('Functionality to run after printing');
      body.setAttribute("data-md-color-scheme", current_color_theme); 
  };

  if (window.matchMedia) {
      var mediaQueryList = window.matchMedia('print');
      mediaQueryList.addListener(function(mql) {
          if (mql.matches) {
              beforePrint();
          } else {
              afterPrint();
          }
      });
  }

  window.onbeforeprint = beforePrint;
  window.onafterprint = afterPrint;

}

And here's a GIF with the script in action:

print js

Metadata

Metadata

Assignees

No one assigned

    Labels

    change requestIssue requests a new feature or improvementresolvedIssue is resolved, yet unreleased if open

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0