Feature Request: Scripting hooks for adding language support and stylsheets to code highlighting.
I understand that code highlighting is early in it's making right now, but here's a preliminary feature request.
In a similar vein to the hook for adding a custom stylesheet it would be a good idea to have a hooks for adding both:
-
Support for languages; Perhaps a JSON file or similar, with explicitly typed keywords, types, 'other's, the start and end of a comment, etc. Bonus points if it support regex so that people can basically copy the regex from highligh.js for the slightly more convoluted languages.
-
Custom language highlighting stylsheets; Extra bonus points for being able to define which code the specific sheet applies to, so that you can have, for example, Java keywords highlighted in one set of colors, but C++ in another.
Would make your job a lot easier if people just added the languages they need themselves as there are billions of them ~~(and I wanna add taggerscript which is always going to be way too low on the priority list)~~. Perhaps you can then assimilate the scripts into the base program or so with an eventual update, if necessary.
In a similar vein to the hook for adding a custom stylesheet it would be a good idea to have a hooks for adding both:
I don't know about hooks, but there will be support for custom stylesheets hopefully. Right now the styles are present in hardcoded strings as you have already seen.
- Support for languages; Perhaps a JSON file or similar, with explicitly typed keywords, types, 'other's, the start and end of a comment, etc.
That lives here: https://github.com/pbek/qmarkdowntextedit/blob/5e49727bdaba9207d70bfa47bda1b201cb72329a/qownlanguagedata.cpp
If a language has keywords, types etc., you just need to add the data (There's a template at the top of the file) and the highlighter will take care of the rest. But if a language has special needs, for e.g HTML / YAML/ INI etc etc., I will need to study the script of the language and write a separate parser for it.
Most of the languages have either // or /* or # style comments. So the parser is able to take care of them. HTML is an oddity, right now we aren't handling <!-- style comments.
Bonus points if it support regex so that people can basically copy the regex from highligh.js for the slightly more convoluted languages.
Yes, with regex it can be relatively easier and cleaner too but unfortunately there is no regex involved here(or in the editor). The major reason to not use regex was performance. (The basic algorithm for parsing is same in both editor and the preview)
2. [Custom language highlighting stylsheets;](https://github.com/pbek/QOwnNotes/blob/cda536e78ea3069835bb26dd65aa1b45b3cb3b51/src/entities/note.cpp#L2143) Extra bonus points for being able to define which code the specific sheet applies to, so that you can have, for example, Java keywords highlighted in one set of colors, but C++ in another.
You would be able to do that with css I think , like so:
.language-cpp > .code-keyword {
color :#f00 !important
}
Would make your job a lot easier if people just added the languages they need themselves as there are billions of them
That'd be wonderful!
~(and I wanna add taggerscript which is always going to be way too low on the priority list)~.
Sure, if it looks like normal programming languages, you just need to add its data and you are done.
Edit: Just looked at taggerscript, it will need a separate parser. If you want it, give me some examples and I will try to write a parser and include it in the next release. Or maybe you can try yourself. YAML highlighter can be used as a reference point.
Thank you very much for your detailed answer!
Interesting choice about regex. I will say, I do appreciate a snappy and fast note editor, so knowing that's a primary design decision is very cool.
The info/template/reference are much appreciated! The code's very understandable so I'll most deffinetely look into it. I'll be honest, my biggest hurdle so far is proving to be just setting this project up in a dev environment more than anything 😅. The parser for taggerscript should be fairly simple in itself though - highlight everything between a '$' and a '(' with one color (including the $), and anything between a pair of '%''s with another. Also highlight any escape character ('\') and the character right after it.
Interesting choice about regex. I will say, I do appreciate a snappy and fast note editor, so knowing that's a primary design decision is very cool.
We are always look for more performance :grin:
I'll be honest, my biggest hurdle so far is proving to be just setting this project up in a dev environment more than anything sweat_smile.
Really? We have kept it totally self contained, no external dependencies. I wonder what's the issue. Let me know, I will help you out.
You just need to setup Qt / Qt creator
The parser for taggerscript should be fairly simple in itself though - highlight everything between a '$' and a '(' with one color (including the $), and anything between a pair of '%''s with another. Also highlight any escape character ('') and the character right after it.
Yeah, I just looked at it. Seems pretty straightforward. So, do you want to do it, or should I? :grin:
Really? We have kept it totally self contained, no external dependencies. I wonder what's the issue. Let me know, I will help you out.
Thank you, I appreciate it! It's simply that I've not dealt with qt before, so setup is new to me. I've setup qt/creator, got the repo, got all the libraries for it, though hitting build->run at that point throws me approx 500 errors so I must be missing a step.
I'm missing a step by step guide to setting up a project I can read through, but I'll dig at it more tomorrow, as it's getting very late for me.
Yeah, I just looked at it. Seems pretty straightforward. So, do you want to do it, or should I? 😁
I'll give it a go! Worst comes to worst I'll call upon you for a resque 😁
Thank you, I appreciate it! It's simply that I've not dealt with qt before, so setup is new to me. I've setup qt/creator, got the repo, got all the libraries for it, though hitting build->run at that point throws me approx 500 errors so I must be missing a step.
hmmm. ok here goes
1. git clone [repo]
2. cd QOwnNotes
3. git submodule update --init
4. Open QtCreator and the "QOwnNotes.pro" file
Alternatively you could just run:
qmake && make [messy]
OR
mkdir build && cd build && cmake .. && make
once the build goes through,
./QOwnNotes will run the program
I'm missing a step by step guide to setting up a project I can read through, but I'll dig at it more tomorrow, as it's getting very late for me.
Maybe you missed it in the readme: https://github.com/pbek/QOwnNotes#building-qownnotes
I'll give it a go! Worst comes to worst I'll call upon you for a resque grin
Haha. I am sure you can do it. I will be available for help or any of the project groups on telegram/irc/gitter/matrix.
I'm missing a step by step guide to setting up a project I can read through, but I'll dig at it more tomorrow, as it's getting very late for me.
https://www.qownnotes.org/installation#building :grin: