click_extra.sphinx.click module¶

Sphinx rendering of CLI based on Click Extra.

Holds the click:source and click:run directives, their options, and the :screenshot: captures and :mirror: regions they maintain. click_extra.sphinx.click_runner runs their blocks, and click_extra.sphinx.click_reference builds the click:tree and click:config reference directives on top of them.

See also

These directives are based on Pallets’ Sphinx Themes, released under a BSD-3-Clause license.

Compared to the latter, it:

  • Adds support for MyST syntax.

  • Adds rendering of ANSI codes in CLI results.

  • Has better error handling and reporting which helps you pinpoint the failing code in your documentation.

  • Has no println function: a block prints a blank line natively.

Todo

Collapse ContentOffsetMixin.abs_content_offset of click_extra.sphinx._base onto its rST branch (content_offset verbatim) once a myst-parser release carries the open rework #1175, which makes content_offset document-relative.

click_extra.sphinx.click.RST_INDENT = '   '¶

The indentation used for rST code blocks lines.

click_extra.sphinx.click.DEFAULT_SCREENSHOT_DIR = 'assets'¶

Directory a click:run :screenshot: capture is written to by default.

Relative to the documentation source root. Overridden by the click_extra_screenshot_dir conf.py value, see SCREENSHOT_DIR_CONFIG.

click_extra.sphinx.click.RUN_CAPTURE_CONFIG = 'click_extra_run_capture'¶

Name of the conf.py value selecting the stream-capture mode for the CLIs that click:run and click:tree execute.

Maps to the capture parameter of Click’s CliRunner, "sys" or "fd". Defaults to "fd", which also captures what a subprocess or a C extension writes to the standard file descriptors: see ClickRunner for what it leaves out. Windows has no file-descriptor capture, so "fd" degrades to "sys" there.

click_extra.sphinx.click.SCREENSHOT_DIR_CONFIG = 'click_extra_screenshot_dir'¶

Name of the conf.py value locating the directory click:run writes captures to.

A path relative to the documentation source directory, holding the SVG a click:run block names with its :screenshot: option. Defaults to DEFAULT_SCREENSHOT_DIR, matching where a Sphinx project conventionally keeps the images its pages embed, and where a README pointing at the repository finds them.

click_extra.sphinx.click.SCREENSHOT_PRESET_CONFIG = 'click_extra_screenshot_preset'¶

Name of the conf.py value naming the terminal every capture is drawn as.

One of PRESETS, applied to each click:run block whose :screenshot: does not name a preset of its own. Empty by default, which keeps the renderer’s neutral window: a project wanting all of its captures to look like the same desktop states it once here instead of on every block.

click_extra.sphinx.click.SCREENSHOT_SYNTAX_STYLE_CONFIG = 'click_extra_screenshot_syntax_style'¶

Name of the conf.py value coloring every capture drawn from source code.

One of the Pygments styles, applied to each source block whose :screenshot: does not name a :screenshot-syntax-style: of its own. Empty by default, which takes the style each chrome is drawn for, see DEFAULT_SYNTAX_STYLES. Unused by a block picturing what a command printed, whose colors that command already chose.

click_extra.sphinx.click.SCREENSHOT_WATERMARK_CONFIG = 'click_extra_screenshot_watermark'¶

Name of the conf.py value crediting every capture a click:run writes.

Empty by default, which draws no credit line: unlike a capture of the screenshot command, a block’s image sits on a page that already says what drew it. A project wanting a credit states its text here, or per block with :screenshot-watermark:.

click_extra.sphinx.click.SCREENSHOT_MARKER_START = '<!-- screenshot -->'¶

Opening marker of a click:run :mirror: region.

Written on its own line, directly below the fence, and paired with SCREENSHOT_MARKER_END. The region holds the Markdown link to the capture the block’s :screenshot: option names, so the image shows wherever the raw Markdown is read: on GitHub, on PyPI, in an editor’s preview.

Same <!-- name --> / <!-- name-end --> grammar as the python:render :mirror: regions, under a name saying what this one holds. Unlike those, the region’s content is derived from the option alone, never from executing anything: it goes stale only when the capture is renamed, which is why no build-time pass regenerates it in memory.

click_extra.sphinx.click.SCREENSHOT_MARKER_END = '<!-- screenshot-end -->'¶

Closing marker of a :mirror: region. See SCREENSHOT_MARKER_START.

click_extra.sphinx.click.register_config(app)[source]¶

