Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't grey-out literals (characters following a backslash) #44

Closed
Jaifroid opened this issue Oct 19, 2018 · 4 comments
Closed

Don't grey-out literals (characters following a backslash) #44

Jaifroid opened this issue Oct 19, 2018 · 4 comments
Labels
enhancement This is an enhancement to a feature of Zettlr.

Comments

@Jaifroid
Copy link

It's fine to grey-out the backslash itself, but the character following it is a literal and therefore is intended to be what it is. For example, if I write myname\@myuniversity.ac.uk currently Zettlr greys out both the backslash and the @ sign. Now I realize I probably don't need to write @ as a literal, but pandoc seems to do it anyway when converting from other formats. Maybe a better case is this (sentence entirely fictional):

L.P. Hartley wrote that "\[t\]he past is a foreign country; they do things differently \[…\]". You will rightly complain that this quotation is incomplete, but that is my point.

Again, maybe I don't need to put the backslashes in, because it's not interpreted as an href, but pandoc puts them in to avoid ambiguity, and the result is I can hardly see the greyed out brackets in Zettlr, and they're peppered through the work I'm converting.

@nathanlesage
Copy link
Member

Yep, this is a problem in the underlying Markdown parser from Codemirror, which does not differentiate between the escaping backlash and the literal character. It has annoyed me for some time myself. The problem would be that, if I manually alter the Markdown parser code then I won't be able to integrate CodeMirror updates so easily in the future, which is why I'm rather hesitant in doing this. I'll look into the chances of doing so!

@Jaifroid
Copy link
Author

Jaifroid commented Oct 19, 2018

I see that the class cm-formatting-escape is applied to the whole text \[, so pure CSS wouldn't work.

But a combination of a regex like:

document = document.replace(/\\([[\]@])/ig, '\\<span class="nogrey">$1</span>');

together with a custom CSS rule for the nogrey class could work? Tested on Regex101: https://regex101.com/r/Jq7xVr/3

EDIT: Added @ to the regex (so it recognizes \@ as well as \[ and \]) and removed redundant backslash

@nathanlesage
Copy link
Member

I see where you get to but this is rather monkey patching-like. I'm not sure that's the best way. In the past months when I was developing Zettlr, I always resorted to monkey-patching. This way I could cramp into the app many features as quickly as possible, and now I'm stuck with a lot of code refactoring. Besides, a simple document.replace wouldn't suffice, as CodeMirror internally does a lot of stuff to the text before it is actually rendered. I guess we're stuck with two options:

  1. Manually adapt the gfm-mode to divide between the escaping character and the literal (which I would prefer)
  2. Add an option to either grey out both, or none of the characters.

As the gfm-mode itself is just a superset of the markdown-mode, maybe there's a way to override this behaviour manually. If so, I'll stick with this, but this requires some more research.

@nathanlesage nathanlesage added the enhancement This is an enhancement to a feature of Zettlr. label Oct 20, 2018
@nathanlesage
Copy link
Member

Tada!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This is an enhancement to a feature of Zettlr.
Projects
None yet
Development

No branches or pull requests

2 participants