1
- use super :: common:: * ;
2
- use super :: gen_types:: * ;
3
- use super :: utils;
4
- use crate :: configuration:: * ;
5
1
use dprint_core:: formatting:: condition_resolvers;
6
2
use dprint_core:: formatting:: conditions:: * ;
7
3
use dprint_core:: formatting:: ir_helpers:: * ;
@@ -11,6 +7,11 @@ use std::borrow::Cow;
11
7
use std:: rc:: Rc ;
12
8
use unicode_width:: UnicodeWidthStr ;
13
9
10
+ use super :: common:: * ;
11
+ use super :: gen_types:: * ;
12
+ use super :: utils;
13
+ use crate :: configuration:: * ;
14
+
14
15
pub fn generate ( node : & Node , context : & mut Context ) -> PrintItems {
15
16
// eprintln!("Kind: {:?}", node.kind());
16
17
// eprintln!("Text: {:?}", node.text(context));
@@ -38,7 +39,6 @@ pub fn generate(node: &Node, context: &mut Context) -> PrintItems {
38
39
Node :: List ( node) => gen_list ( node, false , context) ,
39
40
Node :: Item ( node) => gen_item ( node, context) ,
40
41
Node :: TaskListMarker ( _) => unreachable ! ( "this should be handled by gen_paragraph" ) ,
41
- Node :: TaskListMarker ( _) => unreachable ! ( "this should be handled by gen_paragraph" ) ,
42
42
Node :: HorizontalRule ( node) => gen_horizontal_rule ( node, context) ,
43
43
Node :: SoftBreak ( _) => PrintItems :: new ( ) ,
44
44
Node :: HardBreak ( _) => gen_hard_break ( context) ,
@@ -75,9 +75,7 @@ fn gen_nodes(nodes: &[Node], context: &mut Context) -> PrintItems {
75
75
let mut last_node: Option < & Node > = None ;
76
76
let mut node_iterator = nodes. iter ( ) . filter ( |n| !matches ! ( n, Node :: SoftBreak ( _) ) ) ;
77
77
78
- while let Some ( node) = node_iterator. next ( ) {
79
- let mut node = node;
80
-
78
+ while let Some ( mut node) = node_iterator. next ( ) {
81
79
// handle alternate lists
82
80
if let Some ( Node :: List ( last_list) ) = & last_node {
83
81
if let Node :: List ( list) = & node {
@@ -136,7 +134,21 @@ fn gen_nodes(nodes: &[Node], context: &mut Context) -> PrintItems {
136
134
let new_line_count = context. get_new_lines_in_range ( between_range. 0 , between_range. 1 ) ;
137
135
138
136
if new_line_count == 1 {
139
- if matches ! ( node, Node :: Html ( _) ) {
137
+ // Callout example:
138
+ // > [!NOTE]
139
+ // > Some note.
140
+ let is_callout = if context. is_in_block_quote ( ) && matches ! ( node, Node :: Text ( _) ) {
141
+ if let Node :: Text ( text) = last_node {
142
+ is_callout_text ( & text. text )
143
+ } else {
144
+ false
145
+ }
146
+ } else {
147
+ false
148
+ } ;
149
+ if is_callout && !context. is_text_wrap_disabled ( ) {
150
+ items. push_signal ( Signal :: NewLine ) ; // force a newline
151
+ } else if matches ! ( node, Node :: Html ( _) ) {
140
152
items. push_signal ( Signal :: NewLine ) ;
141
153
} else {
142
154
items. extend ( get_newline_wrapping_based_on_config ( context) ) ;
@@ -163,6 +175,7 @@ fn gen_nodes(nodes: &[Node], context: &mut Context) -> PrintItems {
163
175
if node. starts_with_list_word ( ) {
164
176
items. push_space ( ) ;
165
177
} else {
178
+ if matches ! ( last_node, Node :: Text ( _) ) && matches ! ( node, Node :: Text ( _) ) { }
166
179
items. extend ( get_space_or_newline_based_on_config ( context) ) ;
167
180
}
168
181
}
@@ -423,6 +436,11 @@ fn gen_text(text: &Text, context: &mut Context) -> PrintItems {
423
436
gen_str ( & text. text , context)
424
437
}
425
438
439
+ fn is_callout_text ( text : & str ) -> bool {
440
+ // ex. [!NOTE]
441
+ text. starts_with ( "[!" ) && text. ends_with ( "]" ) && text[ 2 ..text. len ( ) - 1 ] . chars ( ) . all ( |c| c. is_ascii_uppercase ( ) )
442
+ }
443
+
426
444
fn gen_str ( text : & str , context : & mut Context ) -> PrintItems {
427
445
let mut text_builder = TextBuilder :: new ( context) ;
428
446
0 commit comments