2727from collections .abc import Callable
2828from pathlib import Path
2929
30+ from rich .console import Console
31+ from rich .markdown import Markdown
32+
3033from .. import __version__
3134from ..core .analyzer_factory import build_analyzers
3235from ..core .loader import SkillLoadError
@@ -285,21 +288,26 @@ def _resolve_fail_severity(args: argparse.Namespace) -> str | None:
285288def _write_output (args : argparse .Namespace , output : str ) -> None :
286289 """Write *output* to a file or stdout, and emit any additional formats."""
287290 formats = _get_formats (args )
291+ primary_fmt = formats [0 ] if formats else "summary"
292+ render_md = sys .stdout .isatty () and not getattr (args , "no_render_markdown" , False )
288293
289294 # Primary format: write to --output file or stdout
290295 if args .output :
291296 with open (args .output , "w" , encoding = "utf-8" ) as fh :
292297 fh .write (output )
293298 print (f"Report saved to: { args .output } " )
294299 else :
295- print (output )
300+ if primary_fmt == "markdown" and render_md :
301+ Console ().print (Markdown (output ))
302+ else :
303+ print (output )
296304
297305 # Additional formats beyond the first: each gets its own --output-<fmt> file
298306 # or is printed to stdout if no file path is given.
299307 if len (formats ) > 1 :
300- # We already emitted formats[0] above.
301308 result_or_report = getattr (args , "_result_or_report" , None )
302309 if result_or_report is not None :
310+ console = Console ()
303311 for fmt in formats [1 :]:
304312 formatted = _format_single (fmt , args , result_or_report )
305313 output_key = f"output_{ fmt } "
@@ -309,7 +317,10 @@ def _write_output(args: argparse.Namespace, output: str) -> None:
309317 fh .write (formatted )
310318 print (f"{ fmt .upper ()} report saved to: { file_path } " )
311319 else :
312- print (formatted )
320+ if fmt == "markdown" and render_md :
321+ console .print (Markdown (formatted ))
322+ else :
323+ print (formatted )
313324
314325
315326# ---------------------------------------------------------------------------
@@ -703,6 +714,11 @@ def _add_common_scan_flags(parser: argparse.ArgumentParser) -> None:
703714 parser .add_argument ("--output-html" , help = "Write HTML report to this file (when using multiple --format)" )
704715 parser .add_argument ("--output-table" , help = "Write Table report to this file (when using multiple --format)" )
705716 parser .add_argument ("--detailed" , action = "store_true" , help = "Include detailed findings (Markdown output only)" )
717+ parser .add_argument (
718+ "--no-render-markdown" ,
719+ action = "store_true" ,
720+ help = "With --format markdown to terminal: print raw markdown instead of rendering (for pipe/copy)." ,
721+ )
706722 parser .add_argument ("--compact" , action = "store_true" , help = "Compact JSON output" )
707723 parser .add_argument (
708724 "--verbose" ,
0 commit comments