def __call__(self, source, language=None, metadata=None): """ Return a syntax-highlighted version of the input source as html output. Same as Highlight2HTML but with inline line numbers Parameters ---------- source : str source of the cell to highlight language : str language to highlight the syntax of metadata : NotebookNode cell metadata metadata of the cell to highlight """ from pygments.formatters import HtmlFormatter if not language: language = self.pygments_lexer return _pygments_highlight( source if len(source) > 0 else " ", # needed to help post processors: HtmlFormatter(cssclass=" highlight hl-" + language, linenos="inline"), language, metadata, )
def custom_highlight_code(source, language="python", metadata=None): """ Makes the CSS class of the div that contains the `<pre>` be `.highlight-ipynb` instead of `.highlight`. This modifies only HTML content not CSS On the notebook.html.js we modify the CSS styles """ if not language: language = "python" formatter = HtmlFormatter(cssclass="highlight-ipynb hl-" + language) output = _pygments_highlight(source, formatter, language, metadata) return output
def custom_highlight_code(source, language="python", metadata=None): """ Makes the syntax highlighting from pygments in the Notebook output have the prefix(`highlight-ipynb`). So it doesn't break the theme pygments This modifies only html content, not css """ if not language: language = "ipython3" formatter = HtmlFormatter(cssclass=" highlight highlight-ipynb hl-" + language) output = _pygments_highlight(source, formatter, language, metadata) return output
def custom_highlighter(source, language='ipython', metadata=None): """ Makes the syntax highlighting from pygments have prefix(`highlight-ipynb`) So it doesn't break the theme pygments It modifies both css prefixes and html tags """ if not language: language = 'ipython' formatter = HtmlFormatter(cssclass='highlight-ipynb') output = _pygments_highlight(source, formatter, language, metadata) output = output.replace('<pre>', '<pre class="ipynb">') return output
def custom_highlight_code(source, language="python", metadata=None): """ Makes the syntax highlighting from pygments in the Notebook output have the prefix(`highlight-ipynb`). So it doesn"t break the theme pygments This modifies only html content, not css """ if not language: language = "ipython3" formatter = HtmlFormatter(cssclass=" highlight highlight-ipynb hl-"+language) output = _pygments_highlight(source, formatter, language, metadata) return output
def custom_highlighter(source, language="python", metadata=None): """ Makes the syntax highlighting from pygments have prefix(`highlight-ipynb`) So it doesn't break the theme pygments This modifies both css prefixes and html tags Returns new html content """ if not language: language = "python" formatter = HtmlFormatter(cssclass="highlight-ipynb") output = _pygments_highlight(source, formatter, language, metadata) output = output.replace("<pre>", '<pre class="ipynb">') return output
def custom_highlight_code(source, language=None, metadata=None): """ Change CSS class names from .highlight to .highlight-ipynb. This are for the <div> that contains the <pre> This modifies only the HTML not CSS. On the `notebook.html.js` template we modify the CSS styles. """ global cell_id cell_id = cell_id + 1 if not language: language = kernel_lang formatter = HtmlFormatter(cssclass="highlight-ipynb hl-" + language) output = _pygments_highlight(source, formatter, language, metadata) clipboard_copy_txt = f"""<div id="cell-{cell_id}" class="clipboard-copy-txt">{source}</div> """ return output + clipboard_copy_txt
def custom_highlighter(source, language='ipython', metadata=None): formatter = HtmlFormatter(cssclass='highlight-ipynb') if not language: language = 'ipython' output = _pygments_highlight(source, formatter, language) return output.replace('<pre>', '<pre class="ipynb">')