Giter Club home page Giter Club logo

qute-code-hint's Introduction

Qute Code Hint

A small qutebrowser userscript for copying code snippets on web pages to the clipboard.

Example

Hinting: Hinting

Copying to clipboard: Copying

Installation

  1. Download the script:
wget https://raw.githubusercontent.com/LaurenceWarne/qute-code-hint/master/code_select.py -O ~/.local/share/qutebrowser/userscripts/code_select.py
  1. In your qutebrowser config file create a new custom group for code:
c.hints.selectors["code"] = [
    # Selects all code tags whose direct parent is not a pre tag
    ":not(pre) > code",
    "pre"
]
  1. Bind the userscript using a keybinding of your choice:
...
'<ctrl-#>': 'hint code userscript code_select.py',
...
  1. Optionally install the python pyperclip module for better multiline copying:
pip3 install pyperclip --user
# Alternatively for PEP 668 compliance, you can install from your package manager, e.g.
sudo apt install python3-pyperclip

If you're having issues with pyperclip, you can use pyclip instead:

pip3 install pyclip

Multiline Copying

Without pyperclip/pyclip the default behaviour for code snippets spanning multiple lines is to join them all on one line, with semicolons separating the previously seperate lines.

qute-code-hint's People

Contributors

laurencewarne avatar lucastavaresa avatar

Stargazers

 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

Forkers

thisleejones

qute-code-hint's Issues

Pyperclip possibly no longer needed

Not sure if this is true across different version of Qutebrowser, but I was able to copy multiline code blocks without Pyperclip simply by commenting out the line:

        code_text = re.sub("(\n)+", delimiter, code_text)

Can't copy certain code from sites

I wasn't able to copy certain codeblocks from sites like:
https://www.npmjs.com/package/qutejs
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-list/

Apparently it was ElementTree parser problem

After adding this to script, I can now copy

def parse_text_content(element):
    magic = '''<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [
                <!ENTITY nbsp ' '>
                ]>'''  # You can define more entities here, if needed
    root = ET.fromstring(magic + element)
    text = ET.tostring(root, encoding="unicode", method="text")
    text = html.unescape(text)
    return text

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.