Posts Tagged ‘syntax highlighting’

syntax highlight your code and paste in Word

April 14, 2016 1 comment

At you can find a nice syntax highlighter. It supports Python, HTML, Java, and several other languages. The rendered output can be copy-pasted to a Word document and it’ll look the same and remains editable in Word. Pretty cool.

It’s also useful if you want to make a screenshot of the syntax highlighted code. Here is an example:


Thanks to Peter F. for the link.


HTML: add syntax-highlight to textarea

September 26, 2013 1 comment

You have an HTML form with a textarea where you want to accept some source code. You want to turn this simple textarea into a fancy input area that adds syntax highlighting.

I tried EditArea, and it suits my needs. See this SO page for more alternatives.


EditArea is a free javascript editor for source code. This editor is designed to edit souce code files in a textarea. The main goal is to allow text formatting, search and replace and real-time syntax highlight (for not too heavy text).” (source)

For Python support, I had to add these lines to the HTML source:

<script language="javascript" type="text/javascript" src="../editarea/edit_area/edit_area_full.js"></script>
<script language="javascript" type="text/javascript">
    id : "src_input"       // textarea id
    ,syntax: "css"          // syntax to be uses for highgliting
    ,start_highlight: true      // to display with highlight mode on start-up
    ,syntax: "python"
    ,replace_tab_by_spaces: 4

Related work

  • Ace (it seems a more professional solution)

Syntax-highlighted “cat” in command line

May 29, 2013 1 comment

You have a source code whose content you want to display on the stdout. The natural way to do that is the “cat” command but it’s monochrome. How to get a syntax-highlighted output?

Use pygments. If you install it (“sudo apt-get install python-pygments“), you will have a command called “pygmentize” that you can invoke from the command line.


pygmentize -f terminal256 -O style=native -g

Tip: put an alias on it.

alias pcat="pygmentize -f terminal256 -O style=native -g"

There are different styles available, see “pygmentize -L” for a list.

Tip from here. Discussion @reddit here.


Insert syntax highlighted source in Powerpoint

August 7, 2012 1 comment

You want to have syntax highlighted source in Powerpoint.

First, create an RTF file from the source:

pygmentize -f rtf -o hello.rtf

Open the RTF file in Word, select the source, then insert it in Powerpoint.

I made a basic script to automate the conversion. Usage:


The script is available here.

Update (20131030)
What if you want to insert colorized code in HTML?

$ pygmentize -f html -o index.html
$ pygmentize -f html -S default >style.css

The parameter of -S (here: default) is the name of the color scheme. Available color schemes:

>>> from pygments.styles import get_all_styles
>>> list(get_all_styles())
['monokai', 'manni', 'rrt', 'perldoc', 'borland', 'colorful', 'default', 'murphy', 'vs', 'trac', 'tango', 'fruity', 'autumn', 'bw', 'emacs', 'vim', 'pastie', 'friendly', 'native']

Then include style.css in index.html:

    <link rel="stylesheet" type="text/css" href="style.css">

Add syntax highlighting to “less”

August 10, 2011 Leave a comment

This entry is based on this post: Redirecting wget to STDOUT – now with Syntax Highlighting.

Less is a program similar to more, but it allows backward movement in the file as well as forward movement. Example:

cat big_text_file.txt | less

If you have vim installed, it comes with a script called that acts as a replacement of less providing syntax highlighting. Here is how to use it:

$ locate
$ sudo ln -s /usr/share/vim/vim73/macros/ /usr/bin/vless
$ curl | vless
Categories: bash, vim Tags: , ,