{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "d5202f0f-21b8-4509-a9e2-45caf1c7db7a", "metadata": {}, "outputs": [], "source": [ "from textwrap import indent\n", "\n", "\n", "class Note:\n", " def __init__(self, text):\n", " self.text = text\n", "\n", " def _repr_html_(self):\n", " return f'
{self.text}
'\n", "\n", " def _repr_mimebundle_(self, include=None, exclude=None):\n", " return {\"text/x-rst\": \".. note::\\n\\n\" + indent(self.text, \" \")}" ] }, { "cell_type": "code", "execution_count": 2, "id": "5145b05f-3a07-4cff-8738-516a9c27cb58", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Testing testing
" ], "text/plain": [ "<__main__.Note at 0x7f457c0250d0>" ], "text/x-rst": [ ".. note::\n", "\n", " Testing testing" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Note(\"Testing testing\")" ] } ], "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.12.4" } }, "nbformat": 4, "nbformat_minor": 5 }