Skip to content

Conversation

@eclecticpassions
Copy link
Contributor

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 three is not highlighted fully in the colour set in the config file forcodeSpansunder [ColorScheme]. It only highlights the first two and the remaining ` and language is not highlighted.

Fix

After the fix, all three backticks + lang will be in the colour set by codeSpans and the contents of the code can be set by a new parameter called codeBlock. In my code comments I used yellowgreen as the codeSpans colour and codeBlock is orange/#fe5f01.

Relevant Config Settings

[ColorScheme]
codeBlock=orange
codeSpans=yellowgreen

Result

scnsht 2025-07-22 at 10 26 33 p m

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!

Copy link
Member

@mitya57 mitya57 left a 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.


def highlightBlock(self, text):
# Syntax highlighter
# If inside fenced code block (not the fence line)
Copy link
Member

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.

Copy link
Contributor Author

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?

def highlightBlock(self, text):
# Syntax highlighter
# If inside fenced code block (not the fence line)
if self.previousBlockState() == 1:
Copy link
Member

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.

Copy link
Contributor Author

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?)

# Check if this line closes fenced block
if reFencedCodeEnd.match(text):
# Fence closes: highlight fence line in yellowgreen (codeSpans)
fmt = QTextCharFormat()
Copy link
Member

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.

Copy link
Contributor Author

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.

@eclecticpassions eclecticpassions requested a review from mitya57 July 23, 2025 05:43
@mitya57 mitya57 merged commit d55b1a2 into retext-project:master Jul 24, 2025
7 checks passed
@mitya57
Copy link
Member

mitya57 commented Jul 24, 2025

Merged. Thank you again! 🎉

@eclecticpassions
Copy link
Contributor Author

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?

@mitya57
Copy link
Member

mitya57 commented Jul 27, 2025

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).

@eclecticpassions
Copy link
Contributor Author

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!

@mitya57
Copy link
Member

mitya57 commented Jul 27, 2025

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants