Skip to content

[Feature request] Add Console.export_markdown() to export recorded output as Markdown #4271

Open

Description

Motivation

Console can already export its recorded output as plain text (export_text), HTML (export_html) and SVG (export_svg), but there is no way to export it as Markdown. Markdown output would be useful for pasting rendered CLI output into README files, documentation, notebooks and GitHub issues while keeping basic styling such as bold, italic and links.

Proposal

Add a method mirroring export_text:

def export_markdown(
    self, *, clear: bool = True, escape_special_chars: bool = False
) -> str

Behaviour:

  • Requires the console to be created with record=True, otherwise it raises ValueError (same pattern as the other export methods).
  • Converts recorded segments to Markdown: bold to **...**, italic to *...*, bold + italic to ***...***, strikethrough to ~~...~~, and links to [text](url).
  • Preserves line endings and leading/trailing spaces outside the markup.
  • With escape_special_chars=True, punctuation characters in the content are backslash-escaped.
  • Clears the record buffer when clear=True (the default), like export_text.

Implementation

I have a working implementation with tests on my fork, and I would be happy to open a pull request — I noticed PR creation is currently limited to collaborators, which is why I am opening this issue first.

Documentation and a CHANGELOG entry are not included yet; I can add both if the maintainers are happy with the direction.

Would you be open to this addition?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions