0

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?

help-info.de
  • 6,695
  • 16
  • 39
  • 41
wavty
  • 191
  • 2
  • 5

2 Answers2

1

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

help-info.de
  • 6,695
  • 16
  • 39
  • 41
0

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
wavty
  • 191
  • 2
  • 5