GithubHelp home page GithubHelp logo

yorkxin / copy-as-markdown Goto Github PK

View Code? Open in Web Editor NEW
502.0 11.0 78.0 1.56 MB

Copying Link, Image and Tab(s) as Markdown Much Easier.

License: MIT License

JavaScript 37.49% HTML 10.12% Shell 0.40% Java 51.98%
webextensions firefox chrome browser

copy-as-markdown's Introduction

Copy as Markdown for Chrome & Firefox

Do you often type Markdown code manually for a link or image, or even all tabs in a window, and feel tired? Copy as Markdown can help you!

Download

Features

Copy as Markdown is a browser extension that helps you copy the following things as Markdown to your system clipboard:

On the web page:

☑️ Selection Text as Markdown
☑️ A Link on the Page
☑️ An Image on the Page, with or without wrapping link

Exporting tabs in the current window, either all or highlighted tabs:

☑️ Current Tab as Link
☑️ List of Links
☑️ Task List (for GitHub-Flavored Markdown) ☑️ With Tab Grouping (in Chrome, Edge etc.)

Keyboard Shortcuts

You can add keyboard shortcuts for copying tab(s) as Markdown. By default, Copy as Markdown does not assign any keyboard shortcuts.

Firefox

Please refer to this Firefox Help: https://support.mozilla.org/en-US/kb/manage-extension-shortcuts-firefox

Chrome

The Keyboard Shortcuts of extensions can be found at chrome://extensions/shortcuts URL. (Paste and open the link in the Location Bar).

Known Issues

  • [Chrome] When copying an image, the image code does not include the alternative text of that image. This is due to API restrictions.

Development

Here is the folder structure. The platform-specific folders are used to resolve browser inconsistencies.

src/               # Shared Source Code
  background.js
  ...
chrome/            # Chrome / Chromium files
  dist/            # ../src will be copied here
  mainfest.json
  ...
firefox/           # Firefox Manifest V2 files
  dist/            # ../src will be copied here
  mainfest.json
  background.html  # Loads ESModule
  ...
firefox-mv3/       # Firefox Manifest V3 files
  dist/            # ../src will be copied here
  mainfest.json
  ...
e2e/               # E2E Tests
compile.sh         # Copies src/**/* to <platform>/dist/

Install dependencies

npm install -g web-ext
npm install

Debugging

Since the source code is copied to platform-specific folders by compile.sh, it is recommended to use the auto-reload test script.

npm debug-chrome
npm debug-firefox
npm debug-firefox-mv3

For manual debugging without auto-reload:

  • Chrome: [Window] Menu -> Extensions -> Load unpacked extension
  • Firefox: [Tools] Menu -> Add-ons -> [Gear] Icon -> Debug Add-ons -> Load Temporary Add-on

Debug with Firefox XPI Package

To debug some behaviors such as Firefox restarts (for example, are context menus installed properly), it is necessary to build an XPI package and install it on Firefox. Temporary Add-Ons won't be enough because they get uninstalled after Firefox quits.

Firefox checks the signature when installing XPI. To do so,

  1. Grab API keys from Firefox Add-On
  2. Bump version in manifest.json. Note that AMO only accepts version numbers in X.Y.Z format where all 3 segments are numbers without zero prefixes.
  3. Run:
    web-ext sign --channel=unlisted --api-key=... --api-secret=...

It'll create an XPI that is signed with your Firefox Add-Ons account. The file will also be uploaded to Add-On Developer Hub as unlisted.

Note that Firefox Add-On keeps track of all the versions that have ever been uploaded, including 'self-distributed' (channel=unlisted).

See https://extensionworkshop.com/documentation/develop/getting-started-with-web-ext/

Unit Tests

Unit tests are written in mocha, ./test/**/*.test.js.

To run, use npm test.

E2E Tests

Using Selenium (Java). Please refer to e2e/ folder.

QA

There is a qa.html that includes various edge test cases. Open it in the browser, then try Copy as Markdown with the content in it.

License

See MIT-LICENSE.txt

copy-as-markdown's People

Contributors

andreoliwa avatar dependabot[bot] avatar gitoffthelawn avatar itechbear avatar martinnowak avatar matir avatar networm avatar yorkxin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

copy-as-markdown's Issues

Get current tab with new API instead of tabs.getSelected()