Declare the conf.py values the click:* directives read.

Called by click_extra.sphinx.setup() beside the opt-in flag gating the directives, and whether or not the project opts in: a conf.py naming one of these values is then valid on every project loading the extension.

Return type:

None

class click_extra.sphinx.click.ClickDirective(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine)[source]¶

Bases: ContentOffsetMixin

Base class of every click:* directive.

has_content = True¶

May the directive have content?

required_arguments = 0¶

Number of required directive arguments.

optional_arguments = 1¶

The optional argument overrides the default Pygments language to use.

final_argument_whitespace = False¶

May the final argument contain whitespace?

option_spec: ClassVar[OptionSpec] = {'caption': <function unchanged_required>, 'class': <function class_option>, 'dedent': <function optional_int>, 'emphasize-lines': <function unchanged_required>, 'emphasize-result-lines': <function unchanged_required>, 'force': <function flag>, 'hide-prompt': <function flag>, 'hide-results': <function flag>, 'hide-source': <function flag>, 'language': <function unchanged_required>, 'lineno-start': <class 'int'>, 'linenos': <function flag>, 'mirror': <function flag>, 'name': <function unchanged>, 'screenshot': <function unchanged_required>, 'screenshot-animate': <function unchanged_required>, 'screenshot-backdrop': <function unchanged_required>, 'screenshot-background': <function _screenshot_background>, 'screenshot-blank': <function parse_pause>, 'screenshot-blink': <function parse_pause>, 'screenshot-border': <function unchanged_required>, 'screenshot-border-width': <function nonnegative_int>, 'screenshot-closing-prompt': <function flag>, 'screenshot-columns': <function parse_columns>, 'screenshot-cursor': <function _screenshot_cursor>, 'screenshot-emphasize-lines': <function unchanged_required>, 'screenshot-end': <function _positive_number>, 'screenshot-font': <function parse_font_stack>, 'screenshot-hold': <function parse_hold>, 'screenshot-interval': <function _positive_number>, 'screenshot-line-numbers': <function flag>, 'screenshot-margin': <function nonnegative_int>, 'screenshot-opacity': <function _screenshot_opacity>, 'screenshot-padding': <function nonnegative_int>, 'screenshot-palette': <function path>, 'screenshot-preset': <function _screenshot_preset>, 'screenshot-prompt': <function unchanged>, 'screenshot-quantum': <function _positive_number>, 'screenshot-radius': <function nonnegative_int>, 'screenshot-record': <function unchanged_required>, 'screenshot-shadow': <function unchanged_required>, 'screenshot-speed': <function _positive_number>, 'screenshot-start': <function _non_negative_number>, 'screenshot-submit': <function _positive_number>, 'screenshot-syntax-style': <function unchanged_required>, 'screenshot-title': <function unchanged_required>, 'screenshot-typing': <function _positive_number>, 'screenshot-watermark': <function unchanged_required>, 'screenshot-watermark-color': <function unchanged_required>, 'show-prompt': <function flag>, 'show-results': <function flag>, 'show-source': <function flag>}¶

Options supported by this directive.

Support the same options as sphinx.directives.code.CodeBlock, and some specific to Click directives.

The standard emphasize-lines option applies to the source block only. Use emphasize-result-lines to highlight specific lines in the captured output block, with the same syntax (like :emphasize-result-lines: 1,3-5).

Every directive carries the :screenshot: family, because every one of them shows something worth committing as an image. What lands in that image is whatever the block itself draws: a run’s captured output, and a source block’s own code, highlighted by click_extra.capture.snippet.

:screenshot: and :mirror: are deliberately independent. :screenshot: <name>``only *writes*``<name>.svg``under the``click_extra_screenshot_dir, leaving the page’s code block alone: inside Sphinx that block beats an image, being selectable, searchable and theme-aware. :mirror: is what puts the image on the page, by keeping a Markdown link to it in the source .md between the same marker pair the python:render :mirror: flag uses, so the capture shows on GitHub and PyPI as well.

So :screenshot: alone maintains an asset some other surface embeds, and the two together also show it here. Both are refreshed offline by click-extra refresh-directives.

default_language: str¶

Default highlighting language to use to render the code block.

All Pygments’ languages short names are recognized.

source_language: str | None = None¶

Language the source block is highlighted in, when it is not language.

None for a directive showing code of the language it names: the source block of a click:source follows its :language: option. A directive that runs a block names the language of its results instead, so it states the language of the code producing them here, python for every runner of this package.

