├── .bumpversion.cfg ├── .gitignore ├── LICENSE.txt ├── MANIFEST.in ├── README.md ├── conda.recipe ├── meta.yaml ├── post-link.bat ├── post-link.sh ├── pre-unlink.bat └── pre-unlink.sh ├── setup.cfg ├── setup.py ├── src └── jupyter_highlight_selected_word │ ├── __init__.py │ └── static │ └── highlight_selected_word │ ├── README.md │ ├── configurator.yaml │ └── main.js └── tox.ini /.bumpversion.cfg: -------------------------------------------------------------------------------- 1 | [bumpversion] 2 | current_version = 0.2.0 3 | commit = True 4 | message = release {new_version} 5 | tag = False 6 | tag_name = {new_version} 7 | 8 | [bumpversion:file:setup.py] 9 | 10 | [bumpversion:file:src/jupyter_highlight_selected_word/__init__.py] 11 | 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | 3 | # Byte-compiled / optimized / DLL files 4 | __pycache__/ 5 | *.py[cod] 6 | 7 | # Unit test / coverage reports 8 | htmlcov 9 | .tox 10 | .coverage 11 | .coverage.* 12 | .cache 13 | nosetests.xml 14 | coverage.xml 15 | 16 | # Sphinx documentation 17 | docs/_build 18 | 19 | .idea 20 | 21 | # pip install 22 | *.egg 23 | *.egg-info 24 | dist 25 | build 26 | eggs 27 | .eggs 28 | parts 29 | bin 30 | var 31 | sdist 32 | develop-eggs 33 | .installed.cfg 34 | lib 35 | lib64 36 | venv*/ 37 | pyvenv*/ 38 | MANIFEST 39 | 40 | # Installer logs 41 | pip-log.txt 42 | 43 | # ipython notebook checkpoints 44 | .ipynb_checkpoints 45 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | This project is licensed under the terms of the Modified BSD License 2 | (also known as New or Revised or 3-Clause BSD), as follows: 3 | 4 | - Copyright (c) 2016, Joshua Cooke Barnes 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, this 11 | list of conditions and the following disclaimer. 12 | 13 | * Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | 17 | * Neither the name of jupyter_highlight_selected_word nor the names of any 18 | contributors may be used to endorse or promote products derived from this 19 | software without specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 22 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 25 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | # explicit includes 2 | include LICENSE.txt 3 | include README.md 4 | include tox.ini 5 | include .bumpversion.cfg 6 | 7 | # directory includes 8 | graft src 9 | 10 | # directory excludes 11 | prune conda.recipe 12 | 13 | # Patterns to exclude from any directory 14 | global-exclude *~ 15 | global-exclude __pycache__ 16 | global-exclude *.py[cod] 17 | global-exclude .git 18 | global-exclude .ipynb_checkpoints 19 | global-exclude .DS_Store 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Highlight selected word 2 | ======================= 3 | 4 | [![Join the chat at https://gitter.im/jcb91/jupyter_highlight_selected_word](https://badges.gitter.im/jcb91/jupyter_highlight_selected_word.svg)](https://gitter.im/jcb91/jupyter_highlight_selected_word?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 5 | [![GitHub issues](https://img.shields.io/github/issues/jcb91/jupyter_highlight_selected_word.svg?maxAge=3600)](https://github.com/jcb91/jupyter_highlight_selected_word/issues) 6 | 7 | [![GitHub tag](https://img.shields.io/github/tag/jcb91/jupyter_highlight_selected_word.svg?maxAge=3600&label=Github)](https://github.com/jcb91/jupyter_highlight_selected_word/tags) 8 | [![PyPI](https://img.shields.io/pypi/v/jupyter_highlight_selected_word.svg?maxAge=3600)](https://pypi.python.org/pypi/jupyter_highlight_selected_word) 9 | [![Anaconda cloud](https://anaconda.org/conda-forge/jupyter_highlight_selected_word/badges/version.svg)](https://anaconda.org/conda-forge/jupyter_highlight_selected_word) 10 | 11 | 12 | This nbextension highlights all instances of the selected word in either the 13 | current cell's editor, or in all cells in the notebook. 14 | It is based on the CodeMirror addon 15 | [Match Highlighter](https://codemirror.net/demo/matchhighlighter.html), 16 | but now uses its own codebase in order to permit matching across multiple 17 | editors. 18 | 19 | There are a few configurable [options](#Options), all of which sit under the 20 | config key `highlight_selected_word` in the `notebook` config section. 21 | 22 | 23 | Installation 24 | ------------ 25 | 26 | `jupyter_highlight_selected_word` is available as part of the 27 | [jupyter_contrib_nbextensions](https://github.com/ipython-contrib/jupyter_contrib_nbextensions) 28 | collection. If you want to install this nbextension without the rest of the 29 | contrib collection, read on. 30 | 31 | To use the nbextension, there are three basic steps: 32 | 33 | 1. First, install the python package: 34 | 35 | pip install jupyter_highlight_selected_word 36 | 37 | Or, __for those using conda__, there is now a recipe provided through the excellent excellent [conda-forge](https://conda-forge.org/) [channel](https://anaconda.org/conda-forge), which also performs the install into the conda env's jupyter data directory, so you can skip step 2. To install the conda recipe, use 38 | 39 | conda install -c conda-forge jupyter_highlight_selected_word 40 | 41 | 2. Next, install javascript files from the python package into a jupyter data 42 | directory. For those using conda, the conda install performs this step 43 | automatically, so you can skip this. 44 | 45 | If you have jupyter version 4.2 or greater, you can install directly 46 | using jupyter: 47 | 48 | jupyter nbextension install --py jupyter_highlight_selected_word 49 | 50 | For jupyter versions before 4.2, you'll need to do a little more work to 51 | find the nbextension's static files. To find the nbextension source 52 | directory, you can use the following one-liner 53 | (for a rather stretched definition of 'line'): 54 | 55 | python -c "import os.path as p; from jupyter_highlight_selected_word import __file__ as f, _jupyter_nbextension_paths as n; print(p.normpath(p.join(p.dirname(f), n()[0]['src'])))" 56 | 57 | then execute 58 | 59 | jupyter nbextension install 60 | 61 | replacing `` with the directory found above. 62 | 63 | 64 | 3. Enable the nbextension, so that it gets loaded automatically in each 65 | notebook: 66 | 67 | jupyter nbextension enable highlight_selected_word/main 68 | 69 | 70 | Options 71 | ------- 72 | 73 | Options are stored in the notebook section of the nbconfig. 74 | The easiest way to configure these is using the 75 | [jupyter_nbextensions_configurator](https://github.com/Jupyter-contrib/jupyter_nbextensions_configurator) 76 | serverextension, but you can also configure them directly with a few lines of 77 | python. 78 | 79 | The available options are: 80 | 81 | * `highlight_selected_word.highlight_across_all_cells` - if `true`, (default) 82 | highlight matches across all cells. If `false`, only matches within the 83 | currently selected cell will be highlighted. 84 | 85 | * `highlight_selected_word.code_cells_only` - Only apply highlights to editors 86 | for Code cells, not, for example, Markdown or Raw cells 87 | 88 | * `highlight_selected_word.highlight_color` - Color used to highlight matching 89 | words in the focused (active) cell 90 | 91 | * `highlight_selected_word.highlight_color_blurred` - Color used to highlight 92 | matching words in blurred (non-active) cells 93 | 94 | * `highlight_selected_word.outlines_only` - Highlight words using just an 95 | outline, rather than the background color. In contrast to the default 96 | background-color highlight, the outline-only is also applied to the 97 | currently-selected word 98 | 99 | * `highlight_selected_word.outline_width` - Width, in pixels, of the outline 100 | used to highlight words when the outline-only setting (above) is selected. 101 | Defaults to 1. 102 | 103 | * `highlight_selected_word.delay` - Wait time (in milliseconds) before 104 | highlighting the matches 105 | 106 | * `highlight_selected_word.words_only` - If true, only highlight matches if the 107 | selected text is a word 108 | 109 | * `highlight_selected_word.highlight_only_whole_words` - Only highlight matches 110 | which are surrounded by non-word characters. This will use the token 111 | `highlight_selected_word.show_token` to identify word characters, if it's 112 | set, otherwise the regular expression `[\w$]` will be used. 113 | 114 | * `highlight_selected_word.show_token` - Token (regex) to identify word 115 | characters, used to determine what to highlight when nothing is selected. 116 | If blank, nothing is highlighted when nothing is selected. 117 | This regex is also used to determine word boundaries for 118 | `highlight_selected_word.highlight_only_whole_words`. 119 | 120 | * `highlight_selected_word.min_chars` - Minimum number of characters that must 121 | be selected for the highlighting behavior to occur 122 | 123 | * `highlight_selected_word.use_toggle_hotkey` - Bind the 124 | `highlight_selected_word.toggle` action to a hotkey. Defaults to `false`. 125 | 126 | * `highlight_selected_word.toggle_hotkey` - Which hotkey to bind to the 127 | `highlight_selected_word.toggle` action (if set to use, see item above). 128 | Defaults to `alt-h` 129 | 130 | * `highlight_selected_word.only_cells_in_scroll` - Only apply highlights to 131 | editors which are visible in the scrolled view. This may offer performance 132 | benefits for larger notebooks, but may be annoying if you're doing a lot of 133 | scrolling :/ 134 | 135 | * `highlight_selected_word.scroll_min_delay` - Minimum delay in ms between 136 | updating highlights on scrolling the notebook (used only if 137 | `highlight_selected_word.only_cells_in_scroll` is `true`). 138 | If set to zero, no update is done on scroll. 139 | 140 | For example, to set the delay to half a second, and limit highlighting to code 141 | cells, we can use the following python snippet: 142 | 143 | ```python 144 | from notebook.services.config import ConfigManager 145 | cm = ConfigManager() 146 | cm.update('notebook', {'highlight_selected_word': { 147 | 'delay': 500, 148 | 'code_cells_only': True, 149 | }}) 150 | ``` 151 | 152 | 153 | Changes 154 | ------- 155 | 156 | ### 0.2.0 157 | 158 | * optionally hide the selections in non-focussed cells (through CSS classes) 159 | * bugfix for overlays not being removed correctly 160 | * alter CSS mechanism, so we create a `