[TW5] highlight.js

531 views
Skip to first unread message

Bob Flandard

unread,
Sep 10, 2015, 5:48:37 PM9/10/15
to TiddlyWiki
Hello,

I've installed the highlight.js syntax highlighting plugin. How do I go about adding a custom "brush" ? (by brush I mean a language to supported by default).

Thanks, Bob

Jeremy Ruston

unread,
Sep 11, 2015, 2:53:54 PM9/11/15
to TiddlyWiki
Hi Bob

I've installed the highlight.js syntax highlighting plugin. How do I go about adding a custom "brush" ? (by brush I mean a language to supported by default).

I'm afraid custom brushes aren't currently supported. For 5.1.10, I've just upgraded the plugin to the latest v8.8.0 of highlight.js, and spent some time exploring custom brush support, but I'm afraid there isn't a quick way to make the necessary changes, and I don't want to commit to a big round of updates to the plugin right now.


Best wishes

Jeremy.

 

Thanks, Bob

--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/f88a31f8-f8e1-43a6-9783-4bee15d6af3f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Jeremy Ruston
mailto:jeremy...@gmail.com

Bob Flandard

unread,
Sep 11, 2015, 4:12:01 PM9/11/15
to TiddlyWiki, jeremy...@gmail.com
Hello Jeremy,

Thank you for your investigations and the plugin upgrade.

All the best, Bob

Danielo Rodríguez

unread,
Sep 12, 2015, 1:01:04 PM9/12/15
to TiddlyWiki, jeremy...@gmail.com
I just remind that I have created a custom language. I was creating a plugin for my work, and part of the plugin was a custom language. It was not easy, I had to deal with minified code. 

Bob Flandard

unread,
Sep 12, 2015, 1:59:22 PM9/12/15
to TiddlyWiki, jeremy...@gmail.com
Hello Danielo,

I had a look at the plugin code and got about as far as realizing that "hljs.registerLanguage" was the start of each new language. I thought about hijacking one of the existing languages that I'm unlikely to need for its intended purpose, but the minified code looked too impenetrable (combination of stripped down JavaScript and beastly regular expressions).

Did you have any joy with your attempts? and if so do you have any pointers or time savers.

The language I'm interested in is APDL from Ansys. Mainly the keywords for many hundreds of commands; some start with "/" e.g /view, some with "*" e.g *vget and others just normal "words" e.g save etc.

Thanks, Bob

Jeremy Ruston

unread,
Sep 13, 2015, 4:44:26 AM9/13/15
to Bob Flandard, TiddlyWiki
Here's an approach that should let you hack additional language brushes into the preview of 5.1.10. It modifies one of the shadow tiddlers within the highlight plugin, which can cause problems with future upgrades; if that happens, remove the shadow tiddler override and then re-apply the technique described below.

1. Find the brush you want within the highlight.js GitHub repo in the "src/languages" folder: https://github.com/isagalaev/highlight.js/archive/8.8.0.zip
2. Copy the text of the language you want
3. Open the tiddler "$:/plugins/tiddlywiki/highlight/highlightblock.js"
4. Paste the following after the line "hljs.configure(...)":

hljs.registerLanguage("<name_of_language>",<text_of_language_file>);

Save the tiddler and restart.

Let me know how you get on,

Best wishes

Jeremy.




Bob Flandard

unread,
Sep 13, 2015, 5:03:54 AM9/13/15
to TiddlyWiki, bfla...@gmail.com, jeremy...@gmail.com
Hello Jeremy

Thanks for working that out. It may take a while because I need to write the brush myself (It's only me and Motovun Jack that use APDL these days).

I did previously have a go at following the build instructions on the GitHub link you gave above. It output some code but I haven't scrutinized it yet and thankfully it seems like I won't have to now.

I let you know how it goes.

Thanks again, Bob

Brian Moran

unread,
May 7, 2016, 12:08:21 PM5/7/16
to TiddlyWiki, jeremy...@gmail.com
Hi Jeremy

First - many thanks for TiddlyWiki, it truly is wonderful.

I have followed your instructions posted here to try to add the language 'R' into the highlight.js plugin in my copy of 5.1.11.  Unfortunately this results in the red Internal JavaScript Error message.

I am pretty sure I followed your instructions to the letter but I assume that I must have made a mistake.  I can post the code I inserted (or an extract - maybe just the start and end) if you or another member of the TiddlyWiki group might be interested in looking at it...?

It would be great to have R syntax highlighting in TiddlyWiki.

All the best

Brian

Brian Moran

unread,
May 8, 2016, 8:43:35 AM5/8/16
to TiddlyWiki, jeremy...@gmail.com
Hi - I've had a further play and got something working that is good enough for my needs.  Here is what I did in case it helps anyone else trying to do something similar:

I edited $:/plugins/tiddlywiki/highlight/highlight.js instead of $:/plugins/tiddlywiki/highlight/highlightblock.js

In highlight.js the languages are defined in blocks of code starting with hljs.registerLanguage.  I just copied and pasted one of these blocks, named the language "r" and edited the words that I wanted to be highlighted, which are easy to spot within highlight.js.

This seems to be stable and is working ok.

So I have a workaround but it isn't using the official highlight.js R brush and I would love this to be included in a future version of TiddlyWiki .

All the best, and thank you once again for TiddlyWiki.

Brian
Reply all
Reply to author
Forward
0 new messages