coteditor / CotEditor

Lightweight Plain-Text Editor for macOS
https://coteditor.com
Other
6.22k stars 425 forks source link

Markdown Highlighting: No distriction between _italic_ and **bold** #1634

Closed makzsslm closed 1 month ago

makzsslm commented 1 month ago

Description

Markdown has two different ways of putting emphasis, italic and bold. https://www.markdownguide.org/basic-syntax/#emphasis

CotEditor highlights both in the same way, using a single regex rule. I've found this disturbing and changed the regex rules in my preferences to display italic text as Commands rather than Keywords. This might be something that others find useful,

Before:

image

in Keywords

(?<!\\)(\*{1,3})[^ \t*]((?!\R{2})(?:.|\R))*?(?<![\\ ])\1 (?<!\\)\b(_{1,3})[^ \t_]((?!\R{2})(?:.|\R))*?(?<![\\ ])\1

After:

image

in Keywords (?<!\\)(\*{2,3})[^ \t*]((?!\R{2})(?:.|\R))*?(?<![\\ ])\1 (?<!\\)\b(_{2,3})[^ \t_]((?!\R{2})(?:.|\R))*?(?<![\\ ])\1

in Commands (?<!\\)(?<!\*)(\*)[^ \t*]((?!\R{2})(?:.|\R))*?(?<![\\ ])\1 (?<!\\)\b(?<!\_)(_)[^ \t_]((?!\R{2})(?:.|\R))*?(?<![\\ ])\1

To Reproduce

-

Expected behavior

No response

CotEditor version

4.8.2

macOS version

14.4.1

Additional context

No response

1024jp commented 1 month ago

Thank you for the suggestion. The current spec is intended so that inline styling should be keywords in principle, but as you suggested, it would be useful to be able to visually distinguish between em and strong, so I'll adopt your idea. However, as opposed to your suggestion, I assigned the strong one to the comment.

makzsslm commented 1 month ago

Many thanks !

in the image, orange would become red and red would become orange

1024jp commented 1 month ago

Hmmm, that's difficult. It is a proposition with no right answer, so I will try to follow the basic policy. Basically, I don't think we should change the color scheme too unnecessarily since most users are already used to the current spec. I also believe that it should not be needlessly colorful.

  • Actually, now that I think about it, maybe it might be good to assign em to Attributes or Variables, as they are not used in Markdown. That could help distinguish it from other Keywords such as hr and li elements.

On the other hand, I'll take this one because I think it will certainly increase convenience in terms of actual use.

  • To go one step further, maybe all Keywords and Commands could be swapped ? In most themes Commands appear stronger than Keywords. It would make sense to me that #headings are stronger than bold text

As for this one, let us go back to the first principle and reject it. (I understand your feelings. If it had been the first syntax, I might have adopted it.)