LibreOffice Logo LibreOffice Logo Extensions, Documentation and Templates repository

icon 42 Code Highlighter 2

Code snippet highlighter for LibreOffice.

★ ★ ★ ★ ★
Download latest

latest release: 2024-08-27 15:27:51

Description

Code Highlighter 2 allows syntax highlighting over 350 languages in LibreOffice.

Code Highlighter 2 is a fork of Code Highlighter, originally created by slgobinath but no more maintained.

Usage

  • Open a LibreOffice document.
  • Copy and paste the code snippet where you want it:
    • Writer: either in a text frame (preferred option), in a text box, in a table cell or as plain text;
    • Calc: either in a cell or in a text box;
    • Impress and Draw: in a text box.
  • Select the text or the object containing the code snippet.
  • Format -> Code Highlighter 2 -> Highlight Code:
    • in the dialog, select the language and style.
  • Format -> Code Highlighter 2 -> Highlight Code (previous settings):
    • does not open a dialog, but applies previous settings (persistent also between restarts of LO).
  • Format -> Code Highlighter 2 -> Update selection:
    • update an already highlighted snippet using the formatting informations stored with it.

Tips

  • Multiselection is supported: you can select several code snippets at the same time, even from different languages (choose "automatic" in this last case).
  • Not all language aliases that are valide names for Code Highlighter 2 appear in the option dialog: if you don't find a language, try anyway to type its name in the combobox (try for example with "R" or with "Pascal").
  • Click the "More..." button to access line numbers options or character styles options.
  • Uncheck line numbering option to remove unwanted line numbers, due for example to copy-pasted code.
  • The extension contains two styles that are not part of Pygments: libreoffice-classic and libreoffice-dark, that make use of LibreOffice IDE color schemes (classic mode and dark mode). Code Highlighter also adds a "LibreOffice Basic" language, which is not a Pygments lexer but a convenient shortcut to VB.net lexer, which is perfect for parsing LOBasic.

General behaviour

  • Highlighting is applied to the selected object, that can be plain text, text frame, text shape, text table cell or calc cell.
  • Highlight properties are hard-formatted for each token, parsed according to the choosen Pygments lexer (aka coding language). If someone prefers instead to make use of character styles, select the corresponding option in the dialog box (from v2.3.0, Writer only).
  • When cursor is inside a text shape or a Calc cell, highlighting is applied to the whole shape or cell even if only a part of the text is selected.
  • When cursor is inside a text frame, a text table cell or an already highlighted plain text*, highlighting is only applied to the selected text if any, otherwise to the whole frame, cell or plain text snippet.
  • When highlighting applies to the selected text, it formats the entire paragraphs, even if selection starts after the paragraph start or ends before paragraph end, unless the selection is an inline snippet.
  • Choosing "Update selection", the program will update highlighted code keeping the already applied options. If nothing is selected and the cursor is inside an already highlighted block, the whole block will be updated*.

* To allow code update, Code Highlighter 2 stores the formatting options in the document as User Defined Attributes. If you're not comfortable with that, you can disable it by setting the 'StoreOptionsWithSnippet' option to 0 in advanced options (Options-> Advanced-> Open Expert Configuration-> ooo.ext.code-highlighter.Registry).

Dependencies

Linux users may need to first install the LibreOffice script provider for python.

For Ubuntu and derivatives, close all the LibreOffice products and do

sudo apt-get install libreoffice-script-provider-python

Other Linux systems may not need this package. If you encounter any problems after installing the extension, please check whether you have any similar package.

Any problems?

If you find any bugs, please report them at GitHub Issues.

Screenshots

Dialog:

Result:

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

Repository: https://github.com/jmzambon/libreoffice-code-highlighter

Release Description Compatibility Operating Systems License Release notes Updated  
v2.7.2 UI changes, new features and new translations 7.1 Linux, Windows, macOS GPL Allow to remove line numbering with non numeric padding symbol.
Update to Pygments 2.18.0.
Highlight code based on paragraph style.
Use some expanded sections for options.
Locale addition: hu (thank to ovari) and ru (thank to kompilainenn).
Various code and typos fixes.
2024-08-27 15:25:26 Download
v2.5.6 Various fixes and enhancements 7.1 Linux, Windows, macOS GPL Better use of lexer guessing in plain text and text table.

Update to Pygments 2.17.2.

Fix regression when using character styles [Writer].

Minimal version of LibreOffice is now 7.1.

Fix regression in some undo actions.

[Fix] Do not remove current charstyle when style option is not in use.

Fix bug on Windows when removing line numbering.
2024-03-16 14:05:24 Download
v2.5.2 In-document preview and improved performance 6.4 Linux, Windows, macOS GPL - New button allowing in-document preview.

- Enhanced dialog box.

- Better performance, especially for Impress and Calc.

- Code improvements and bug fixes.
2023-09-02 18:58:37 Download
v2.4.10 New features, bug fixes and code upgrade. 6.4 Linux, Windows, macOS GPL Update to Pygments 2.16.1.
Fix issue #21: Line numbers zero padding.
Add an option to specify any custom padding character.
Fix issue #22: Trouble with highlighting Julia Code, possibly due to unicode characters.
Extend last fix to Calc cells.
Fix issue #17: The dialog window won't open.
Fix regression in deleting unused character styles.
Last trailing whitespaces should not be highlighted.
Recognize already highlighted code snippet in all cases.
Colorize line numbers with comment colour.
Fix character background bug in Calc.
Improve dialog help texts.
Fix buffer wrongly emptied in higlight_code().
2023-08-06 16:52:01 Download
v2.4.2 New features, bug fixes and code upgrade. 6.4 Linux, Windows, macOS GPL - Update to Pygments 2.13.0.

