Compare commits

...

3 Commits

Author SHA1 Message Date
Laurence Warne 54f2a7e692 Update documentation 5 months ago
Laurence Warne 6593dab643 Fix issue issue with single quote interpolation 5 months ago
Laurence Warne a9d8f5a513 Fix issue with code blocks not copying due to ET parser issue
Co-authored-by: daru <darupeter@pm.me>
5 months ago

@ -14,13 +14,13 @@ Copying to clipboard:
1. Download the script:
```
```bash
wget https://raw.githubusercontent.com/LaurenceWarne/qute-code-hint/master/code_select.py -O ~/.local/share/qutebrowser/userscripts/code_select.py
```
2. In your qutebrowser config file create a new custom group for code:
```
```python
c.hints.selectors["code"] = [
# Selects all code tags whose direct parent is not a pre tag
":not(pre) > code",
@ -30,7 +30,7 @@ c.hints.selectors["code"] = [
3. Bind the userscript using a keybinding of your choice:
```
```python
...
'<ctrl-#>': 'hint code userscript code_select.py',
...
@ -38,13 +38,15 @@ c.hints.selectors["code"] = [
4. Optionally install the python [pyperclip](https://github.com/asweigart/pyperclip) module for better multiline copying:
```
```bash
pip3 install pyperclip --user
# Alternatively for PEP 668 compliance, you can install from your package manager, e.g.
sudo apt install python3-pyperclip
```
Pyperclip doesn't work on wayland so you can use [pyclip](https://github.com/spyoungtech/pyclip) instead:
If you're having issues with `pyperclip`, you can use [pyclip](https://github.com/spyoungtech/pyclip) instead:
```
```bash
pip3 install pyclip
```

@ -19,7 +19,12 @@ else:
def parse_text_content(element):
root = ET.fromstring(element)
# https://stackoverflow.com/a/35591507/15245191
magic = '''<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [
<!ENTITY nbsp ' '>
]>'''
root = ET.fromstring(magic + element)
text = ET.tostring(root, encoding="unicode", method="text")
text = html.unescape(text)
return text
@ -40,7 +45,7 @@ def main():
pyperclip.copy(code_text)
send_command_to_qute(
"message-info 'copied to clipboard: {info}{suffix}'".format(
info=code_text.splitlines()[0],
info=code_text.splitlines()[0].replace("'", "\""),
suffix="..." if len(code_text.splitlines()) > 1 else ""
)
)

Loading…
Cancel
Save