Tinderbox Forum

Code highlighting in preview pane

(Kay Krämer) #1


I am not sure, if this topic is already existing here, but I could not find it.
Perhaps anyone can need something like this: Code highlighting in the export and also in the preview.

Looks like this (in this example are simpy a few lines of TB code and JavaScript Code):

(Galen Menzel) #2

Can you attach the document that you used to generate the screenshot?

(Kay Krämer) #3

Yes. Here it is!
prism_test.tbx (158.2 KB)

I have marked all notes and lines red, that are important for this to happen.
The prism.css and prism.js are from the website https://prismjs.com/

You can choose there, which languages should be highlighted. The two files in this tbx are rather minimalistic… if you want more ore different languages, you can build your own prism.js und prism.css there…

Btw… I stole the idea here at the DT Forum, and simply adjusted it a little bit for TB.

(Galen Menzel) #4

Very cool!

BTW, it seems that you have to run the export once for the preview command to pick up the generated css files.

I’m rather confused at how the preview command finds these .jss files. How does it know what to consider the document root???

(Kay Krämer) #5

It also took me some time to figure this out :rofl:
But in the end it worked…

Not quite sure, but very likely it works that way.

Preview uses - like HTML in general - css and JavaScript to style a document and to interact with it. So you only need to tell the HTML, where those files are. This happens with the 2 code lines in the „Test“ note, that I marked red. The 2 „prism“ notes are saved as prism.css and prism.js and use the „Text“ Template, so that really only the $Text is saved, without the title or any other stuff. Hereby is guaranteed, that those files are really „clean“.
Root is always the top level of a TB document, and the export code ^root^ point to this location, but not absulutely, but relatively. In the case of this document, you could the ^root^ expression, because everything is at root level. This gets interesting, when your notes, that should be styled, are located in containers…