blob: 25a6ad83ead08f0a0d9db5a86cfcfbb83ddb2ef8 [file] [edit]
// Copyright (c) 2009 Giampaolo Rodola. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Syntax-highlight REPL inside pycon output spans (class="go").
// Pygments tokenizes >>> lines as Python, but leaves output as plain
// Generic.Output.
document.querySelectorAll(".highlight-pycon .go").forEach((span) => {
let html = span.innerHTML;
// Highlight quoted strings (must run first, before we inject spans).
html = html.replace(/('[^']*'|"[^"]*")/g,
'<span class="pycon-string">$1</span>');
// Highlight namedtuple field names (word before '=').
// The (?!") lookahead avoids matching class= in the injected span tags.
html = html.replace(/\b([a-z_]\w*)=(?!")/g,
'<span class="pycon-field">$1</span>=');
// Highlight numbers after '=' or at the start of a line.
html = html.replace(/(?<==)\d+\.?\d*|^\d+\.?\d*/gm,
'<span class="pycon-number">$&</span>');
span.innerHTML = html;
});
// Disable title showing up on hover.
document.querySelectorAll("a.sphinx-codeautolink-a[title]").forEach((a) => {
a.removeAttribute("title");
});