block: fix container indent trim on enter
This commit is contained in:
		
					parent
					
						
							
								ec69d98c75
							
						
					
				
			
			
				commit
				
					
						64c7678775
					
				
			
		
					 1 changed files with 10 additions and 12 deletions
				
			
		
							
								
								
									
										22
									
								
								src/block.rs
									
										
									
									
									
								
							
							
						
						
									
										22
									
								
								src/block.rs
									
										
									
									
									
								
							|  | @ -254,13 +254,7 @@ impl<'s> TreeParser<'s> { | ||||||
|                         self.tree.exit(); |                         self.tree.exit(); | ||||||
|                     } |                     } | ||||||
|                     Block::Container(c) => { |                     Block::Container(c) => { | ||||||
|                         let (skip_chars, skip_lines_suffix) = match c { |                         let line_count_inner = lines.len() - usize::from(matches!(c, Div)); | ||||||
|                             Blockquote => (2, 0), |  | ||||||
|                             List{..} | DescriptionList => panic!(), |  | ||||||
|                             ListItem(..) | Footnote => (indent, 0), |  | ||||||
|                             Div => (0, 1), |  | ||||||
|                         }; |  | ||||||
|                         let line_count_inner = lines.len() - skip_lines_suffix; |  | ||||||
| 
 | 
 | ||||||
|                         // update spans, remove indentation / container prefix
 |                         // update spans, remove indentation / container prefix
 | ||||||
|                         lines |                         lines | ||||||
|  | @ -268,14 +262,18 @@ impl<'s> TreeParser<'s> { | ||||||
|                             .skip(1) |                             .skip(1) | ||||||
|                             .take(line_count_inner) |                             .take(line_count_inner) | ||||||
|                             .for_each(|sp| { |                             .for_each(|sp| { | ||||||
|                                 let skip = (sp |                                 let spaces = sp | ||||||
|                                     .of(self.src) |                                     .of(self.src) | ||||||
|                                     .chars() |                                     .chars() | ||||||
|                                     .take_while(|c| c.is_whitespace()) |                                     .take_while(|c| c.is_whitespace()) | ||||||
|                                     .count() |                                     .count(); | ||||||
|                                     + skip_chars) |                                 let skip = match c { | ||||||
|                                     .min(sp.len() - usize::from(sp.of(self.src).ends_with('\n'))); |                                     Blockquote => spaces + 2, | ||||||
|                                 *sp = sp.skip(skip); |                                     ListItem(..) | Footnote | Div => spaces.min(indent), | ||||||
|  |                                     List { .. } | DescriptionList => panic!(), | ||||||
|  |                                 }; | ||||||
|  |                                 let len = sp.len() - usize::from(sp.of(self.src).ends_with('\n')); | ||||||
|  |                                 *sp = sp.skip(skip.min(len)); | ||||||
|                             }); |                             }); | ||||||
| 
 | 
 | ||||||
|                         if let Container::ListItem(ty) = c { |                         if let Container::ListItem(ty) = c { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue