mirror of
https://github.com/encode/django-rest-framework.git
synced 2026-01-10 18:50:56 +03:00
Merge remote-tracking branch 'origin/feat/mkdocs-material' into feat/mkdocs-material
# Conflicts: # docs/theme/stylesheets/extra.css # mkdocs.yml
This commit is contained in:
commit
05cabcdf69
30
docs_theme/css/copy-button.css
Normal file
30
docs_theme/css/copy-button.css
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
.copy-block-button {
|
||||
position: absolute;
|
||||
top: 6px;
|
||||
right: 6px;
|
||||
z-index: 10;
|
||||
white-space: nowrap; /* Prevent text wrap */
|
||||
}
|
||||
|
||||
/* Ensure the PRE container provides positioning context */
|
||||
pre {
|
||||
position: relative;
|
||||
padding-top: 35px; /* Room for the button */
|
||||
overflow-x: auto; /* Allow horizontal scrolling */
|
||||
}
|
||||
|
||||
/* Code block scrollable */
|
||||
pre code {
|
||||
display: block;
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
/*
|
||||
The MkDocs/DRF theme injects a <span> inside buttons and applies
|
||||
a text color that overrides btn-inverse defaults.
|
||||
This override is intentionally scoped and limited to color only.
|
||||
*/
|
||||
.copy-block-button,
|
||||
.copy-block-button span {
|
||||
color: #ffffff !important;
|
||||
}
|
||||
24
docs_theme/js/copy-button.js
Normal file
24
docs_theme/js/copy-button.js
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
document.addEventListener("DOMContentLoaded", function () {
|
||||
document.querySelectorAll("pre > code").forEach(function (codeBlock) {
|
||||
const button = document.createElement("button");
|
||||
button.className = "copy-block-button btn btn-inverse btn-mini";
|
||||
button.type = "button";
|
||||
button.textContent = "Copy";
|
||||
|
||||
button.addEventListener("click", function () {
|
||||
navigator.clipboard.writeText(codeBlock.textContent)
|
||||
.then(() => {
|
||||
button.textContent = "Copied!";
|
||||
setTimeout(() => button.textContent = "Copy", 1200);
|
||||
})
|
||||
.catch(() => {
|
||||
button.textContent = "Failed";
|
||||
setTimeout(() => button.textContent = "Copy", 1200);
|
||||
});
|
||||
});
|
||||
|
||||
const pre = codeBlock.parentNode;
|
||||
pre.style.position = "relative";
|
||||
pre.appendChild(button);
|
||||
});
|
||||
});
|
||||
|
|
@ -16,6 +16,9 @@
|
|||
<link href="{{ 'css/bootstrap.css'|url }}" rel="stylesheet">
|
||||
<link href="{{ 'css/bootstrap-responsive.css'|url }}" rel="stylesheet">
|
||||
<link href="{{ 'css/default.css'|url }}" rel="stylesheet">
|
||||
{% for path in config.extra_css %}
|
||||
<link href="{{ path|url }}" rel="stylesheet">
|
||||
{% endfor %}
|
||||
|
||||
|
||||
<script type="text/javascript">
|
||||
|
|
|
|||
|
|
@ -51,6 +51,11 @@ markdown_extensions:
|
|||
- admonition
|
||||
- toc:
|
||||
permalink: true
|
||||
- pymdownx.highlight:
|
||||
pygments_lang_class: true
|
||||
- pymdownx.inlinehilite
|
||||
- pymdownx.snippets
|
||||
- pymdownx.superfences
|
||||
|
||||
nav:
|
||||
- Home: 'index.md'
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user