Tags: Calc Extensions Impress Writer
last edited: 2023-01-24
This extension highlights the code snippets over 350 languages in LibreOffice.
To highlight a code snippet, follow these steps:
- Insert a new Text Box (Insert -> Text Box)
- Copy and paste/write your code snippet into the text box (You can choose any fonts based on your preference)
- Select the text box
- Go to Tools -> Highlight Code -> <Language of the code>
That's it. Your code should be colored based on the syntax.
I have tested only a few languages. If you find any bugs, please report them at GiHub Issues.
Note: This extension uses pygments to color the code. Pygments does not highlight some languages properly. Therefore, you may not get the best outcome for some languages. Sorry for the inconvenience.
Requirements (Close all LibreOffice products before installing these dependencies):
libreoffice-script-provider-python(May be optional)
Ubuntu and its derivatives users can install the dependencies using the following commands:
sudo apt install libreoffice-script-provider-python python3-pip
sudo pip3 install pygments
Windows users can install the dependencies using the following commands:
pip3 install pygments
Mac users can install it by following the instructions given at
Windows requires the environment variable:
PYTHONPATH pointing to:
Additional documentation: https://github.com/slgobinath/libreoffice-code-highlighter
- Release Description Compatibility Operating Systems License Release notes
- 1.6 Include a dialog to select custom styles 4.0 Linux, Windows, macOS GPL Download
- 1.5 Fix script error in highlighting text selection in LO Impress 4.0 Linux, Windows, macOS GPL Download
Linux, Windows, macOS
- Support automatic language detection
- Long list of languages are categorized into submenus 4.0 Linux, Windows, macOS GPL Download
Fixed error when coloring Yaml
The pygments' language lexers and styles have some conflicting tokens which caused to runtime errors in this extension. Such bugs are fixed in this release.
See GitHub issue #5Download
Code Highlighter 1.0
Tested with LO 184.108.40.206 4.0 Linux GPL
Supports 379 languages
Tested with LibreOffice Writer, Calc and Impress 220.127.116.11
Jorge Charry Jun 18, 2022, 6:13 PM (11 months ago)
Works perfectly for Fortran!
stefan pofahl Jul 26, 2021, 11:20 AM (22 months ago)
Phyton code seems to be broken.
Installation of LibreOffice was done via PortableApps.com
My Version is: 18.104.22.168 (x86)
pythonscript.py", line 1046, in getScript
storageUri = self.provCtx.getStorageUrlFromPersistentUrl(
File "C:\bin\PortableApps\LibreOfficePortable\App\libreoffice\program\pythonscript.py", line 417, in getStorageUrlFromPersistentUrl
package = self.mapPackageName2Path[ packageName ]
Alex Nov 21, 2020, 2:53 PM (3 years ago)
Works very nicely! Not sure what all the fuss is about here. Simply install the dependencies, then go to the Github releases page, click the oxt file. This should open your LO application and install the extension. Worked flawlessly for me. (v1.6 with LO 7.x on Debian) I’m not to fond of the usability (once you have applied a style, it is not associated with the selected text), but that’s a different story.
G Nov 1, 2020, 7:32 PM (3 years ago)
Worked perfectly for me after renaming it from edb...-whatever-....oxt to simply codehighlighter.oxt and then installing it after taking care of the dependencies
Bruce Oct 23, 2020, 6:12 PM (3 years ago)
Difficult to install, So left it.
Ego Ipse Sep 11, 2020, 3:19 AM (3 years ago)
It doesn't work. LibreOffice 7.0.1
Will Jul 2, 2020, 3:39 PM (3 years ago)
I had to remove the prefix in the installation file name to have it work as intended.
Otherwise very good work !
Alex ndm Jun 24, 2020, 12:29 PM (3 years ago)
Thanks for you work !
If, after installing the python package "pygments" (required by code-highlighter), you get the following error message when trying to run the add-on : "Message: <class 'ImportError'>: No module named 'pygments' ...", it may be because LibreOffice embeds its own version of python, independant of the one running on your system.
In order to properly install pygments to the LibreOffice embedded version of python on linux, you can add it to the folder "/opt/libreofficeX.X/program/python-core-X.X.X/lib/site-packages" where the Xs depend the version of LibreOffice (and its embbeded python) you are running. There should be an equivalent fix for other OSs.
admin Jun 14, 2020, 7:04 PM (3 years ago)
download extension file and rename it to codehighlighter.oxt
FG Jun 9, 2020, 10:29 AM (3 years ago)
Same with me. LibreOffice 22.214.171.124 on Ubuntu, with OpenJDK-JRE and openoffice-java-common.