Syntax highlighting

I’ve been writing a text document, where I want to paste an excerpt of a shell script. I want to put it in a frame as a separate “figure”, referred to in the text as “Box ##”. To make it clearer to the reader, I want to have the appropriate syntax highlighting. How to do it?

Searching the topic returns solutions for Notepad++. The closest relative of it for Linux is Notepadqq, which, however, does not seem to have this functionality.

I finally found a solution, the site To HTML, which offers “online syntax highlighting for the masses”. It does exactly what I want it to do. For example, pasting the SlackBuild for Amplicon, gives the following colouring in HTML format:

<pre style='color:#000000;background:#ffffff;'><span style='color:#008000; '>#!</span><span style='color:#007997; '>/bin/sh</span>

<span style='color:#008000; '># Slackware build script for amplicon</span>

<span style='color:#008000; '># Copyright 2011-2016 Petar Petrov </span><span style='color:#7144c4; '>slackalaxy ат gmail дот com</span>
<span style='color:#008000; '># All rights reserved.</span>
<span style='color:#008000; '>#</span>
<span style='color:#008000; '># Redistribution and use of this script, with or without modification, is</span>
<span style='color:#008000; '># permitted provided that the following conditions are met:</span>
<span style='color:#008000; '>#</span>
<span style='color:#008000; '># 1. Redistributions of this script must retain the above copyright</span>
<span style='color:#008000; '>#    notice, this list of conditions and the following disclaimer.</span>
<span style='color:#008000; '>#</span>
<span style='color:#008000; '>#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED</span>
<span style='color:#008000; '>#  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF</span>
<span style='color:#008000; '>#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO</span>
<span style='color:#008000; '>#  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,</span>
<span style='color:#008000; '>#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,</span>
<span style='color:#008000; '>#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;</span>
<span style='color:#008000; '>#  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,</span>
<span style='color:#008000; '>#  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR</span>
<span style='color:#008000; '>#  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF</span>
<span style='color:#008000; '>#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>

<span style='color:#800080; font-weight:bold; '>PRGNAM</span><span style='color:#0000ff; '>=</span>amplicon
<span style='color:#800080; font-weight:bold; '>VERSION</span><span style='color:#0000ff; '>=</span><span style='color:#800080; font-weight:bold; '>${</span>VERSION<span style='color:#0000ff; '>:</span>-b09<span style='color:#0000ff; font-weight:bold; '>.</span><span style='color:#800000; '>1</span><span style='color:#800080; font-weight:bold; '>}</span>
<span style='color:#800080; font-weight:bold; '>BUILD</span><span style='color:#0000ff; '>=</span><span style='color:#800080; font-weight:bold; '>${</span>BUILD<span style='color:#0000ff; '>:</span>-<span style='color:#800000; '>2</span><span style='color:#800080; font-weight:bold; '>}</span>
<span style='color:#800080; font-weight:bold; '>TAG</span><span style='color:#0000ff; '>=</span><span style='color:#800080; font-weight:bold; '>${</span>TAG<span style='color:#0000ff; '>:</span>-_SBo<span style='color:#800080; font-weight:bold; '>}</span>

<span style='color:#800080; font-weight:bold; '>ARCH</span><span style='color:#0000ff; '>=</span>noarch

<span style='color:#800080; font-weight:bold; '>CWD</span><span style='color:#0000ff; '>=</span><span style='color:#0000ff; '>$(</span><span style='color:#000088; font-weight:bold; '>pwd</span><span style='color:#0000ff; '>)</span>
<span style='color:#800080; font-weight:bold; '>TMP</span><span style='color:#0000ff; '>=</span><span style='color:#800080; font-weight:bold; '>${</span>TMP<span style='color:#0000ff; '>:</span>-<span style='color:#40015a; '>/tmp/SBo</span><span style='color:#800080; font-weight:bold; '>}</span>
<span style='color:#800080; font-weight:bold; '>PKG</span><span style='color:#0000ff; '>=</span><span style='color:#800080; font-weight:bold; '>$TMP</span><span style='color:#40015a; '>/package-</span><span style='color:#800080; font-weight:bold; '>$PRGNAM</span>
<span style='color:#800080; font-weight:bold; '>OUTPUT</span><span style='color:#0000ff; '>=</span><span style='color:#800080; font-weight:bold; '>${</span>OUTPUT<span style='color:#0000ff; '>:</span>-<span style='color:#40015a; '>/tmp</span><span style='color:#800080; font-weight:bold; '>}</span>

