Open HeyMyian opened 5 months ago
Unfortunately, shortcodes are not parsed by the syntax highlighter, other than the code tag itself. Handling this would require nested parsing, since these are basically free form. The only way to really do it is to add Markdown-like highlighting with ==
wrappers or something like that.
What are your thoughts on adding additional markdown for this? The visual effect would be consistent with the other markdown vs. shortcodes, where only the markdown variant changes how the text renders in the editor.
I think it would be a nice-to-have feature, but perhaps there are some arguments against adding more and more markdown.
I think it would be a nice-to-have feature, but perhaps there are some arguments against adding more and more markdown.
Well, yes. Each markdown addition needs an independent rule which is processed on a text paragraph on every single key press you make. The nice thing about shortcodes is that they are all included in a single rule. so adding more comes at a minimal cost.
That said, there's still room before keypresses become laggy (the spell checker also runs on the whole paragraph on each keypress) and we're not really hitting any issues yet that I know of. Python is relatively slow, but moder computers are also very fast. But I've noticed typing lag in other Python-based apps because there is too much processing going on when you type, and that is annoying. Especially for a writing app.
Anyway, I can add the ==
notation. The main reason I never did is that =
is a more common symbol to actually use than the other markdown symbols _
, *
and ~
, so it may misfire more often. I'll need to add a \=
escape as well.
If it wasn't for the fact that novelWriter runs on Python, I would probably write a parser that didn't rely on regular expressions. That way I could process character by character and flag formatting on and off as needed. I've written parser like this before in machine code compiled languages, and they are plenty fast enough, and have the ability to accept any rule logic I want.
I fear this will be too slow on Python, but I may give it another try at some point. Especially if there are too many highlight rules. The non-text blocks (headings, keywords, comments, footnotes) already uses this style of parsing rather than regex.
That said, there's still room before keypresses become laggy (the spell checker also runs on the whole paragraph on each keypress) and we're not really hitting any issues yet that I know of.
It looks to me like we're far off reaching any performance issues. I have this old 2011 Intel Atom N450 netbook lying around where I recently installed antiX Linux on to see if I could still use it for writing (I could)(but I don't). This thing is really slow and can barely handle a web browser. I see no issues at all though typing in novelWriter; keystrokes are crisp.
Out of curiosity, what are those Python apps you've seen where typing is laggy?
I renamed this to "Add Markdown highlighting format" instead, as that's the solution to add actual formatting to the editor. I'll use the syntax discussed before, which was a non-standard Markdown format using ==highlighted text==
. I really don't like it, but anyway ...
Is there a chance we could get the highlight background color as it is displayed in the document viewer also in the document editor? I next to never use the document viewer, but having a more eye-catching highlight color for marked stuff could be useful in the editor too. Unsure if technically possible.
1) Current viewer 2) Current editor 3) Proposed editor