Why are code snippets uncopyable when using "mkdocs build"?

485 Views Asked by At

Why code snippets can be copied when running "mkdocs serve" with the mkdocs-material theme, but not when using "mkdocs build"?

Using mkdocs serve is resulting in:

abcd

Using mkdocs build there is no "copied" button:

enter image description here

How can I enable copying of code snippets in the static files generated by mkdocs build?

2

There are 2 best solutions below

0
On BEST ANSWER

Refer: mkdocs-material docs

I found out that I wrote one less feature parameter in the latest version, as follow:

theme:
  name: material
  features:
    - announce.dismiss
    - content.action.edit
    - content.action.view
    - content.code.annotate
    - content.code.copy
0
On

If you really configured the mkdocs-material theme, the Copy icon will also appear in the generated static HTML pages.

Perform the following steps as a simple test case e.g. using PowerShell:

  1. Create new project mkdocs new test
  2. Goto to test directory cd test
  3. Open mkdocs.yml using your favorite text editor.
  4. Add the theme like shown below
site_name: My Docs
# ============================================
# APPEARANCE
# ============================================
theme:
  name: material
  1. Run mkdocs build

When you open site/index.html this is resulting in:

enter image description here

Tested on Windows 10 22H2, mkdocs 1.4.2, mkdocs-material 8.5.6