LibreOffice Logo LibreOffice Logo Extensions, Documentation and Templates repository

code highlighter Code Highlighter

This extension highlights the code snippets over 350 languages in LibreOffice.

★ ★ ☆ ☆ ☆
Calc Extensions Impress Writer
Download latest

latest release: 2023-11-27 20:50:20

Description

To highlight a code snippet, follow these steps:

  1. Insert a new Text Box (Insert -> Text Box)
  2. Copy and paste/write your code snippet into the text box (You can choose any fonts based on your preference)
  3. Select the text box
  4. 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):

  • Python 3
  • python3-pygments
  • 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

  • https://github.com/slgobinath/libreoffice-code-highlighter/issues/10
  • https://github.com/slgobinath/libreoffice-code-highlighter/issues/14

Windows requires the environment variable: PYTHONPATH pointing to: C:\Users\<UserName>\AppData\Local\Programs\Python\Python<PythonVersion>\Lib\site-packages

 
You may face Scripting Framework error in your system. It happens if LibreOffice is using a different (most probably an internal package) Python. Please check the following Git Hub issues to resolve them.
  • https://github.com/slgobinath/libreoffice-code-highlighter/issues/25
  • https://github.com/slgobinath/libreoffice-code-highlighter/issues/29
  • https://github.com/slgobinath/libreoffice-code-highlighter/issues/26

Additional documentation: https://github.com/slgobinath/libreoffice-code-highlighter

Homepage: https://github.com/slgobinath/libreoffice-code-highlighter

Release Description Compatibility Operating Systems License Release notes  
1.2 - Support automatic language detection
- Long list of languages are categorized into submenus
4.0 Linux, Windows, macOS GPL Download
1.0 Code Highlighter 1.0
379 Languages
Tested with LO 5.3.2.2
4.0 Linux GPL Supports 379 languages

Tested with LibreOffice Writer, Calc and Impress 5.3.2.2

Tested languages:

Java
Python
C
Download
1.1 Fixed error when coloring Yaml 4.0 Linux GPL 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 #5
Download
1.5 Fix script error in highlighting text selection in LO Impress 4.0 Linux, Windows, macOS GPL Download
1.4 Release 1.4 4.0 Linux, Windows GPL Release 1.4 Download
1.6 Include a dialog to select custom styles 4.0 Linux, Windows, macOS GPL Download
1.3 Support C++ 4.0 Linux, Windows, macOS GPL Support C++ Download
Show more

Feedback

★ ★ ☆ ☆ ☆

Post your review

You cannot post reviews until you have logged in. Login Here.

Reviews

  • Fabian Jun 3, 2020, 1:27 AM (4 years ago)

    ★ ☆ ☆ ☆ ☆

    Seems not to work under LibreOffice 6.4.3.2...
    Installation runs fine, but it keeps throwing errors when I'm trying to use it.

  • Jim May 28, 2020, 4:47 AM (4 years ago)

    ★ ☆ ☆ ☆ ☆

    Tried to download and kept getting this error.
    Failed to register package for vnd.sun.star.expand:$UNO_USER_PACKAGES_CACHE/uno_packages/lu11512q61hem.tmp_/ea4db15f_codehighlighter.oxt/python

    • Gael Langlais Feb 1, 2021, 3:54 PM (4 years ago)

      Hi Jim,

      The following did it for my:
      sudo apt-get install python3-pip
      sudo -H pip3 install --system pygments
      sudo apt install libreoffice-script-provider-python

RSS feed for reviews on this page | RSS feed for all reviews