code highlighter Code Highlighter

Tags: Calc Extension Impress Writer

Rating: ★ ☆ ☆ ☆ ☆

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

code highlighter ca7a61dd d3f7 48c6 b4e2 b50b5c31a3d4

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 List

  • 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
  • 1.4 Release 1.4 4.0 Linux, Windows GPL

    Release 1.4

    Download
  • 1.3 Support C++ 4.0 Linux, Windows, macOS GPL

    Support C++

    Download
  • 1.2 - Support automatic language detection
    - Long list of languages are categorized into submenus
    4.0 Linux, Windows, macOS GPL 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.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

Feedback

★ ☆ ☆ ☆ ☆

Post your review

Reviews

  • Will Jul 2, 2020, 3:39 PM (3 hours ago)

    ☆ ☆ ☆ ☆ ☆

    Same as

    https://github.com/slgobinath/libreoffice-code-highlighter/issues/29#issuecomment-635216707

    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 (8 days 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 (18 days ago)

    ★ ☆ ☆ ☆ ☆

    download extension file and rename it to codehighlighter.oxt
    then install

  • FG Jun 9, 2020, 10:29 AM (23 days ago)

    ☆ ☆ ☆ ☆ ☆

    Same with me. LibreOffice 6.4.3.2 on Ubuntu, with OpenJDK-JRE and openoffice-java-common.

  • Fabian Jun 3, 2020, 1:27 AM (30 days 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 (36 days 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

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