API reference¶
cutiepynb
¶
Make Jupyter notebooks colorful and easier to navigate.
create_new_document(document, colors=None, *, add_toc=True, toc_title=TOC_TITLE, heading_edits=None)
¶
Return a styled copy of a notebook dictionary.
The input is never mutated. Markdown headings receive stable, unique
anchors and optional colors; code cells and fenced code examples are left
untouched. heading_edits maps zero-based heading positions to a new
title, a new level from 1 to 6, or both.
Source code in cutiepynb/core.py
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 | |
cutiepy_nb(file, sns_palette=None, colors=None, save=True, update_colors=None, *, output_file=None, add_toc=True, toc_title=TOC_TITLE)
¶
Compatibility API for styling a notebook.
The transformed notebook dictionary is always returned. If save is
true, it is also written to output_file or to *_chulo.ipynb. This
wrapper keeps the original overwrite behavior; new applications should
prefer :func:process_notebook for explicit overwrite protection.
Source code in cutiepynb/core.py
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 | |
enchular_ipynb(file, sns_palette=None, colors=None, update_colors=None, *, add_toc=True, toc_title=TOC_TITLE)
¶
Load and transform a notebook without writing it to disk.
Source code in cutiepynb/core.py
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 | |
process_notebook(input_file, output_file=None, *, colors=None, sns_palette=None, add_toc=True, toc_title=TOC_TITLE, overwrite=False)
¶
Transform input_file and save it, returning the output path.
When output_file is omitted, report.ipynb becomes
report_chulo.ipynb. Existing output is protected unless
overwrite=True is explicitly requested.
Source code in cutiepynb/core.py
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 | |
update_heading_colors_in_document(document, new_colors)
¶
Return a copy with existing styled heading colors replaced.
Both current cutiepynb markup and spans generated by early releases are supported. The original notebook dictionary is not mutated.
Source code in cutiepynb/styles.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
Core helpers¶
cutiepynb.core
¶
Core notebook transformations for :mod:cutiepynb.
The functions in this module deliberately operate on ordinary dictionaries.
That keeps the package lightweight while remaining compatible with notebooks
loaded by either :mod:json or :mod:nbformat.
generate_new_cells(cells, colors=None, *, heading_edits=None)
¶
Return decorated cells and the headings used to build a table of contents.
Existing cutiepynb table-of-contents cells are removed, which makes the transformation safe to run more than once.
Source code in cutiepynb/core.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | |
generate_contents(info_to_add, title=TOC_TITLE, *, cell_id='cutiepynb-toc')
¶
Build the generated table-of-contents markdown cell.
Source code in cutiepynb/core.py
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | |
create_new_document(document, colors=None, *, add_toc=True, toc_title=TOC_TITLE, heading_edits=None)
¶
Return a styled copy of a notebook dictionary.
The input is never mutated. Markdown headings receive stable, unique
anchors and optional colors; code cells and fenced code examples are left
untouched. heading_edits maps zero-based heading positions to a new
title, a new level from 1 to 6, or both.
Source code in cutiepynb/core.py
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 | |
format_title_index(title_numb, titles)
¶
Format one heading as a nested Markdown table-of-contents item.
Source code in cutiepynb/core.py
393 394 395 396 397 398 399 400 401 402 403 | |
extract_info(source, titles)
¶
Extract headings from markdown source into titles.
This compatibility helper does not modify the source. New code will
usually call :func:create_new_document instead.
Source code in cutiepynb/core.py
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 | |
create_source_anchor(source, values, colors=None)
¶
Add a cutiepynb anchor and styling to a single heading source.
This function is retained for compatibility with the original public module. It returns notebook-style source lines.
Source code in cutiepynb/core.py
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 | |
enchular_ipynb(file, sns_palette=None, colors=None, update_colors=None, *, add_toc=True, toc_title=TOC_TITLE)
¶
Load and transform a notebook without writing it to disk.
Source code in cutiepynb/core.py
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 | |
process_notebook(input_file, output_file=None, *, colors=None, sns_palette=None, add_toc=True, toc_title=TOC_TITLE, overwrite=False)
¶
Transform input_file and save it, returning the output path.
When output_file is omitted, report.ipynb becomes
report_chulo.ipynb. Existing output is protected unless
overwrite=True is explicitly requested.
Source code in cutiepynb/core.py
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 | |
cutiepy_nb(file, sns_palette=None, colors=None, save=True, update_colors=None, *, output_file=None, add_toc=True, toc_title=TOC_TITLE)
¶
Compatibility API for styling a notebook.
The transformed notebook dictionary is always returned. If save is
true, it is also written to output_file or to *_chulo.ipynb. This
wrapper keeps the original overwrite behavior; new applications should
prefer :func:process_notebook for explicit overwrite protection.
Source code in cutiepynb/core.py
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 | |