screenshots_source: bool = False¶

Whether a :screenshot: on this directive pictures the block’s own code.

False for a directive that runs something: what is worth committing there is the output, and the code producing it is on the page already. True for one that only declares code, which has no output to picture and whose subject is the code itself. See screenshot_lines().

show_source_by_default: bool = True¶

Whether to render the source code of the example in the code block.

show_results_by_default: bool = True¶

Whether to render the results of the example in the code block.

show_prompt_by_default: bool = True¶

Whether to draw the invocation above the results it produced.

runner_method: str¶

The name of the method to call on the per-document runner.

A ClickRunner for the click:* directives.

runner_attr: ClassVar[str] = 'click_runner'¶

Name of the attribute holding the runner on the doctree.

Subclasses (like PythonDirective) override this so the Click and Python runners don’t collide on the same document.

runner_factory¶

Class to instantiate for the per-document runner.

Called with the capture mode the click_extra_run_capture conf.py value resolves to, see runner.

alias of ClickRunner

property runner¶

Get or create the per-document runner.

Creates one runner per document, keyed by runner_attr.

property language: str[source]¶

Short name of the Pygments lexer used to highlight the code block.

Returns, in order of precedence, the language specified in the :language: directive options, the first argument of the directive (if any), or the default set in the directive class.

code_block_options(target='source')[source]¶

Render the options supported by Sphinx’ native code-block directive.

target selects which block these options will be attached to: "source" for the directive’s input source code, "results" for the captured output. emphasize-lines routes to the source block; emphasize-result-lines is rewritten as emphasize-lines on the results block, so authors can highlight different lines in each.

Return type:

list[str]

property show_source: bool[source]¶

Whether to show the source code of the example in the code block.

The last occurrence of either show-source or hide-source options wins. If neither is set, the default is taken from show_source_by_default.

property show_results: bool[source]¶

Whether to show the results of running the example in the code block.

The last occurrence of either show-results or hide-results options wins. If neither is set, the default is taken from show_results_by_default.

property show_prompt: bool[source]¶

Whether to draw the invocation above the output it produced.

The last occurrence of either show-prompt or hide-prompt options wins. If neither is set, the default is taken from show_prompt_by_default.

The prompt is one line rendered by format_cli_prompt(), prepended to the captured output. It is therefore part of the results, not a block of its own: hiding it drops it from the results code block and from the SVG a :screenshot: writes, which is drawn from the same lines. Reach for it when the invocation is noise the surrounding prose already carries, or when a capture is wanted as bare output.

evaluate(expression, subject)[source]¶

Evaluate expression in the runner namespace of the document.

The namespace is the one the earlier blocks of the page filled, so an expression names what a click:source above built. subject opens the error, naming what asked for the evaluation: a directive, like click:tree, or one of its options, like click:run: :screenshot-animate:.

Raises:

RuntimeError – when the expression cannot be evaluated.

Return type:

Any

render_code_block(lines, language, target='source')[source]¶

Render the code block with the source code or results.

target is forwarded to code_block_options() so the emphasize-lines / emphasize-result-lines split routes the right highlighting to each block.

Return type:

list[str]

property screenshot: str | None[source]¶

Name of the SVG capture this block renders to, without its extension.

Set by the :screenshot: option. None when the block renders its results as a code block, which is the default.

property screenshot_background: TerminalBackground[source]¶

Chrome the capture is drawn on, set by :screenshot-background:.

Defaults to the dark chrome a terminal and this package’s default theme both look like. A block rendering a light-background theme says so, or its capture washes out: see TerminalBackground.

property screenshot_columns: int | Literal['auto'][source]¶

Width the capture is laid out at, set by :screenshot-columns:.

Defaults to the fixed width a terminal capture is taken at. auto sizes the image to the longest line the block printed, which is what a run holding a line Click does not wrap needs to keep on one line: a prompt, a wide table, a machine-readable dump.

resolve_animation(expression, option)[source]¶

Frames the capture animates, set by :screenshot-animate:.

The option is a Python expression, evaluated in the same per-document namespace the block’s own source runs in, so a click:source block above can build the subject and this one picture it. It yields either:

  • a Spinner, whose frame_lines() and interval are taken as they stand, which is the whole declaration for a spinner;

  • a sequence of Frame, as a recording hands back, each carrying the screen it held and for how long. Those durations are wall-clock, so they are rounded onto a grid before they reach the picture, see :screenshot-quantum:. :screenshot-start: and :screenshot-end: first keep the slice between two times of the recording, see start_at() and end_at();

  • any other sequence of strings, one captured text per frame, whose :screenshot-interval: says how long each is shown.