- Change some behaviours when using character styles.

- Store formatting options with snippets (may be disabled).

- Make code snippets updatable.

- New menu items.

- Enhanced line numbering.

- Lot of code improvements.

- Fix some typos and bugs.
2022-08-23 16:44:19 Download
v2.3.3 New features, code enhancements and bug fixes 6.4 Linux, Windows, macOS GPL Add option to use character styles instead of direct formatting.
Add pseudo-lexer for LibreOffice Basic (which is in fact a convenient shortcut to VB.net lexer) and two LibreOffice specific styles: libreoffice-classic and libreoffice-dark.
Add support for character background color and underline.
Allow highlighting inline snippets.
Fix some bugs and misbehaviors.
2022-07-16 18:04:14 Download
v2.2.3 New features, bug fixes and code upgrade. 6.4 Linux, Windows, macOS GPL Logging facilities.
Support for line numbering.
French localisation.
Upgrade Pygments to version 2.11.2.
Bug fixes.
Some code rewriting.
2022-02-19 18:17:33 Download
v2.0.1 Small fixes and upgrades 6.4 Linux, Windows, macOS GPL Upgrade Pygments to version 2.11.1.
Fix error in getting lexer from some language aliases.
Fix error in undoing text box highlighting.
2022-01-05 12:34:11 Download
Code Highlighter 2 v2.0 - First release after forking Code Highlighter 6.4 Linux, Windows, macOS GPL embed Pygments
support for text frame and table cell selection in Writer (frame selection is preferred)
support cell selection in Calc
show highlight operations in undo manager
add key shortcuts (Shift+Alt+X and Alt+X)
add Pygments icon and version in dialog box
add error messages for unsupported selection or no selection at all
add menu item icons
speed up dialog opening + sorted languages and styles
remove spelling language for highlighted code
various little enhancements and fixes
automatic updates
2022-01-03 15:48:53 Download
Show more

Related Extensions

try: import

Logo for try: import

Displays the result of trying to "import <Library>" in Python.(Calc Template)

11-2024

75

Not rated yet

Script for parallel installation

Logo for Script for parallel installation

Batch script for parallel installation of LibreOffice on Windows

11-2024

54

Not rated yet

Indian Arts and Crafts

Arts and Crafts in India suit beautifully in business templates. Provide feedback and rating for further improvements. 

11-2024

71

Not rated yet

PyPi Reader

Screenshot for PyPi Reader

Get release information from RSS in the PyPi-library.(Calc Template)

11-2024

20

Not rated yet

CROS - Curretore regionale ortogràficu Sardu

Logo for CROS - Curretore regionale ortogràficu Sardu

Curretore regionale ortogràficu sardu (versione LSC) / Sardinian spelling and hyphenation dictionary (LSC)

11-2024

28

Not rated yet

Basic Chrono CV template

Screenshot for Basic Chrono CV template

Chronological type CV template

11-2024

108

Not rated yet

Feedback

★ ★ ★ ★ ★

Post your review

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

Reviews

  • Eliya Gopkalo 15 de jun. de 2024, 16:15 (5 months ago)

    ★ ★ ★ ★ ★

    Thank you so much. You are a life saver.

  • riinii fin 17 de fev. de 2024, 21:22 (9 months ago)

    ★ ★ ★ ★ ★

    Thank you!

  • Vyacheslav Kovalevsky 31 de mai. de 2023, 06:55 (18 months ago)

    ★ ★ ★ ★ ☆

    Good extension but some things are missing:
    * No theme or formatting preview
    * Ligth/Dark themes are mixed together, could be useful to have them in different tabs/groups

  • Pavlos Gkesos 8 de ago. de 2022, 02:24 (2 years ago)

    ★ ★ ★ ★ ★

    It has many many color sets for many many languages.
    No paragraph/character style introduction.
    Just select text and apply specific language and specific color set.
    On Windows works without nuclear physics knownledge.

    • Jean-Marc Zambon 18 de ago. de 2022, 22:33 (2 years ago)

      Thanks for your comment :)

  • Nick Matthews 14 de jul. de 2022, 21:48 (2 years ago)

    ★ ★ ★ ★ ★

    Excellent extension! I'm a computer science student and this helps a lot with quickly producing readable documents. I love that there are many options available for language and style. The extension is also super easy to use!

    • Jean-Marc Zambon 18 de ago. de 2022, 22:34 (2 years ago)

      Glad this is useful for you!

  • Carsten Timm 1 de jun. de 2022, 10:51 (2 years ago)

    ★ ★ ★ ★ ★

    Wahoo
    Danke dir
    Danke dir


    kannst du es auf java porten .-) für lern zwecke?
    der start zum plugin entwickeln mit Libreoffice Java war so lala.

    • Jean-Marc Zambon 18 de ago. de 2022, 22:35 (2 years ago)

      Sorry, I'm not able to port it to java.

  • Paul Fremdling 24 de mar. de 2022, 16:04 (3 years ago)

    ★ ★ ★ ★ ★

    Works excellent with LibreOffice 7.2

    • Jean-Marc Zambon 18 de ago. de 2022, 22:35 (2 years ago)

      Thanks!

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