baudren / NoteOrganiser

Scientific Note Taking
MIT License
13 stars 6 forks source link

Syntax highlighting for the main title and the post's titles #67

Closed baudren closed 8 years ago

baudren commented 8 years ago

Currently, there is no highlighting for the title of the notebook, nor for each titles. Because I did not find a way to make the QSyntaxHighlighter work for underlined titles (they have to match ^={3,*}$, or ^-{3,*}$, then highlight this and the line before.

egolus commented 8 years ago

it looks like we have to subclass the QSyntaxHighlighter

here they show an example to find comments in C++. Our Highligher would have to look for the underlines and then look above for the emply line (or the start of the document)

egolus commented 8 years ago

You know, we could use the other style of titles.

# Main title

## post title

### section title inside of the post

#### - ###### does anyone ever use these? (Html H4-H6 titles are just too small)

the problem is we would have to find a different syntax for the tags and we would need to automatically update the existing notebooks

(and of course update a whole lot of code in text_processing.py)

baudren commented 8 years ago

But, but... that would mean giving up! I actually openend a stackoverflow question to see if there are some ideas around.

egolus commented 8 years ago

My question is, do you have a special reason to use underlining in the first place? I prefer #-style headers for some reasons:

the only advantage of underlining I see may be readability

baudren commented 8 years ago

Underlining both for the main-title and the posts titles is in #84, could you check it, @egolus ?

In particular, I should probably do something to be sure not to highlight tables...

egolus commented 8 years ago

This looks good.

There is one table style where you start and end with one line with just dashes, but normally you have some other characters in every line to separate the table columns (spaces, pipes, colons, etc.) So this one table style not only is highlighted wrong but also breaks the conversion because it's identified as a new note header. I'm not sure we can do much about it. (other than telling the user to use another table style)

baudren commented 8 years ago

We could add a check for the line of dashes: if there is an empty line above, or below, we know it is not a title separation, but is instead a table. It could also be added at the level of the syntax highlighting, to check the line following starts with a hash.

baudren commented 8 years ago

I added the mentioned above checks - should now be more robust, and should not crash on tables :)

egolus commented 8 years ago

When is the highlighting updated? It looks like it's only updated, when I change something in the line itself or above. So If I add a title in the editor, it doesn't get highlighted because at the time it looks at the lines after the title, this is still empty, because I haven't reached it yet to add the tags. If I add the tags, then go back to the title and change something, the title gets highlighted correctly.

[note1]

|

the file before I change anything. The pipe is my cursor

[note1]

this is my title
-----------------|

the line under the underlining is still empty, the pipe is my cursor

[note1]

this is my title
-----------------
# tags tags tags

now the title should be highlighted, but it's not updated. If I change anything in the title-line itself or above, it gets updated to a proper title-highlighting

baudren commented 8 years ago

Got it - As described there, the next() returns the next line properly under the condition that it is not updated. As you type, the next().text() check is not validated. There is no problem if you use the New Note, as everything gets written at once.

I am not sure how to try and fix this. Maybe trying to find a way to refresh the content more often than what is being done now, in the text editor. What is strange is that not even a save triggers the proper highlighting.

And in any case, my implementation was faulty, since the main title was not being highlighted anymore (not followed by a written line :))

egolus commented 8 years ago

hmm. At least after the save we could trigger a highlighting. We should be careful with too many updates while the user writes in the editor. I've got this problem in vim when using some highlighting-heavy filetype like markdown.. sometimes it takes a looong time to update while writing and it's really annoying

baudren commented 8 years ago

Fixed with #84