mixmark-io / turndown

🛏 An HTML to Markdown converter written in JavaScript
https://mixmark-io.github.io/turndown
MIT License
8.95k stars 883 forks source link

Clipboard to Markdown using Turndown #251

Open lamyergeier opened 6 years ago

lamyergeier commented 6 years ago

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.

domchristie commented 6 years ago

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.

lamyergeier commented 6 years ago

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.

mals14 commented 5 years ago

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