:screenshot-interval: overrides a spinner’s own when both are stated, and times a recording flatly when it would rather not keep the pace it was recorded at.

Caution

An animated block pictures its frames, not its results. The block still runs, and its results still render on the page as any other block’s do, but they are not what the image shows.

A declared subject keeps the committed asset deterministic outright: the same expression composes the same lines on every build. A recording cannot, its frames being timed by the wall clock, so it is written once: write_screenshot() leaves an asset that carries an @recording line alone.

Return type:

tuple[tuple[str, ...], float | tuple[float, ...]]

Returns:

the frames and how long each is shown, or None when the block draws a still.

Raises:
  • RuntimeError – when the expression cannot be evaluated.

  • TypeError – when it yields neither a spinner nor strings.

  • ValueError – when a bare sequence of frames states no interval, or when :screenshot-start: or :screenshot-end: cut anything but a recording, or cut all of it.

refuse_cuts(expression)[source]¶

Fail a block cutting a slice out of frames nobody recorded.

Only a recording has seconds to drop: a spinner and a declared sequence cycle in place, so no moment of theirs is worth starting or ending on. Saying so beats drawing the animation as if the option were not there.

Parameters:

expression (str) – the expression the frames came from.

Raises:

ValueError – when the block states :screenshot-start: or :screenshot-end:.

Return type:

None

property screenshot_animation: tuple[tuple[str, ...], float | tuple[float, ...]] | None[source]¶

Frames a declared animation draws, set by :screenshot-animate:.

Declared frames are composed rather than timed, so they come out the same on every build and the asset is regenerated like any other, which is what keeps it from drifting away from the code. See resolve_animation() for what the expression may yield, and :screenshot-record: for the case that cannot be regenerated.

Returns:

the frames and how long each is shown, or None when the block draws a still.

property emphasis_spec: str | None¶

The lines the capture bands, as the block spells them.

Only :screenshot-emphasize-lines: on a directive whose image is its output: the block’s three emphasis options then mark three different contents, and folding any two together would band the wrong one.

A block picturing its own code has one content, so :emphasize-lines: marks the same lines in the page’s code block and in the image, and saying it twice would be the surprise. :screenshot-emphasize-lines: still overrides it where the two should differ.

screenshot_emphasis(total)[source]¶

Lines the capture bands, set by :screenshot-emphasize-lines:.

Takes the same specification :emphasize-lines: does, 1,3-5 and the rest, and counts from one the same way. It is read here rather than at option-parsing time because the specification may name a range open at one end, which only means something once the capture’s height is known.

Parameters:

total (int) – how many lines the capture is drawing.

Return type:

tuple[int, ...]

Returns:

the lines to band, counted from one.

Raises:

ValueError – when the specification names no readable line.

numbered(frames)[source]¶

Number every frame’s lines when :screenshot-line-numbers: asks.

Counted within each frame rather than once across the animation: a frame is a screen, and a screen’s gutter numbers the rows it is showing. An animation whose rows accumulate therefore numbers more of them as it goes. The gutter is as wide on every frame as on the tallest, so no row moves when the count gains a digit, see number_frames().

Parameters:

frames (tuple[str, ...]) – the animation’s frames.

Return type:

tuple[str, ...]

Returns:

the same frames, each with a gutter, or unchanged.

screenshot_hold(fallback)[source]¶

Seconds the last frame stays up, set by :screenshot-hold:.

Parameters:

fallback (float | Literal['auto']) – what to hold for when the block states nothing.

Return type:

float | Literal['auto']

Returns:

the pause, in seconds, or the auto sentinel.

property screenshot_syntax_style: str[source]¶

Pygments style a source capture is colored with.

Set by :screenshot-syntax-style:, falling back to the click_extra_screenshot_syntax_style conf.py value, then to the one the chrome is drawn for. Unused by a directive picturing its output, whose colors the command it ran already chose.

Returns:

the style’s name.

Raises:

ValueError – when the name is not a style Pygments knows.

property screenshot_scheme: TerminalPalette | None[source]¶

Terminal colors the capture is drawn in, set by :screenshot-palette:.

The option names a color scheme file, see read_palette(), relative to the page or, opening on /, to the source root, as literalinclude reads its path. The page is then rebuilt whenever the scheme changes.

