xnano.utils.markup
xnano.utils.markup
¶
xnano.utils.markup
Parse ANSI, highlighted source code, and Markdown into styled text runs.
Functions:
-
strip_ansi_escapes–Return
contentwith all ANSI escape sequences removed. -
parse_ansi_lines–Parse ANSI-escaped content into styled
Runlines. -
highlight_lines–Syntax-highlight
contentinto styledRunlines. -
markdown_lines–Parse markdown
contentinto styledRunlines. -
markdown_blocks–Parse markdown into an ordered list of text and image blocks.
MarkdownBlock
module-attribute
¶
MarkdownBlock: TypeAlias = (
"tuple[str, tuple[tuple[Run, ...], ...]] | tuple[str, str, str]"
)
One parsed block: ("text", lines) or ("image", src, alt).
strip_ansi_escapes
¶
parse_ansi_lines
cached
¶
Parse ANSI-escaped content into styled Run lines.
SGR (color/style) sequences become run styles carried across lines; all other escape sequences are stripped, not emulated — this is a log view, not a terminal emulator.
Parameters:
-
content(str) –Raw text containing ANSI escape sequences.
Returns:
Source code in xnano/utils/markup.py
highlight_lines
cached
¶
Syntax-highlight content into styled Run lines.
Parameters:
-
content(str) –Source code to highlight.
-
language(str) –A Pygments lexer name (
"python","rust", …). Unknown names fall back to plain text.
Returns:
Source code in xnano/utils/markup.py
markdown_lines
cached
¶
Parse markdown content into styled Run lines.
Headings render bold in an accent color, emphasis/strong map to italic/bold, list items get bullets, blockquotes render dim, inline code renders reversed, and fenced code blocks are syntax-highlighted by their fence language tag. Tables and images are out of scope and render as their plain text.
Parameters:
-
content(str) –Markdown source.
Returns:
Source code in xnano/utils/markup.py
markdown_blocks
cached
¶
Parse markdown into an ordered list of text and image blocks.
Text is grouped into ("text", lines) blocks of styled runs, the
same as :func:markdown_lines. Each Markdown image is split out into
its own ("image", src, alt) block so a document viewer can render
it as a real terminal image between the surrounding text.
Parameters:
-
content(str) –Markdown source.
Returns:
-
Any–A tuple of
("text", lines)and("image", src, alt)blocks -
...–in document order.
Source code in xnano/utils/markup.py
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 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 498 499 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 530 531 532 533 534 535 536 537 538 539 540 541 542 543 | |