MCPcopy Index your code
hub / github.com/python/cpython / _highlightSyntax

Method _highlightSyntax

Doc/_static/profiling-sampling-visualization.js:275–291  ·  view source on GitHub ↗
(line)

Source from the content-addressed store, hash-verified

273 }
274
275 _highlightSyntax(line) {
276 return line
277 .replace(/&/g, "&")
278 .replace(/</g, "&lt;")
279 .replace(/>/g, "&gt;")
280 .replace(/(f?"[^"]*"|f?'[^']*')/g, '<span class="string">$1</span>')
281 .replace(/(#.*$)/g, '<span class="comment">$1</span>')
282 .replace(
283 /\b(def|if|elif|else|return|for|in|range|print|__name__|__main__)\b/g,
284 '<span class="keyword">$1</span>',
285 )
286 .replace(
287 /<span class="keyword">def<\/span>\s+(\w+)/g,
288 '<span class="keyword">def</span> <span class="function">$1</span>',
289 )
290 .replace(/\b(\d+)\b/g, '<span class="number">$1</span>');
291 }
292
293 highlightLine(lineNumber) {
294 if (this.currentLine === lineNumber) return;

Callers 1

_renderSourceMethod · 0.95

Calls 1

replaceMethod · 0.45

Tested by

no test coverage detected