turndown icon indicating copy to clipboard operation
turndown copied to clipboard

Clipboard to Markdown using Turndown

Open lamyergeier opened this issue 5 years ago • 3 comments

Hi! Please have a look at this euangoddard/clipboard2markdown: Convert rich-text on your clipboard to markdown, it is based on your old library to-markdown.

Could you please provide this interface to your new library? Your library has more advanced features. Just that your website requires us to input html, which is less user-friendly.

I am less familiar with Javascript, but I saw that the author has created a function to send the copied webpage content to your old library.

lamyergeier avatar Aug 25 '18 08:08 lamyergeier

Thanks for the idea. This feature would require a layer to capture rich text as HTML from a paste. It is probably a little out of scope for the library itself, but it's "nice-to-have" for the demo. I'd recommend that euangoddard/clipboard2markdown is updated to use Turndown, so you might want to raise an issue there.

domchristie avatar Aug 25 '18 19:08 domchristie

Hi, I saw that at this page, euangoddard has mentioned that he won't be maintaining that project anymore. I have seen his code, in the file:

/*
 * clipboard2markdown
 * Copyright (c) 2014 Euan Goddard
 * Licenced under the MIT licence
 */
  var convert = function (str) {
    return escape(toMarkdown(str, { converters: pandoc, gfm: true }));
  }
  document.addEventListener('DOMContentLoaded', function () {
    var info = document.querySelector('#info');
    var pastebin = document.querySelector('#pastebin');
    var output = document.querySelector('#output');
    var wrapper = document.querySelector('#wrapper');

    document.addEventListener('keydown', function (event) {
      if (event.ctrlKey || event.metaKey) {
        if (String.fromCharCode(event.which).toLowerCase() === 'v') {
          pastebin.innerHTML = '';
          pastebin.focus();
          info.classList.add('hidden');
          wrapper.classList.add('hidden');
        }
      }
    });

    pastebin.addEventListener('paste', function () {
      setTimeout(function () {
        var html = pastebin.innerHTML;
        var markdown = convert(html);
        output.value = markdown;
        wrapper.classList.remove('hidden');
        output.focus();
        output.select();
      }, 200);
    });
  });
})();

The above snippet does capture HTML and in the above he has used convert function to call tomarkdown function. He has defined an object called pandoc which is the definiton of convertor defined in tomarkdown.

I really hope that you could integrate this, so we can have an updated library.

One Nice Application: Apart from demo purposes that you mentioned, I take notes by copying contents from websites on the browser as markdown. It can serve as a great tool for note-taking!

Also if we could do this then another issue that I raised Incomplete (broken) Links are being created by Turndown · Issue #252 · domchristie/turndown, would be solved - euangoddard/clipboard2markdown is able to capture complete link.

lamyergeier avatar Aug 25 '18 21:08 lamyergeier

would be great to be able to use Turndown from the command line!

mals14 avatar Jan 08 '19 02:01 mals14