3

Is it possible to copy a comment text in markdown to the clipboard?

E.g., if the comment text in markdown is blah $x$ and http://stats.stackexchange.com/questions/221704/results-of-softmax-regression-on-mnist-dataset, I will get blah xx and stats.stackexchange.com/questions/221704/… if I select then copy the comment text (assuming latex is activated), whereas I want to have the comment text in markdown.

The edit button is only present for five minutes and for one's own comments.

0
4

No, this is not possible. One way to get the markdown of the comment is via SEDE; e.g. this query shows the comments on this answer.

Of course, SEDE is updated only once a week, on Sunday morning, so the comment needs to have a certain age for this to work.

4

I've previously made a userscript that does just that: Copy post content as markdown — quick and easy way to quote people!

It allows you to press Ctrl + Alt + M to show a prompt to copy the text as markdown (M for markdown)!

It works anywhere on the page (or at least it should!)

Note: it has a few bugs, I'm working on fixing them right now fixed!

6
  • @Glorfindel no :( but I can look into making it work with MathJax, but I've never used it before. do you know of a page somewhere that describes it in it's basic form so I can try it out? :) – ᔕᖺᘎᕊ Jan 1 '17 at 17:57
  • no problem, found this: meta.math.stackexchange.com/questions/5020/… :) – ᔕᖺᘎᕊ Jan 1 '17 at 17:58
  • Nice! Maybe you could integrate this as a feature to SOX :-) (e.g., adding a copy button to each comment) – Franck Dernoncourt Jan 1 '17 at 18:06
  • @FranckDernoncourt yeah, I could look into adding it to SOX :) (btw it's fixed now) – ᔕᖺᘎᕊ Jan 1 '17 at 18:24
  • @Glorfindel v1.2 now has basic mathjax support :) – ᔕᖺᘎᕊ Jan 1 '17 at 20:09
  • @FranckDernoncourt v1.2 now has basic mathjax support :) – ᔕᖺᘎᕊ Jan 1 '17 at 20:10
1

Sure. Use the userscript I made here...

// ==UserScript==
// @name           Show Comment Markdown
// @namespace      cai
// @version        0.2
// @description    Show the Markdown source of a comment, useful for copy/pasting.
// @author         Cai
// @include        http://stackoverflow.com/*
// @include        http://serverfault.com/*
// @include        http://superuser.com/*
// @include        http://meta.stackoverflow.com/*
// @include        http://meta.serverfault.com/*
// @include        http://meta.superuser.com/*
// @include        http://stackapps.com/*
// @include        http://*.stackexchange.com/*
// @include        http://askubuntu.com/*
// @include        http://meta.askubuntu.com/*
// @include        http://mathoverflow.net/*
// @include        http://area51.stackexchange.com/proposals/*
// @exclude        http://chat.*/*
// @grant          none
// ==/UserScript==

function with_jquery(f) {
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.textContent = "(" + f.toString() + ")(jQuery)";
    document.body.appendChild(script);
}

with_jquery(function ($) {

    $('head').append(
        $(
            '<style>' +
            '#markdown-clipboard { \
                 position: fixed; \
                 top: 0; left: 0; right: 0; bottom: 0; \
                 background: rgba(0,0,0,0.2); \
            } \
            #markdown-clipboard textarea { \
                 display: block; \
                 width: 400px; \
                 height: 160px; \
                 margin: auto; \
                 padding: 20px; \
                 box-shadow: 0 2px 5px rgba(12,13,14,0.3); \
                 background-color: #FFF; \
                 border: solid 1px #9fa6ad; \
            } \
            #markdown-clipboard-close { \
                 cursor: pointer; \
                 display: block; \
                 margin: 30vh auto 20px auto; \
                 text-align: center; \
                 font-size: 2em; \
                 color: #fff; \
                 background: #0C0D0E; \
                 width: 30px; \
                 height: 30px; \
                 line-height: 28px; \
            } \
            .show-markdown-link { \
                 cursor: pointer; \
                 color: #9199a1; \
                 opacity: 0; \
            } \
            .comment:hover .show-markdown-link { \
                 opacity: 1; \
            }' +
            '</style>'
        )
    );
    $('body').append('<div id="markdown-clipboard" style="display:none;"><span id="markdown-clipboard-close">&times;</span><textarea></textarea></div>');

    $(document).ajaxComplete(function(){
        $('.comments').each(make_copy_links);
    });

    $('.comments').each(make_copy_links);

    function make_copy_links() {
        $(this).find('.comment:not(:has(.show-markdown-link)) .comment-body').each(function () {
            $('<span class="show-markdown-link" title="Source">| Source</span>').click(show_markdown).appendTo(this);
        });
    }

    function show_markdown() {
        var comment = $(this).closest(".comment");
        var cid = comment.attr("id");
        var cdash = cid.lastIndexOf('-');
        var comment_id = cid.substring(cdash + 1);
        $.getJSON(window.location.protocol + '//api.stackexchange.com/2.2/comments/' + comment_id + '?site=' + window.location.hostname + '&filter=!)Q29lpdRHRpfMsqok1CFj-3(',
            function (data) {
                var markdown = data.items[0].body_markdown;
                $('#markdown-clipboard').show().find('textarea').html(markdown);
            }
        );
    }

    $('#markdown-clipboard-close').click(clear_clipboard);

    function clear_clipboard() {
        $('#markdown-clipboard').hide().find('textarea').html();
    }

});

This gives you a "Source" link at the end of every comment, which when clicked will show you the Markdown source of the comment in a popup.

Comment Markdown source popup


It's also worth noting that you can copy comments in Markdown via the iOS app (not sure about the Android app though).

5
  • thanks, the source button is present, however after clicking on it not pop-up appears ( Google Chrome ). Android also seems to have this feature: meta.stackexchange.com/q/245900/178179 – Franck Dernoncourt Jan 1 '17 at 18:11
  • What OS and Chrome version? I use it with no problem on latest Chrome on macOS and Windows 7 – Cai Jan 1 '17 at 18:14
  • Windows 7 SP1 x64 Ultimate, Google Chrome Version 55.0.2883.87 m (latest version). Weird :/ I disabled all other tampermonkey scripts. – Franck Dernoncourt Jan 1 '17 at 18:18
  • Any errors or anything in the console? I'll have a look at it later but I'm not at a computer atm – Cai Jan 1 '17 at 18:24
  • I see one 400 (Bad Request) when I click on source: i.stack.imgur.com/axFlo.png I tried on the page stats.stackexchange.com/questions/16921/… – Franck Dernoncourt Jan 2 '17 at 17:09

Not the answer you're looking for? Browse other questions tagged .