[Request] Embedded source view to support syntax highlighting on code snippets

Bug #275714 reported by LouisHandfield on 2008-09-29
This bug affects 16 people
Affects Status Importance Assigned to Milestone

Bug Description

I realize Zim is not a code editor, but having syntax highlighting inside verbatim areas might be something nice to have. I am guessing it could simply be that you right-click on a verbatim block, click on Edit, and you would have the possibility to choose a language to highlight with.

Or perhaps it would be better to have a completely separate plugin that would insert a code widget and let you choose which syntax you want, line numbers, etc...

Awesome work so far though :)

Related branches

It is very difficult to have one widget render both wiki text and syntax highlighted code, so the proper way to implement this would be embedding a special widget, probably a GtkSourceView widget. This should go into a plugin since it is functionality which is only useful for a specific audience and can be implemented without touching any of the core libraries (ok this is not entirely true, but it should be).

Low on my TODO list for now, but if anyone wants to work on this I will support it.

Changed in zim:
importance: Undecided → Wishlist
status: New → Confirmed
Pablo Angulo (pablo-angulo) wrote :

A comment:

I'd recommend the following practice to work with syntax highlighted code:

1) Instead of creating a source code note within zim, drag and drop source code files into zim, or simply write the filename in zim and zim will recognize the path and build a link
2) Hit the link within zim to open it with your preferred source code editor

In my opinion, there are far too many good source code editors not to take advantage of them. They have tons of other features people will start to ask if anyone decides to add source code support for zim (smart indent, templates, code folding???)

No worries, zim will not become a source code editor, there are indeed plenty of those available already. Indeed you can link source files and open them with your standard editor.

However highlighting small snippets is a nice feature for people taking notes about software but also examples of HTML / CSS etc. The way I would like to do this is by re-using the gtksourceview widget which is pretty good in basic features. The viewer would then embed one or more sourceview widgets into a page like small frames. Re-using that widget will isolate zim from a flood of feature requests.

As stated before this is low on my priority list. On the other hand do I need to look at embedded widgets for other features as well, which might make it very simple to add this one as well.

From Bug #303454: also disable spell checking for verbatim code snippets, this will come for free when code snippets are shown in an embedded sourceview widget.

summary: - [Request] Syntax highlighting
+ [Request] Embedded source view to support syntax highlighting on code
+ snippets

From Bug #666099: Allow showing code from external files, e.g. attachments.

tags: added: embedded objects
tags: added: embedded-objects
removed: embedded objects

Is it possible to use pygments like in Moinmoin?

At the moment, Zim uses the GTK+ TextView widget. TextView widgets are
formatted with the Pango system. There isn't really an easy way to get
syntax highlighting into it. You have some choices (as previously
* embed a GTK SourceView widget in the TextView
* convert Zim to use Webkit instead of a TextView (lots and lots of
work and it may be best to let Webkit stabilise more yet)

In conjunction with Webkit, it would probably be possible to use pygments.

Both options are a lot of work.


On Sun, Apr 10, 2011 at 1:28 AM, Eugene Krivobokov
<email address hidden> wrote:
> Is it possible to use pygments like in Moinmoin?
> --
> You received this bug notification because you are subscribed to Zim.
> https://bugs.launchpad.net/bugs/275714
> Title:
>  [Request] Embedded source view to support syntax highlighting on code
>  snippets

On Sun, Apr 10, 2011 at 9:37 AM, Michael Mulqueen <email address hidden>wrote:

> * embed a GTK SourceView widget in the TextView

This is actually planned for next release + 1 (so maybe zim 0.52 ) there is
a branch availble already implementing this.

-- Jaap

Martin Minka (martin-minka) wrote :

Please add code syntax highlighting to Zim, then it will be the definitive tool for my needs. Thank you.

Changed in zim:
status: Confirmed → In Progress
Changed in zim:
status: In Progress → Fix Committed

Fixed <= release 0.62

Changed in zim:
status: Fix Committed → Fix Released
Mike (mrmikee) wrote :

So if this feature has been added in 0.62, how can we use it to highlight Python code in our notebooks? I don't see it anywhere in the documents or options even as of Zim 0.65.

This is the number one feature I feel Zim is missing for developers to use it for their project documentations needs as Zim already exports to the other formats we use.

PLEASE add something like Pygments. ZIM is awesome otherwise!!!!

Mike (mrmikee) wrote :

Sorry, I now see that the Source View plugin is what needs to be enabled along with installing an additional package in Ubuntu for it to work.

Thank you for a great tool!

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Duplicates of this bug

Other bug subscribers