{ "cells": [ { "cell_type": "markdown", "id": "3746ad3d", "metadata": { "tags": [ "nbprint:section:covermatter" ] }, "source": [ "# Runtime API Demo" ] }, { "cell_type": "code", "execution_count": 1, "id": "b669d202", "metadata": { "execution": { "iopub.execute_input": "2026-04-24T14:34:34.501861Z", "iopub.status.busy": "2026-04-24T14:34:34.501675Z", "iopub.status.idle": "2026-04-24T14:34:36.987589Z", "shell.execute_reply": "2026-04-24T14:34:36.987270Z" }, "nbprint": { "ignore": true } }, "outputs": [], "source": [ "# Load the %%nbprint cell magic so later cells can use it.\n", "%load_ext nbprint.config.magic" ] }, { "cell_type": "code", "execution_count": 2, "id": "28af9116", "metadata": { "execution": { "iopub.execute_input": "2026-04-24T14:34:36.989190Z", "iopub.status.busy": "2026-04-24T14:34:36.989039Z", "iopub.status.idle": "2026-04-24T14:34:36.992871Z", "shell.execute_reply": "2026-04-24T14:34:36.992498Z" } }, "outputs": [ { "data": { "application/nbprint.cell+json": "{\"section\": \"covermatter\", \"css\": \":scope, :scope * { text-align: center; }\\n:scope h1 { font-size: 32pt; }\"}" }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "# Big Centered Headline" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from IPython.display import Markdown, display\n", "from nbprint import NBPrintCell, Style, Font\n", "\n", "# Route this cell to covermatter and centre it.\n", "NBPrintCell(section=\"covermatter\",\n", " css=\":scope, :scope * { text-align: center; }\\n:scope h1 { font-size: 32pt; }\")\n", "display(Markdown(\"# Big Centered Headline\"))" ] }, { "cell_type": "code", "execution_count": 3, "id": "bea6b4cb", "metadata": { "execution": { "iopub.execute_input": "2026-04-24T14:34:36.993927Z", "iopub.status.busy": "2026-04-24T14:34:36.993869Z", "iopub.status.idle": "2026-04-24T14:34:36.996654Z", "shell.execute_reply": "2026-04-24T14:34:36.996316Z" } }, "outputs": [ { "data": { "application/nbprint.cell+json": "{\"style\": {\"tags\": [], \"role\": \"undefined\", \"ignore\": false, \"css\": \"\", \"esm\": \"\", \"classname\": \"\", \"attrs\": {}, \"font\": {\"tags\": [], \"role\": \"undefined\", \"ignore\": false, \"css\": \"\", \"esm\": \"\", \"classname\": \"\", \"attrs\": {}, \"important\": false, \"size\": 18, \"type_\": \"nbprint.config.common.text.Font\"}, \"type_\": \"nbprint.config.common.style.Style\"}}" }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "This text inherits the NBPrintCell `Style`." ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Context-manager form wraps the display output in a styled div.\n", "with NBPrintCell(style=Style(font=Font(size=18))):\n", " display(Markdown(\"This text inherits the NBPrintCell `Style`.\"))" ] }, { "cell_type": "code", "execution_count": 4, "id": "1f0fe40f", "metadata": { "execution": { "iopub.execute_input": "2026-04-24T14:34:36.997496Z", "iopub.status.busy": "2026-04-24T14:34:36.997444Z", "iopub.status.idle": "2026-04-24T14:34:37.000248Z", "shell.execute_reply": "2026-04-24T14:34:36.999858Z" } }, "outputs": [ { "data": { "application/nbprint.cell+json": "{\"section\": \"frontmatter\", \"css\": \":scope { font-style: italic; }\"}" }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "Magic-line metadata: routed to frontmatter." ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%nbprint section=frontmatter css=\":scope { font-style: italic; }\"\n", "from IPython.display import Markdown, display\n", "display(Markdown(\"Magic-line metadata: routed to frontmatter.\"))" ] }, { "cell_type": "markdown", "id": "edd9b04b", "metadata": {}, "source": [ "# Body Content\n", "\n", "Cells with no `NBPrintCell()` call or `%%nbprint` magic fall through\n", "to `middlematter` by default." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.11.15" } }, "nbformat": 4, "nbformat_minor": 5 }