<span style='color:#000088; font-weight:bold; '>set</span> <span style='color:#0000ff; font-weight:bold; '>-e</span>

rm -rf <span style='color:#800080; font-weight:bold; '>$PKG</span>
mkdir <span style='color:#0000ff; font-weight:bold; '>-p</span> <span style='color:#800080; font-weight:bold; '>$TMP</span> <span style='color:#800080; font-weight:bold; '>$PKG</span> <span style='color:#800080; font-weight:bold; '>$OUTPUT</span>
<span style='color:#000088; font-weight:bold; '>cd</span> <span style='color:#800080; font-weight:bold; '>$TMP</span>
rm -rf <span style='color:#800080; font-weight:bold; '>$PRGNAM-</span><span style='color:#800080; font-weight:bold; '>$VERSION</span>
mkdir <span style='color:#800080; font-weight:bold; '>$PRGNAM-</span><span style='color:#800080; font-weight:bold; '>$VERSION</span>
<span style='color:#000088; font-weight:bold; '>cd</span> <span style='color:#800080; font-weight:bold; '>$PRGNAM-</span><span style='color:#800080; font-weight:bold; '>$VERSION</span>
gunzip <span style='color:#0000ff; font-weight:bold; '>-c</span> <span style='color:#800080; font-weight:bold; '>$CWD</span><span style='color:#40015a; '>/Amplicon-Linux-</span><span style='color:#800080; font-weight:bold; '>$VERSION.py.gz</span> <span style='color:#e34adc; '>></span> <span style='color:#800080; font-weight:bold; '>$PRGNAM.py</span>
unzip <span style='color:#800080; font-weight:bold; '>$CWD</span><span style='color:#40015a; '>/AmpliconManualb06.zip</span>

<span style='color:#008000; '># </span><span style='color:#ffffff; background:#808000; '>Fix the window size</span>
<span style='color:#000088; font-weight:bold; '>sed</span> <span style='color:#0000e6; '>"</span><span style='color:#0000ff; font-weight:bold; '>s</span><span style='color:#0000e6; '>:</span><span style='color:#0000e6; '>root</span><span style='color:#0000ff; '>.</span><span style='color:#0000e6; '>maxsize</span><span style='color:#0000ff; '>(</span><span style='color:#0000e6; '>965,570</span><span style='color:#0000ff; '>)</span><span style='color:#0000e6; '>:</span><span style='color:#0000e6; '>root.maxsize(1400,800)</span><span style='color:#0000e6; '>:</span><span style='color:#0000e6; '>"</span> -i <span style='color:#800080; font-weight:bold; '>$PRGNAM.py</span>

install -D -m755 <span style='color:#800080; font-weight:bold; '>$PRGNAM.py</span> <span style='color:#800080; font-weight:bold; '>$PKG</span><span style='color:#40015a; '>/usr/bin</span><span style='color:#40015a; '>/</span><span style='color:#800080; font-weight:bold; '>$PRGNAM.py</span>

mkdir <span style='color:#0000ff; font-weight:bold; '>-p</span> <span style='color:#800080; font-weight:bold; '>$PKG</span><span style='color:#40015a; '>/usr/share</span><span style='color:#40015a; '>/</span><span style='color:#0000ff; '>{</span>applications,pixmaps<span style='color:#0000ff; '>}</span>
cp <span style='color:#800080; font-weight:bold; '>$CWD</span><span style='color:#40015a; '>/</span><span style='color:#800080; font-weight:bold; '>$PRGNAM.desktop</span> <span style='color:#800080; font-weight:bold; '>$PKG</span><span style='color:#40015a; '>/usr/share/applications</span><span style='color:#40015a; '>/</span>
cp <span style='color:#800080; font-weight:bold; '>$CWD</span><span style='color:#40015a; '>/</span><span style='color:#800080; font-weight:bold; '>$PRGNAM.png</span> <span style='color:#800080; font-weight:bold; '>$PKG</span><span style='color:#40015a; '>/usr/share/pixmaps</span>

