Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a possibility for downloadable snippets / copy to clipboard #22

Closed
sypets opened this issue Feb 16, 2018 · 11 comments
Closed

Provide a possibility for downloadable snippets / copy to clipboard #22

sypets opened this issue Feb 16, 2018 · 11 comments
Assignees
Labels
accepted Accept something (to be done) enhancement New feature or request help wanted Extra attention is needed

Comments

@sypets
Copy link
Contributor

sypets commented Feb 16, 2018

see

grafik

@marble
Copy link
Member

marble commented Jul 2, 2018

  1. Files can be shown in code-blocks, though we hardly use that. In that case you can simply write a link to that file as well.

  2. I don't know how the dokuwiki does that downloading of code-block content as file. Im curious, but I don't think it's an essential feature.

  3. A button: "Mark all content of the code-block" and copy it to the clipboard could be convenient.

I close this issue for now. If somebodies stumbles across a nice solution for three on some other website we can still consider that and reopen this issue.

@marble marble closed this as completed Jul 2, 2018
@marble
Copy link
Member

marble commented Jul 6, 2018

Oops, just noticed, that I had found that nice solution back in 2016 already ;-))
http://mbless.de/blog/2015/01/15/looking-for-wisdom-about-javascript.html#copy-to-clipboard

@sypets sypets changed the title Provide a possibility for downloadable snippets Provide a possibility for downloadable snippets / copy to clipboard Jul 7, 2019
@sypets
Copy link
Contributor Author

sypets commented Jul 7, 2019

Can we reopen? I think copy to clipboard would be more useful than download to file.

I changed the title.

Examples that use this in the TYPO3 universe:

Forger reST helper for changelog

https://forger.typo3.com/utilities/rst

  1. Click "Breaking"
  2. Click "Code Block"
  3. Click the icon

forger

Gerrit

  1. open a review, e.g. https://review.typo3.org/c/Packages/TYPO3.CMS/+/58255
  2. press download

gerrit

@sypets sypets reopened this Jul 7, 2019
@DanielSiepmann
Copy link
Member

As far as I understand, we "just" need to add @marble JavaScript solution to the theme?

@sypets
Copy link
Contributor Author

sypets commented Dec 2, 2019

Example on Symfony page:

clipboard

https://symfony.com/doc/current/doctrine.html

@marble
Copy link
Member

marble commented Dec 3, 2019

Ok, I'll go for a solution. Is certainly a useful "nice to have".

@marble
Copy link
Member

marble commented Dec 4, 2019

On the symfonie page it's

(window.webpackJsonp = window.webpackJsonp || []).push([["doc"], {
    b2hv: function (e, t, n) {
    }, "ip/K": function (e, t, n) {
        "use strict";
        n.r(t);
        var c = n("eBEy");

        function o(e) {
            var t = localStorage.getItem("selectedFormat"),
                n = e.querySelector("li");
            e.querySelectorAll("[class^=highlight-]").forEach(function (e) {
                e.style.display = "none"
            }), e.querySelectorAll("li").forEach(function (e) {
                e.classList.remove("selected"), e.querySelector("em").textContent == t && (n = e)
            });
            var c = n.querySelector("[class^=highlight-]"),
                o = n.closest("ul.simple"),
                i = 28 + (c.classList.contains("highlight-terminal") ? 34 : 0);
            n.classList.add("selected"), c.style.display = "block", o.style.height = c.scrollHeight + i + "px"
        }

        n("b2hv"), window.addEventListener("load", function () {
            !function () {
                var e = {
                    allowHTML: !0,
                    animateFill: !1,
                    animation: "fade",
                    ignoreAttributes: !0,
                    interactive: !0,
                    maxWidth: 500,
                    placement: "right",
                    sticky: !0,
                    trigger: "click",
                    theme: "light-border"
                };
                if (null === document.querySelector("#doc-menu-guides")) return;
                Object(c.a)("#doc-menu-guides", Object.assign({}, e, {content: document.querySelector("#doc-menu-guides-content").innerHTML})), Object(c.a)("#doc-menu-components", Object.assign({}, e, {
                    content: document.querySelector("#doc-menu-components-content").innerHTML,
                    maxWidth: 650
                }))
            }(), document.querySelectorAll("div.configuration-block").forEach(function (e) {
                e.classList.add("jsactive", "clearfix"), o(e), e.querySelectorAll("li").forEach(function (e) {
                    var t = e.querySelector("em"), n = t.textContent;
                    t.innerHTML = '<a href="#">' + n + "</a>", t.addEventListener("click", function (e) {
                        localStorage.setItem("selectedFormat", n), document.querySelectorAll("div.configuration-block").forEach(function (e) {
                            o(e)
                        }), e.preventDefault()
                    })
                })
            }), document.querySelectorAll(".highlight-terminal .gp, .highlight-terminal .c1").forEach(function (e) {
                e.dataset.content = e.textContent
            }), document.querySelectorAll("div.literal-block .highlight").forEach(function (e) {
                var t = e.closest("[class*=highlight-]");
                if (!t.classList.contains("highlight-terminal") && !t.classList.contains("highlight-diff")) {
                    var n = document.createElement("button");
                    n.classList.add("btn", "btn--code-copy"), e.prepend(n), n.addEventListener("click", function (t) {
                        var c, o;
                        c = e.textContent, (o = document.createElement("textarea")).setAttribute("readonly", ""), o.style = {
                            position: "absolute",
                            left: "-9999px"
                        }, o.value = c, document.body.appendChild(o), o.select(), document.execCommand("copy"), document.body.removeChild(o), n.classList.add("btn--code-copied"), setTimeout(function () {
                            n.classList.remove("btn--code-copied")
                        }, 1500), t.preventDefault()
                    })
                }
            })
        })
    }
}, [["ip/K", "runtime", 1]]]);

@benjaminkott benjaminkott transferred this issue from TYPO3-Documentation/t3SphinxThemeRtd Jan 23, 2020
@marble marble self-assigned this Oct 9, 2020
@marble marble added accepted Accept something (to be done) enhancement New feature or request help wanted Extra attention is needed labels Oct 9, 2020
@susannemoog
Copy link

How about using https://sphinx-copybutton.readthedocs.io/en/latest/ ?

@marble
Copy link
Member

marble commented Jun 8, 2021

How about using https://sphinx-copybutton.readthedocs.io/en/latest/ ?

Cool, will have a look.

@marble
Copy link
Member

marble commented Jul 23, 2021

Done and solved with Docker rendering container version v2.9.0

@marble marble closed this as completed Jul 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Accept something (to be done) enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants