Blog Friends RSS About

Zotero: How to highlight code in note?

11 August, 2016

This is a revised blog, see the original blog.

1. install highlight

2. copy the following code into your clipboard (ctrl+v)

Purpose: It’s the material, which will be highlighted.

# It's ruby code
class User
  def foo
    puts "foo"

  def bar
    puts "bar"

3. execute the following commandline in your Iterm2(or Terminal), it will generate highlighted html code in your clipboard.

{query} is a placehold, please replace it with language, such as ruby, python, java.

export PATH=$PATH:/usr/local/bin
pbpaste | highlight --fragment --enclose-pre --inline-css  --syntax {query} --font Monaco --out-format html --style solarized-dark | pbcopy

What do those options mean?

# -O, --out-format=<format>      output file in given format, <format>=[html, xhtml latex, tex      
# -S, --syntax=<type>            specify type of source code
# -f, --fragment                 omit document header and footer
# -k, --font=<font>              set font (specific to output format)
# -s, --style=<style>            set colour style (see -w)   
#     --enclose-pre              enclose fragmented output with pre tag
#     --inline-css               output CSS within each tag (verbose output)

highlight java code

export PATH=$PATH:/usr/local/bin
pbpaste | highlight --fragment --enclose-pre --inline-css  --syntax java --font Monaco --out-format html --style solarized-dark | pbcopy

highlight ruby code

export PATH=$PATH:/usr/local/bin
pbpaste | highlight --fragment --enclose-pre --inline-css  --syntax ruby --font Monaco --out-format html --style solarized-dark | pbcopy

4. insert html code into your Zotero note.

click html button

insert html code from your clipboard (ctrl+v), save it!

5. it works.


No need to hack Zotero config. It’s much better.