Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Factory:Rebuild
python-jupyterlab-pygments
Example.ipynb
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File Example.ipynb of Package python-jupyterlab-pygments
{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from pygments import highlight\n", "from pygments.lexers import PythonLexer\n", "from pygments.formatters import HtmlFormatter\n", "from jupyterlab_pygments import JupyterStyle" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "mycode = \"\"\"\n", "class PythonCode:\n", " def __init__(self, value):\n", " self.value = value\n", " \n", " def _repr_html_(self, **kwargs):\n", " formatter = HtmlFormatter(style=JupyterStyle)\n", " html = highlight(self.value, PythonLexer(), formatter)\n", " return f'<div class=\"highlight\">{html}</div>'\n", "\"\"\"\n", "exec(mycode)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Rendering the previous cell in HTML with Pygments and JupyterStyle respects the JupyterLab theme" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "PythonCode(mycode)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.4" } }, "nbformat": 4, "nbformat_minor": 4 }
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor