Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ReText/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
'htmlStrings': {'light': '#808000', 'dark': '#d0d070'},
'htmlComments': {'light': '#a0a0a4', 'dark': '#b0b0aa'},
'codeSpans': {'light': '#505050', 'dark': '#afafaf'},
'codeBlock': {'light': '#aa6600', 'dark': '#fe5f01'},
'markdownHeaders': {'light': '#000000', 'dark': '#ffffff'},
'markdownLinks': {'light': '#000090', 'dark': '#8080ff'},
'blockquotes': {'light': '#808080', 'dark': '#b0b0b0'},
Expand Down
33 changes: 32 additions & 1 deletion ReText/highlighter.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

from ReText.editor import getColor

reFencedCodeStart = re.compile(r'^(`{3,})(\w+)?\s*$')
reFencedCodeEnd = re.compile(r'^`{3,}\s*$')
reHtmlTags = re.compile('<[^<>@]*>')
reHtmlSymbols = re.compile(r'&#?\w+;')
reHtmlStrings = re.compile('"[^"<]*"(?=[^<]*>)')
Expand Down Expand Up @@ -155,7 +157,36 @@ class ReTextHighlighter(QSyntaxHighlighter):
)

def highlightBlock(self, text):
# Syntax highlighter
# If inside fenced code block (not the fence line)
if self.docType == 'Markdown' and self.previousBlockState() == 1:
fmt = QTextCharFormat()
fmt.setFontItalic(True)

# Check if this line closes fenced block
if reFencedCodeEnd.match(text):
# Fence closes: highlight fence line in yellowgreen (codeSpans)
fmt.setForeground(getColor('codeSpans')) # fence color yellowgreen
self.setFormat(0, len(text), fmt)
self.setCurrentBlockState(0)
else:
# Inside fenced code: highlight in orange (codeBlock)
fmt.setForeground(getColor('codeBlock')) # code block content color orange
self.setFormat(0, len(text), fmt)
self.setCurrentBlockState(1)
return

# If this line is a fence opening line (3+ backticks with optional lang)
if self.docType == 'Markdown' and reFencedCodeStart.match(text):
fmt = QTextCharFormat()
fmt.setForeground(getColor('codeSpans')) # fence color yellowgreen
fmt.setFontItalic(True)
self.setFormat(0, len(text), fmt)
self.setCurrentBlockState(1)
return

# Otherwise, normal highlighting for text outside fenced blocks
self.setCurrentBlockState(0)

codeSpans = set()
if self.docType in docTypesMapping:
markup = docTypesMapping[self.docType]
Expand Down