Tinderbox Forum

Color Code in Code Notes

I’m wondering if there is a way to use the code coloring that exits for action code in the Text pane of a note.

Currently, when I try to write code in the Text pane of a code note, the text format is simply that of the default $Text. By the term “code note,” I’m referring to a note that contains code that I’d like to run in a bunch of other notes. One failed attempt to address this color coding goal was to use the built in code prototype, but that does not affect $Text format.

I’ve thought of a couple of workarounds,

  1. Write code in the rule or edict sections of a code note instead of in the text pane, and disable the rule from running in the code note. I haven’t tested this, but I expect that I could set a rule in some other note that runs the rule in the code note.

  2. Write code in the rule or edict sections of a code note, then cut and paste the code into the Text pane. This preserves the color coding, though it’s not exactly an elegant solution.

  3. Use a separate text editor. This may work in many cases, but at least with Visual Studio Code and Tinderbox in dark mode, this does not work well. The dark color of the text background from Visual Studio Code gets copied into TinderBox, where the background dark color doesn’t match. Yuck!

Of those three alternatives, #1 is most appealing to me, but it would be nice to be able to write code directly in a nice big Text Pane and have it pick up coding syntax colors. Is this possible?


Yes, use the Highlighters feature: Highlighters.

Hi Michael,

I added the Built-in Hints to my tbx file and then selected my note with code in the text field, to set $SyntaxHighlighting to a value of “Syntax.”

So far, I’m still lost.

I want to use the same syntax coloring process that’s used in the action inspector the Text panel. Here is a small slice of example code as reference: if($Group=1){$StartDate=date(2021,9,3,8,0)};

If I wrote that in the action inspector, if would be blue, date would be blue, and the $attributes would be violet. Any strings would be red. If I made a mistake such as capitalizing If or not capitalizing an $attribute, then the text would revert to white as it is no longer recognized as a function or an attribute.

That sort of interactive color coding functionality is what I’m after in the $Text pane. I’d find useful to help identify syntax coding errors.

It’s not clear to me how the SyntaxHighlighting feature could be used to bring about the same color syntax functionality in the Text pane that exists in the action inspector.

I hope that better explains what I’d like to accomplish.


@_Bill I’ve been away at Hypertext 2021 last week and think this passed me by.

To be fair too Eastgate, Tinderbox is 20+ years old which is an aeon in software terms. I won’t claim the ‘code note’ was my idea but I certainly doubled down on the notion when helping in earlier Tinderbox fora and documented the idea in aTbRef (see here).

Step forward to today. There is code colouring Action Inspector and Stamps inputs (and commenting is allowed). Incremental improvements which broadly work; there are some gremlins at present but these will be reported resolved.

For my 2¢ worth, I like the notion of a code note. I think is should:

  • ignore/disable all ‘smart’ substitutions as they aren’t pertinent. We’re not typesetting here!
  • dump all font styling when pasting. Do we really want to code in Papyrus typeface? IOW, for code notes, paste == past and match style, so stripping unwanted styling. $CodeFont should be used (no bold/italic/strike-though/highlight/etc.). I’d suggest $TextFontSize be consistent but those harder of seeing might make a case for font sizing being needed.
  • use a fixed style/rule for all code notes (notes or Inspector) with lots of tabs - think nested code loops.

That said, at present a ‘code note’ is implemented by use of a prototype (“Code”). Now syntax colouring (checking is here), I think the above might might better be implanted by an $IsCodeNote attribute. This reifies the notes status regardless of prototype settings.

Hi Mark,

Wow, a lot of thought has gone into code notes. Thanks for sharing. I’d expect that syntax colouring in the $Text of code notes would be of interest to anyone who uses code notes. I hope that this, in combination with your 2¢ (above), can be turned into a feature request.

1 Like

When Mb’s back from leave, I think there’s some useful reflection to be done here. As said that the meet-up, ROI is a factor. I’d like this, as I use action code a lot. Others: not so much. I’m sure it’s a difficult balance behind the curtain.

In the meantime, you can use a reverse approach. Copy/paste your code note page into a stamp and check the syntax colouring. Why a stamp? Well you can save it without executing the code, unlike with a Rule or Edict. HTH!