Returns:

the scheme’s palette, or None when the block names none.

Raises:

ValueError – when the file cannot be read, or holds no scheme.

property screenshot_palette: TerminalPalette | None[source]¶

Colors a still capture resolves against, beyond what the chrome names.

A capture of a terminal, which is every run, takes the screenshot_scheme, and None when the block names none: its colors are then the terminal’s own, and the chrome already answers for them. A capture of code takes them from its syntax style instead, background included, so the picture looks like that style does in an editor.

Raises:

ValueError – when a block picturing its code names a scheme, as its colors come from :screenshot-syntax-style:, like the snippet command’s do.

screenshot_lines(results)[source]¶

The lines the still capture draws, before its gutter is added.

The captured output, with one substitution: a block is run by a documentation build rather than by the terminal it pictures, so it prompts with this platform’s sigil where the drawn terminal has its own.

A block picturing its own code draws that instead, colored by highlight_code() into the same ANSI a command would have printed. It has no prompt to substitute, and results is whatever its runner returned, which for a source block is nothing.

Parameters:

results (Iterable[str]) – what the block’s runner returned.

Return type:

list[str]

Returns:

the lines to draw.

Raises:

ValueError – when the block names a language or style Pygments does not know.

property screenshot_frame: dict[str, Any][source]¶

Window the capture is drawn in, set by the :screenshot-*: options.

Each entry is left out when its option is: the renderer then picks what the chrome asks for, which is what every block on these pages wants. :screenshot-backdrop:, :screenshot-border: and :screenshot-shadow: take a CSS color (or none to paint neither), :screenshot-border-width:, :screenshot-margin:, :screenshot-padding: and :screenshot-radius: take pixels, :screenshot-opacity: how solid the window’s body is, :screenshot-title: the caption drawn in the window’s own chrome, and :screenshot-watermark: a credit line for the image’s corner, which no capture carries here unless asked for. :screenshot-font: names the font families the text is set in, see parse_font_stack(). :screenshot-line-numbers: is a flag, numbering every line the block rendered, its prompt first. :screenshot-cursor: draws a terminal cursor, in the shape it names or in the preset’s own, and :screenshot-blink: says how long one blink takes. See render_svg().

A block naming no preset falls back to the one the click_extra_screenshot_preset conf.py value names, so a project drawing all of its captures as the same terminal states it once.

property invocation: str[source]¶

The command line the capture draws above itself, styled as a prompt.

Set by :screenshot-prompt:, which states the line a reader would type rather than anything the block ran: a click:run block invokes a Python callable, so there is no argv to recover one from. Styled exactly as a still capture styles its own, see prompt_line().

Note

Animations only. A still block already prints its invocation, so the option would draw it twice; the animated paths are the ones holding what a command drew and nothing about the command line that drew it.

Returns:

the styled line, empty when the block states none.

closed(frames)[source]¶

Put the shell’s prompt under the last frame, when asked.

:screenshot-closing-prompt: draws the sigil on the row a finished command leaves the shell waiting on, see append_prompt(). The last frame alone carries it: the shell has not come back while the command is still drawing.

Parameters:

frames (tuple[str, ...]) – the animation’s frames, in order.

Return type:

tuple[str, ...]

Returns:

the same frames, the last one closed, or unchanged.

opened(frames, interval)[source]¶

Draw the invocation over an animation, and type it when asked.

A block records what a command drew and never the command line that drew it, so an animation opens on output arriving from nowhere. :screenshot-prompt: puts the line back over every frame, and :screenshot-typing: opens on it being typed, one character a frame, see type_line().

Parameters:
  • frames (tuple[str, ...]) – the animation’s frames, in order.

  • interval (float | tuple[float, ...]) – how long each is shown, one number for all alike.

Return type:

tuple[tuple[str, ...], float | tuple[float, ...]]

Returns:

the frames and their timing, both grown by the opening.

render_animation(frames, interval, *, hold, blank)[source]¶

Draw an animated capture of frames, whatever produced them.

The two animated paths agree on everything but what closes a cycle: a recording ends somewhere and pauses on that ending, while a declared animation turns in place and ends nowhere, so it pauses for nothing unless the block asks. Both fallbacks are overridden by :screenshot-hold: and :screenshot-blank:.

Parameters:
  • frames (tuple[str, ...]) – the animation’s frames, in order.

  • interval (float | tuple[float, ...]) – how long each of them is shown.

  • hold (float | Literal['auto']) – seconds the last frame stays up when the block states none.

  • blank (float) – seconds of empty screen closing the cycle when the block states none.

Return type:

str

Returns:

the SVG document.

write_screenshot(results)[source]¶

Write the captured output as an SVG beside the documentation.

The file lands in the directory the click_extra_screenshot_dir conf.py value names, under the source root, so a README pointing at the repository embeds the very output this page renders live.

This is a side effect, not a rendering: the page keeps its results code block, which stays selectable, searchable and theme-aware where an image would not be. Use :mirror: to put the image on the page as well.

Writing during the build keeps the committed asset in step with the CLI without anyone remembering to refresh it. unique_id is pinned to the asset’s name, so an unchanged CLI draws the same bytes, and the file is then left alone, its modification time included. Only the generator’s release stamps and any output that varies by machine can change.

Note

That refresh only happens when the document carrying the block is re-parsed: Sphinx’s environment cache skips unchanged sources. A change on the package side (a new config format widening a --config default, say) leaves every capture stale until a rebuild with a fresh environment (sphinx-build -E).

Return type:

None

run()[source]¶

Execute the directive and render its source and results.

Return type:

list[Node]

class click_extra.sphinx.click.SourceDirective(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine)[source]¶

Bases: ClickDirective

Directive to declare a Click CLI source code.

This directive is used to declare a Click CLI example in the documentation. It renders the source code of the example in a Python code block.

default_language: str = 'python'¶

Default highlighting language to use to render the code block.

All Pygments’ languages short names are recognized.

show_source_by_default: bool = True¶

Whether to render the source code of the example in the code block.

show_results_by_default: bool = False¶

Whether to render the results of the example in the code block.

runner_method: str = 'execute_source'¶

The name of the method to call on the per-document runner.

A ClickRunner for the click:* directives.

screenshots_source: bool = True¶

Whether a :screenshot: on this directive pictures the block’s own code.

False for a directive that runs something: what is worth committing there is the output, and the code producing it is on the page already. True for one that only declares code, which has no output to picture and whose subject is the code itself. See screenshot_lines().

class click_extra.sphinx.click.RunDirective(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine)[source]¶

Bases: ClickDirective

Directive to run a Click CLI example.

This directive is used to run a Click CLI example in the documentation. It renders the results of running the example in a shell session code block supporting ANSI colors.

default_language: str = 'ansi-shell-session'¶

Default highlighting language to use to render the code block.

All Pygments’ languages short names are recognized.

show_source_by_default: bool = False¶

Whether to render the source code of the example in the code block.

show_results_by_default: bool = True¶

Whether to render the results of the example in the code block.

runner_method: str = 'run_cli'¶

The name of the method to call on the per-document runner.

A ClickRunner for the click:* directives.

source_language: str | None = 'python'¶

Language the source block is highlighted in, when it is not language.

None for a directive showing code of the language it names: the source block of a click:source follows its :language: option. A directive that runs a block names the language of its results instead, so it states the language of the code producing them here, python for every runner of this package.

click_extra.sphinx.click.rewrite_screenshot_regions(text, directory='assets')[source]¶

Return text with every capture block’s :mirror: region refreshed.

Only a top-level click:run, click:source, python:run or python:source fence carrying both :screenshot: and :mirror: gets a region, holding the Markdown link to the capture. The walk, the insertion and the idempotency are those of click_extra.markdown.blocks.rewrite_fenced_regions().

The image itself is written by the directive at build time. This only maintains the Markdown pointing at it. The click-extra refresh-directives command calls it on each page, and update_screenshot_blocks() on each file it is given.

Return type:

str

click_extra.sphinx.click.update_screenshot_blocks(paths, *, check=False, directory='assets')[source]¶

Refresh every capture block’s :mirror: region in the given sources.

See click_extra.markdown.blocks.update_blocks() for the walk, write, and check-mode contract. Unlike the python:render :mirror: refresher, this executes nothing: a region’s content is derived from the block’s :screenshot: name.

Parameters:
  • paths (Iterable[Path]) – Markdown files, or directories recursed for *.md.

  • check (bool) – report what would change without writing.

  • directory (str) – where the captures live, relative to each document.

Return type:

list[Path]

Returns:

the files whose regions were (or, under check, would be) updated.

click_extra.sphinx.click.cleanup_runner(app, doctree)¶

Drop the ClickRunner from the doctree.

Connected to doctree-read, so it runs once the document is read.

Return type:

None