From 050bda6609663820362117cbb3c7acc358ab7561 Mon Sep 17 00:00:00 2001 From: squidfunk Date: Mon, 2 Jan 2023 14:29:16 +0100 Subject: [PATCH] Added documentation for code copy button --- docs/reference/code-blocks.md | 39 +++++++++++++++++++++++++++++++++++ docs/reference/tooltips.md | 2 +- docs/schema/theme.json | 7 +++++++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/docs/reference/code-blocks.md b/docs/reference/code-blocks.md index c2f09a535..8dd034080 100644 --- a/docs/reference/code-blocks.md +++ b/docs/reference/code-blocks.md @@ -42,6 +42,45 @@ See additional configuration options: [SuperFences]: ../setup/extensions/python-markdown-extensions.md#superfences [Snippets]: ../setup/extensions/python-markdown-extensions.md#snippets +### Code copy button + +[:octicons-tag-24: 9.0.0][Code copy button support] · +:octicons-unlock-24: Feature flag + +Code blocks can automatically render a button on the right side to allow the +user to copy a code block's contents to the clipboard. Add the following to +`mkdocs.yml` to enable them globally: + +``` yaml +theme: + features: + - content.code.copy +``` + + [Code copy button support]: https://github.com/squidfunk/mkdocs-material/releases/tag/9.0.0 + +??? info "Enabling or disabling code copy buttons for a specific code block" + + If you don't want to enable code copy buttons globally, you can enable them + for a specific code block by using a slightly different syntax based on the + [Attribute Lists] extension: + + ```` yaml + ``` { .yaml .copy } + # Code block content + ``` + ```` + + Note that the language shortcode which has to come first must now also be + prefixed by a `.`. Similarily, the copy button can also be disabled for a + specific code block: + + ```` { .yaml .no-copy } + ``` { .yaml .no-copy } + # Code block content + ``` + ```` + ### Code annotations [:octicons-tag-24: 8.0.0][Code annotations support] · diff --git a/docs/reference/tooltips.md b/docs/reference/tooltips.md index aaf363616..de9c4a7d8 100644 --- a/docs/reference/tooltips.md +++ b/docs/reference/tooltips.md @@ -51,7 +51,7 @@ theme: Now, tooltips will be rendered for the following elements: -- __Content__ – elements with a `title`, permalinks and copy-to-clipboard button +- __Content__ – elements with a `title`, permalinks and code copy button - __Header__ – home button, header title, color palette switch and repository link - __Navigation__ – links that are shortened with ellipsis, i.e. `...` diff --git a/docs/schema/theme.json b/docs/schema/theme.json index ea9af64c0..97cafc24e 100644 --- a/docs/schema/theme.json +++ b/docs/schema/theme.json @@ -587,6 +587,13 @@ "content.code.annotate" ] }, + { + "title": "Code copy button", + "markdownDescription": "https://squidfunk.github.io/mkdocs-material/reference/code-blocks/#code-copy-button", + "enum": [ + "content.code.copy" + ] + }, { "title": "Linked content tabs", "markdownDescription": "https://squidfunk.github.io/mkdocs-material/reference/content-tabs/#linked-content-tabs",