MCPcopy Index your code
hub / github.com/Akascape/CTkCodeBox / highlight_code

Method highlight_code

CTkCodeBox/ctk_code_box.py:167–179  ·  view source on GitHub ↗
(self, code)

Source from the content-addressed store, hash-verified

165 self.edited = False
166
167 def highlight_code(self, code):
168 code = code.replace("\n"," ",1)
169 try:
170 tokens = list(lex(code, self.lexer()))
171 except:
172 raise ValueError("Not a valid lexer. Available lexers: https://pygments.org/docs/lexers")
173 start_line=1
174 start_index = 0
175 for token in tokens:
176 end_line, end_index = self.index(f'{start_line}.{start_index}+{len(token[1])} chars').split('.')
177 self.tag_add(str(token[0]), f'{start_line}.{start_index}', f'{end_line}.{end_index}')
178 start_line = end_line
179 start_index = end_index
180
181 def configure(self, param=None, **kwargs):
182 if "theme" in kwargs:

Callers 1

update_codeMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected