-
Notifications
You must be signed in to change notification settings - Fork 207
Fix fenced code block not showing correct syntax highlighting for backticks #669
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
Fix fenced code block not showing correct syntax highlighting for backticks #669
Conversation
mitya57
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this PR! Left some comments.
ReText/highlighter.py
Outdated
|
|
||
| def highlightBlock(self, text): | ||
| # Syntax highlighter | ||
| # If inside fenced code block (not the fence line) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please indent this comment by 4 spaces.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to clarify, do you mean indent line 160's comment starting "If inside..." by another 4 spaces so it's 8 total?
ReText/highlighter.py
Outdated
| def highlightBlock(self, text): | ||
| # Syntax highlighter | ||
| # If inside fenced code block (not the fence line) | ||
| if self.previousBlockState() == 1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add the additional condition self.docType == 'Markdown' to this block and to the next one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Completed. This commit.
(Do I need to comment on each of your comments here with a link to the commit resolves it?)
ReText/highlighter.py
Outdated
| # Check if this line closes fenced block | ||
| if reFencedCodeEnd.match(text): | ||
| # Fence closes: highlight fence line in yellowgreen (codeSpans) | ||
| fmt = QTextCharFormat() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can move initialization of fmt and fmt.setFontItalic(True) outside the if, because they are present in both if and else branches.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit moves it outside.
|
Merged. Thank you again! 🎉 |
The pleasure is all mine! I learnt a lot about the PR process and Python. Hope I can help out a bit more in the future as ReText is pretty awesome. I have written two blog posts/guides about it actually. Idk if it'll be useful to share it on the project somewhere? |
|
I guess it's this one? Feel free to convert it into a wiki page if you want to (the wiki is editable by everyone). |
I didn't want to sound like I was self promoting, but yes (thanks for finding it), that's one and the other is a guide for users installing ReText on macOS. I can try writing my first wiki page! I'll make a draft of it and do a PR? Thanks for giving me a chance to work on ReText @mitya57! |
|
There are no PRs in GitHub wiki. You just write it directly either using the web interface in the “Wiki” section, or by cloning the wiki repository and editing it in your favorite editor (e.g. ReText). |
Note: This PR is in relation to issue #667, there's screenshots there showing the before and after the code changes.
Problem
In the editor panel (left panel), when creating fenced blocks, i.e. three
backticks followed by the langauge and ending the code block with another three; the threeis not highlighted fully in the colour set in the config file forcodeSpansunder [ColorScheme]. It only highlights the first twoand the remaining ` and language is not highlighted.Fix
After the fix, all three backticks + lang will be in the colour set by
codeSpansand the contents of the code can be set by a new parameter calledcodeBlock. In my code comments I used yellowgreen as thecodeSpanscolour andcodeBlockis orange/#fe5f01.Relevant Config Settings
Result
Remarks
I hope this PR is a suitable fix and doesn't affect the rest of the code/app (I'm a newbie at PRs and Python in general). I tried to add comments to the code (mainly for me to not get confused), feel free to remove it if it's not needed. Thanks for this great app!