mkdir <span style='color:#0000ff; font-weight:bold; '>-p</span> <span style='color:#800080; font-weight:bold; '>$PKG</span><span style='color:#40015a; '>/usr/doc</span><span style='color:#40015a; '>/</span><span style='color:#800080; font-weight:bold; '>$PRGNAM-</span><span style='color:#800080; font-weight:bold; '>$VERSION</span>
cp <span style='color:#0000ff; font-weight:bold; '>-a</span> AmpliconManualVersion2<span style='color:#0000ff; font-weight:bold; '>.</span>doc <span style='color:#800080; font-weight:bold; '>$PKG</span><span style='color:#40015a; '>/usr/doc</span><span style='color:#40015a; '>/</span><span style='color:#800080; font-weight:bold; '>$PRGNAM-</span><span style='color:#800080; font-weight:bold; '>$VERSION</span>
cat <span style='color:#800080; font-weight:bold; '>$CWD</span><span style='color:#40015a; '>/</span><span style='color:#800080; font-weight:bold; '>$PRGNAM.SlackBuild</span> <span style='color:#e34adc; '>></span> <span style='color:#800080; font-weight:bold; '>$PKG</span><span style='color:#40015a; '>/usr/doc</span><span style='color:#40015a; '>/</span><span style='color:#800080; font-weight:bold; '>$PRGNAM-</span><span style='color:#800080; font-weight:bold; '>$VERSION</span><span style='color:#40015a; '>/</span><span style='color:#800080; font-weight:bold; '>$PRGNAM.SlackBuild</span>
cat <span style='color:#800080; font-weight:bold; '>$CWD</span><span style='color:#40015a; '>/References</span> <span style='color:#e34adc; '>></span> <span style='color:#800080; font-weight:bold; '>$PKG</span><span style='color:#40015a; '>/usr/doc</span><span style='color:#40015a; '>/</span><span style='color:#800080; font-weight:bold; '>$PRGNAM-</span><span style='color:#800080; font-weight:bold; '>$VERSION</span><span style='color:#40015a; '>/References</span>

mkdir <span style='color:#0000ff; font-weight:bold; '>-p</span> <span style='color:#800080; font-weight:bold; '>$PKG</span><span style='color:#40015a; '>/install</span>
cat <span style='color:#800080; font-weight:bold; '>$CWD</span><span style='color:#40015a; '>/slack-desc</span> <span style='color:#e34adc; '>></span> <span style='color:#800080; font-weight:bold; '>$PKG</span><span style='color:#40015a; '>/install/slack-desc</span>
cat <span style='color:#800080; font-weight:bold; '>$CWD</span><span style='color:#40015a; '>/doinst.sh</span> <span style='color:#e34adc; '>></span> <span style='color:#800080; font-weight:bold; '>$PKG</span><span style='color:#40015a; '>/install/doinst.sh</span>

<span style='color:#000088; font-weight:bold; '>cd</span> <span style='color:#800080; font-weight:bold; '>$PKG</span>
<span style='color:#40015a; '>/sbin/makepkg</span> -l y <span style='color:#0000ff; font-weight:bold; '>-c</span> n <span style='color:#800080; font-weight:bold; '>$OUTPUT</span><span style='color:#40015a; '>/</span><span style='color:#800080; font-weight:bold; '>$PRGNAM-</span><span style='color:#800080; font-weight:bold; '>$VERSION-</span><span style='color:#800080; font-weight:bold; '>$ARCH-</span><span style='color:#800080; font-weight:bold; '>$BUILD</span><span style='color:#800080; font-weight:bold; '>$TAG.</span><span style='color:#800080; font-weight:bold; '>${</span>PKGTYPE<span style='color:#0000ff; '>:</span>-tgz<span style='color:#800080; font-weight:bold; '>}</span>
</pre>
<!--Created using ToHtml.com on 2019-08-04 06:50:43 UTC -->

When pasted into a text editor, such as LibreOffice Writer, results in coloured text. Great!

This entry was posted in office, system and tagged , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s