(Same issue in yorkxin/git-io-shortener#5)

chrome.tabs.getSelected() is deprecated since Chrome 16. It might be removed sooner or later.

The methods getAllInWindow() and getSelected() have been deprecated. To get details about all tabs in the specified window, use chrome.tabs.query() with the argument {'windowId': windowID}. To get the tab that is selected in the specified window, use chrome.tabs.query() with the argument {'active': true}.

So we should use chrome.tabs.query({active: true}, function() {...} );

http://code.google.com/chrome/extensions/tabs.html#method-query

Per-site link formatting

Problem

Personally I use this extension a lot for aggregating pull requests.

When copying with GitHub issues, we get string like this:

* [Web extension by chitsaou · Pull Request #48 · chitsaou/copy-as-markdown](https://github.com/chitsaou/copy-as-markdown/pull/48)

result is:

For GitHub, instead of links, we can also copy title only -- GitHub will handle link referencing automatically:

* Web extension by chitsaou · Pull Request #48 · chitsaou/copy-as-markdown

becomes

  • Web extension by chitsaou · Pull Request #48 · chitsaou/copy-as-markdown

But the string itself can be reformatted to make it look better:

* #48 Web extension by @chitsaou 

becomes

  • #48 Web extension by @chitsaou

Idea

Add a setting to let user customize title style per domain.

Make it per site because usually the title are same under the same domain.

For example:

/(.+) by ([\S]+) · Pull Request (#\d+) · (.+)

replaces to

$3 $1 by @$2 ($4)

Furthermore, it should be able to be imported, so users can "install a plugin" for common sites.

Convert Highlighted Tabs to Markdown

Currently it only supports "convert all tabs to markdown."

It would be great if user can select which tabs he want to convert to list of links in Markdown, by highlighting specific tabs (command-click on Mac, or control-click on Windows).

Is it possible to do this through chrome.tabs.query() ?

Could this work with FF bookmarks?

Would it be possible to make this work with bookmarks? For example, I'd like to copy an existing FF link in my bookmark toolbar as Markdown link?

Dropdown menu is all black with a dark KDE/Firefox theme

Summary

The dropdown menu is all black and illegible when used with a KDFE/Firefox dark theme.

Reproduction Steps

Expected Behavior

  • Dropdown box has visible text.

Actual Behavior

  • Dropdown box has invisible text because background and foreground are both black.

Reproducible Environment

  • Browser (Version): Firefox 59.0.2
  • Operating System (Version): Linux kernel 4.14.31-1-MANJARO
    DISTRIB_ID=ManjaroLinux
    DISTRIB_RELEASE=17.1.7
    DISTRIB_CODENAME=Hakoila
    DISTRIB_DESCRIPTION="Manjaro Linux"
  • System Language: English en_IN
  • Example Webpage (if applicable): see attached screenshot below.

Firefox version

Firefox version is now implemented on firefox branch under src-fx directory.

Features:

[x] Copy all tabs of current window as a Markdown list.
[x] Right click on anywhere of a page and copy the page title with URL as Markdown.
[x] Right click on a link and copy it as Markdown.
[x] Right click on an image and copy it as Markdown.
[ ] When copying an Image, if it is wrapped by a link, then the copied Markdown should also include that link.
[ ] Context Menu Icon.
[ ] Dynamic context menu item titles.
[ ] A dropdown menu when clicking the Copy as Markdown browser button, like Chrome version. (Requires ui/button/toggle API, available from Firefox 30)

Direct context menu if there's only one option

What an awesome extension! I use it via a context menu and this is what I see 99% of the time as I'm generally interested only in full page titles:

image

This means that I need to hover over the top-level menu item, move my cursor to the right and select the single option. Would it be possible to somehow make the top-level item do the copy already if there's just a single nested item?

I realize that there are situations where there are more nested items, in which case they would stay. For example:

image

Right-click context menu not available in Chrome

Summary

Right click context menu not available in latest version of Chrome

Reproduction Steps

  • Select some text on a page
  • Right click on the selection to use right-click context menue

Expected Behavior

Right-click context menu is shown

Actual Behavior

Right-click context menu not available in menu

Reproducible Environment

  • Browser (Version): Google Chrome Version 72.0.3590.0 (Official Build) dev (64-bit)
  • Operating System (Version): Mac OS X 10.12.6
  • System Language: English
  • Example Webpage (if applicable):

screen shot 2018-10-30 at 11 07 29

Extending Firefox functionality

Hi,

I'd like to copy articles and automatically include links as markdown (italics, bolds, etc. would be nice as well).

I can implement the logic myself, but could you point me in the right direction? Which files would I need to edit to create a button on right click, where do I need to put my logic and so on.

Thanks

Keyboard shortcuts (other than activating extension) don't work (OSX at least)

Used to work. Upgraded today and now they don't. Clicking the buttons themselves still works. I was wrong, the buttons don't work either :/

EDIT: It seems that the buttons work until you set up a keyboard shortcut and try to use it, then the keyboard shortcut does nothing and the buttons also cease to do anything. Uninstalling and reinstalling the extension gets you back to square one, but adding shortcuts again causes it to get stuck.

Escape characters are being included in titles

I think this is new with Version: 1.1.0, Updated: January 11, 2016. When you use it on a page with underscores or brackets (probably other chars), the backslash appears in the title when it shouldn't, e.g. a page with the title [a_b] is being copied as [\[a\_b\]](http://example.com)

Copy as Markdown not copying from addons.mozilla.org (AMO)

I recall that when AMO tightened its CSP a few months ago, a variety of extensions became non-applicable to AMO – washing machine, for example:

Today I was surprised by Copy as Markdown (and Link Text and Location Copier) not working at AMO. Surprised because I'm an extremely frequent user of Copy as Markdown, and I must have copied titles and URLs from AMO pages on hundreds or thousands of occasions in recent months, and I don't recall performing the copies without Copy as Markdown.

Am I going mad? (Has the extension never worked with the the increased CSP at AMO?)

I'm aware of WebExtensions APIs and so on, just surprised by the non-function today.


Using Waterfox, if that's relevant. Recently updated to 56.2.0.31 on FreeBSD-CURRENT.

Keyboard shortcut

As allenlinli recommended, it would be good to let user specify a keyboard shortcut to copy the markdown code of current page.

As of Chrome 22, in the Extensions page, user can configure keyboard shortcuts for commands of Extensions. So I think the only thing to implement is to let Chrome know there is such a command that can be bounded with a keyboard shortcut.

Close the popup box automatically

It would be nice to close the popup automatically after a short timeout to avoid the unnecessary extra click.
The current "copied!" message could be replaced by highlighting the button.

Right-click context menu not available in Chrome

This is a follow up to #65 (comment) because I couldn't re-open that issue.

Summary

Per #65

Reproduction Steps

Per #65

Expected Behavior

Per #65

Actual Behavior

Per #65

Reproducible Environment

  • Browser (Version): Google Chrome Version 78.0.3904.50 (Official Build) beta (64-bit)
  • Operating System (Version): macOS 10.12.6
  • System Language: English
  • Example Webpage (if applicable): n/a

Popup / Command does not work when background (event) page is inactive

Description

Event page will become inactive, causing Popup and Command (keyboard shortcut) not working.

Reproduce

  1. Install the extension.
  2. Leave it for a while until it shows Background page (Inactive)

screen shot 2017-09-03 at 12 12 48

  1. Try click popup icon -> All Tabs, or hit keyboard shortcut

Expected

  • It copies to clipboard
  • It shows a badge on toolbar icon

Actual

  • It does not show badge
  • Clipboard not copied

Reason

Copy link doesn't fetch title

I am happy user of copy-as-org-mode. But since I can't use it in Quantum. I use copy-as-markdown to my org-mode buffer than invoke my function to transform the link to org-mode.

But, I can have title.
When I use copy-as-org-mode, I often copy link in SO questions ( I can have the title, even I copy the link of the question) . But with copy-as-markdown, I get no-title.

e.g

When I copied this link
2018-02-26-19 20 16

I get

[(No Title)](https://emacs.stackexchange.com/questions/33380/cant-set-default-servers-in-erc-layer)

Expected output

[Can't set default servers in ERC layer](https://emacs.stackexchange.com/questions/33380/cant-set-default-servers-in-erc-layer)

Firefox 58.0.2
Debian 9.2

Support keyboard shortcut for firefox

I use this extension dozen times a day. I saw in README that keybinding/shortcut only works in chrome.

Can we hope adding shortcut support for Firefox ?

Many keyboard binding extension stop working for Quantum. But I find saka works in Quantum. So I think there is still a hope :).

[Suggestion] Better Copy Link Text for Firefox

Hey, I am trying to find an alternative to CoLT since that seems abandoned and I have found you addon.
Would it be possible to implement identical functionality? Like copying just the link text and even better if it can be an option on the main right click. (for example with CoLT I can right click and select Copy Link Text right away or even faster right click and press "x" on the keyboard because the developer added that shortcut)
Thanks

Why does the newest version for Chrome require additional permissions?

Thanks for this extension! It's fantastic.

I just discovered that Chrome has disabled the extension because it now requires additional permissions. I can't tell what permissions are new but Chrome states:

It can now:

  • Read your browsing history
  • Modify data you copy and paste

Which of the permissions is new? Why is the new permission needed? Why is the 'browsing history' permission needed?

I'm assuming the 'copy and paste' permission is just allowing the extension to change the contents of the clipboard/pasteboard – is that correct?

Is there any way to copy multi links at the same time ?

Thanks for this brilliant extension, it saves me a lot of time.

But I usually need to copy multi links at the same time, for example, I want to copy this project's title.

chitsaou / copy-as-markdown

The html code is like this:

<a href="/chitsaou">chitsaou</a> / <a href="/chitsaou/copy-as-markdown">copy-as-markdown</a>

Is it possible to copy this as:

[chitsaou](https://github.com/chitsaou) / [copy-as-markdown](https://github.com/chitsaou/copy-as-markdown)

Go a step further, is there any way to copy selected block to markdown directly?

Sincerely.

Copy current tab URL with text selection as link text

Hi, thank you for the extension, it already covers 90% of the use cases that I have. There's one feature that would cover the remaining 10%.

Summary

What Copy As Markdown currently lets you do is to copy the tab URL with the tab title as a markdown link.

What I'd also like to be able to do:

  1. Select some text
  2. Right click and choose "Copy As Markdown"
  3. Get a markdown link with the selected text as the link text and the destination equal to the URL of the page.

Make list style configurable

Currently the list style used to export links is hardcoded to asterisks. I'd love to see an option to change the style:

  • asterisk (i.e. "* ...", "* ...")
  • dash (i.e. "- ...", "- ...")
  • numbered list (i.e. "1. ...", "1. ...")

Convert web page to markdown

First of all: thank you for your work! 👍
I found your extension because I was looking for a way to convert content from a web page to markdown.

Now I saw that this isn't fully possible yet but it would be really, really nice.
I'm basically looking for the functionality given in http://heckyesmarkdown.com.

Bonus: ideally with the possibility to select content that should be converted and converting to inline images.

Thank you in advance and I hope you have a nice day!

Migrate to WebExtensions

So that code can be shared between Chrome and Firefox, and possibly browsers supporting WebExtensions in the future.

So it can continue work on Firefox since 2018: https://blog.mozilla.org/addons/2016/11/23/add-ons-in-2017/

https://wiki.mozilla.org/WebExtensions

Problems:

  • API incompatibilities, e.g. How to get selection text? How to write to clipboard?
  • Bad code smell in current Chrome version. Should be rewritten first.
    • -> Working on web-extension branch, with Webpack. Looks good.
  • [Need to confirm] There was no module and ES6 support in the current Chrome extension API. Should use Babel? Webpack?
    • -> Webpack looks good. Certain ES6 features supported

Compatibility update for newer Firefox versions

Hi

I love this extension and use it routinely. I noticed that it is marked as a "Legacy" extension for Firefox. Do you have plans to update it to be more compatible with newer Firefox versions?

Make "Escape Markdown code" as an option

See #34

In some rare cases the Markdown code should be escaped, but mostly it is not necessary.

Before we figure out how to handle this smartly, let's make it an option in Extensions page.

[Firefox] Not available in private windows

Hello,

Thanks for your plugin which helps to spend less time when writing in Markdown. I tried it and it works well with normal windows.

However, I often use the private windows in Firefox and the "Copy as markdown" action doesn't show on right click. It appears only in normal windows.

Could you make your plugin also available in private windows?

I'm using Firefox 47.0.1 on Linux.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.