click_extra.capture.html module¶

Render captured terminal text as self-contained HTML.

click_extra.capture.screenshot decides what a capture shows, then hands the text, its palette and the resolved Chrome to render_html(), which writes them as an inline-styled <pre>: selectable, searchable text that needs no stylesheet and reflows with the page. The window around it is drawn with the geometry click_extra.capture.svg publishes, so the two documents look like the same terminal.

click_extra.capture.html.LINE_SPACING = 1.25¶

Height of a line of a capture’s <pre>, as a multiple of its font size.

Every box a run of shapes is drawn in is this tall too, so two stacked rows of shapes meet where their lines do.

click_extra.capture.html.block_css(char, count)[source]¶

Draw a run of one Block Elements character as shapes, in CSS.

The run becomes an inline block as tall as its line, and each rectangle BLOCK_ELEMENTS names becomes a background layer painted in the run’s own color: one layer across the run for a rectangle as wide as its cell, a band repeated cell by cell for a narrower one. A font draws the glyph shorter than the line, and an inline background covers only the font’s height, so either would leave a band between two stacked rows. The glyphs stay in the text, with a transparent fill.

Parameters:
  • char (str) – the Block Elements character.

  • count (int) – how many cells of it the run holds.

Return type:

str

Returns:

the declarations, semicolon-separated.

click_extra.capture.html.braille_css(char, count)[source]¶

Draw a run of one Braille pattern as dots, in CSS.

Each dot the pattern raises becomes a background layer: a disc in the run’s own color, at its place on a tile one cell wide, repeated along the run, see BRAILLE_DOTS. The disc’s edge fades over a pixel, which a hard stop would leave jagged.

Parameters:
  • char (str) – the Braille pattern.

  • count (int) – how many cells of it the run holds.

Return type:

str

Returns:

the declarations, semicolon-separated.

click_extra.capture.html.box_html(text)[source]¶

Draw a run of Box Drawing as an SVG filling the run’s box.

The SVG holds the lines box_svg() draws for an SVG capture, scaled to the run’s cells and painted in the run’s own color. One SVG spans the whole run, so a table’s rule is one shape: repeated cell by cell, a background would end each line on a fraction of a pixel and leave seams.

Parameters:

text (str) – the run, Box Drawing only.

Return type:

str

Returns:

the SVG markup, to sit in the run’s box, see _pre_markup().

click_extra.capture.html.render_html(text, *, title='', full=True, palette=('#292929', '#c5c8c6', ('#2e3436', '#cc0000', '#4e9a06', '#c4a000', '#3465a4', '#75507b', '#06989a', '#d3d7cf', '#555753', '#ef2929', '#8ae234', '#fce94f', '#729fcf', '#ad7fa8', '#34e2e2', '#eeeeec'), '#292929'), chrome=Chrome(border='none', border_width=1, radius=8, backdrop='none', shadow='none', margin=0, padding=0, opacity=1.0, watermark='', watermark_color='rgba(128,128,128,0.85)'), font_stack="'Fira Code', 'Cascadia Code', Menlo, Consolas, monospace")[source]¶

Render captured terminal text to HTML.

The <pre> carries its own inline styling, so a fragment pasted into an existing page needs no stylesheet and cannot be restyled out of legibility by the host. Nothing else is needed either: a <pre> preserves the capture’s own spacing, which is what spares HTML the column arithmetic render_svg() performs for a picture. Box Drawing, Block Elements and Braille patterns are the exception, drawn as shapes by box_html(), block_css() and braille_css().

Caution

The text is escaped before its ANSI is translated, the order click_extra.table uses for its html format. Skip it and any < a CLI prints opens a tag: click-extra’s own --export-config help says it writes to <stdout>.

Note

An OSC 8 hyperlink loses its URL and keeps its visible text: the escape is dropped rather than turned into an <a>.

Parameters:
  • text (str) – captured output, ANSI escape sequences included.

  • title (str) – <title> of the document. Ignored for a fragment.

  • full (bool) – wrap the <pre> in a standalone document. False returns the <pre> and its credit line alone, to paste into a page that has its own.

  • palette (TerminalPalette) – terminal colors the text resolves against, see resolve_palette().

  • chrome (Chrome) – the block around the text, resolved, see resolve(). Its margin is left around the block, its padding added inside the block on top of its own, its backdrop fills the page behind it, and its opacity thins the block’s background alone, down to 0.0 where the page shows straight through the text. The credit line sits under the block, against its right edge, where an SVG draws it in the margin. Defaults to BARE_CHROME.

  • font_stack (str) – fonts the text is set in, best first.

Return type:

str

Returns:

the rendered markup.

Raises:

ValueError – when chrome is not resolved.