File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2478,3 +2478,92 @@ fn markdown_formatting_preview_enabled() -> Result<()> {
24782478 "# ) ;
24792479 Ok ( ( ) )
24802480}
2481+
2482+ #[ test]
2483+ fn markdown_formatting_stdin ( ) -> Result < ( ) > {
2484+ let test = CliTest :: new ( ) ?;
2485+
2486+ let fixtures = Path :: new ( "resources" ) . join ( "test" ) . join ( "fixtures" ) ;
2487+ let unformatted = fs:: read ( fixtures. join ( "unformatted.md" ) ) . unwrap ( ) ;
2488+ assert_cmd_snapshot ! ( test. format_command( )
2489+ . args( [ "--isolated" , "--preview" , "--stdin-filename" , "unformatted.md" ] )
2490+ . arg( "-" )
2491+ . pass_stdin( unformatted) , @r#"
2492+ success: true
2493+ exit_code: 0
2494+ ----- stdout -----
2495+ This is a markdown document with some fenced code blocks with unformatted code.
2496+
2497+ Unlabeled Python code:
2498+
2499+ ```
2500+ print( "hello" )
2501+ ```
2502+
2503+ Unlabeled Rust code:
2504+
2505+ ```
2506+ fn thing() {
2507+ println!( "hello" );
2508+ }
2509+ ```
2510+
2511+ Labeled Python code:
2512+
2513+ ```py
2514+ print("hello")
2515+
2516+
2517+ def foo():
2518+ pass
2519+ ```
2520+
2521+ Labeled Python stub:
2522+
2523+ ```pyi
2524+ print("hello")
2525+
2526+ def foo():
2527+ pass
2528+ ```
2529+
2530+ Labeled Rust code:
2531+ ```rust
2532+ fn thing() {
2533+ println!( "hello" );
2534+ }
2535+ ```
2536+
2537+ Indented code blocks should also work:
2538+
2539+ * List item
2540+
2541+ ```py
2542+ print("hello")
2543+ ```
2544+
2545+ Block quoted code blocks may not be supported:
2546+
2547+ > Quoted text
2548+ >
2549+ > ```py
2550+ > print( "hello" )
2551+ > ```
2552+
2553+
2554+ Blacken-docs supports ignore directives:
2555+
2556+ <!-- blacken-docs:off -->
2557+ ```py
2558+ print("hello")
2559+ ```
2560+ <!-- blacken-docs:on -->
2561+
2562+ ```py
2563+ print("hello")
2564+ ```
2565+
2566+ ----- stderr -----
2567+ "# ) ;
2568+ Ok ( ( ) )
2569+ }
Original file line number Diff line number Diff line change @@ -130,6 +130,8 @@ impl SourceKind {
130130 Ok ( notebook
131131 . is_python_notebook ( )
132132 . then_some ( Self :: IpyNotebook ( Box :: new ( notebook) ) ) )
133+ } else if source_type. is_markdown ( ) {
134+ Ok ( Some ( Self :: Markdown ( source_code) ) )
133135 } else {
134136 Ok ( Some ( Self :: Python ( source_code) ) )
135137 }
You can’t perform that action at this time.
0 commit comments