Add SoftBreakAddsNewLinePlugin plugin in core module
This commit is contained in:
		
							parent
							
								
									cc35c35581
								
							
						
					
					
						commit
						9532d32e8d
					
				| @ -13,6 +13,8 @@ | |||||||
|   ``` |   ``` | ||||||
| * `JLatexMathPlugin`: add `theme` (to customize both inlines and blocks) | * `JLatexMathPlugin`: add `theme` (to customize both inlines and blocks) | ||||||
| * `JLatexMathPlugin`: add `renderMode` to use previous (pre `4.3.0`) LaTeX rendering | * `JLatexMathPlugin`: add `renderMode` to use previous (pre `4.3.0`) LaTeX rendering | ||||||
|  | * add `SoftBreakAddsNewLinePlugin` plugin (`core` module) | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| # 4.2.2 | # 4.2.2 | ||||||
| * Fixed `AsyncDrawable` display when it has placeholder with empty bounds ([#189]) | * Fixed `AsyncDrawable` display when it has placeholder with empty bounds ([#189]) | ||||||
|  | |||||||
| @ -0,0 +1,26 @@ | |||||||
|  | package io.noties.markwon; | ||||||
|  | 
 | ||||||
|  | import androidx.annotation.NonNull; | ||||||
|  | 
 | ||||||
|  | import org.commonmark.node.SoftLineBreak; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * @since 4.3.0-SNAPSHOT | ||||||
|  |  */ | ||||||
|  | public class SoftBreakAddsNewLinePlugin extends AbstractMarkwonPlugin { | ||||||
|  | 
 | ||||||
|  |     @NonNull | ||||||
|  |     public static SoftBreakAddsNewLinePlugin create() { | ||||||
|  |         return new SoftBreakAddsNewLinePlugin(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void configureVisitor(@NonNull MarkwonVisitor.Builder builder) { | ||||||
|  |         builder.on(SoftLineBreak.class, new MarkwonVisitor.NodeVisitor<SoftLineBreak>() { | ||||||
|  |             @Override | ||||||
|  |             public void visit(@NonNull MarkwonVisitor visitor, @NonNull SoftLineBreak softLineBreak) { | ||||||
|  |                 visitor.forceNewLine(); | ||||||
|  |             } | ||||||
|  |         }); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -21,6 +21,7 @@ import io.noties.markwon.Markwon; | |||||||
| import io.noties.markwon.MarkwonConfiguration; | import io.noties.markwon.MarkwonConfiguration; | ||||||
| import io.noties.markwon.MarkwonSpansFactory; | import io.noties.markwon.MarkwonSpansFactory; | ||||||
| import io.noties.markwon.MarkwonVisitor; | import io.noties.markwon.MarkwonVisitor; | ||||||
|  | import io.noties.markwon.SoftBreakAddsNewLinePlugin; | ||||||
| import io.noties.markwon.core.MarkwonTheme; | import io.noties.markwon.core.MarkwonTheme; | ||||||
| import io.noties.markwon.image.ImageItem; | import io.noties.markwon.image.ImageItem; | ||||||
| import io.noties.markwon.image.ImagesPlugin; | import io.noties.markwon.image.ImagesPlugin; | ||||||
| @ -35,15 +36,17 @@ public class BasicPluginsActivity extends ActivityWithMenuOptions { | |||||||
| 
 | 
 | ||||||
|     private TextView textView; |     private TextView textView; | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|     @NonNull |     @NonNull | ||||||
|     @Override |     @Override | ||||||
|     public MenuOptions menuOptions() { |     public MenuOptions menuOptions() { | ||||||
|         return MenuOptions.create() |         return MenuOptions.create() | ||||||
|                 .add("paragraphSpan", this::paragraphSpan) |                 .add("paragraphSpan", this::paragraphSpan) | ||||||
|                 .add("disableNode", this::disableNode) |                 .add("disableNode", this::disableNode) | ||||||
|  |                 .add("customizeTheme", this::customizeTheme) | ||||||
|                 .add("linkWithMovementMethod", this::linkWithMovementMethod) |                 .add("linkWithMovementMethod", this::linkWithMovementMethod) | ||||||
|                 .add("imagesPlugin", this::imagesPlugin); |                 .add("imagesPlugin", this::imagesPlugin) | ||||||
|  |                 .add("softBreakAddsSpace", this::softBreakAddsSpace) | ||||||
|  |                 .add("softBreakAddsNewLine", this::softBreakAddsNewLine); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
| @ -217,6 +220,28 @@ public class BasicPluginsActivity extends ActivityWithMenuOptions { | |||||||
|         markwon.setMarkdown(textView, markdown); |         markwon.setMarkdown(textView, markdown); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     private void softBreakAddsSpace() { | ||||||
|  |         // default behavior | ||||||
|  | 
 | ||||||
|  |         final String md = "" + | ||||||
|  |                 "Hello there ->(line)\n(break)<- going on and on"; | ||||||
|  | 
 | ||||||
|  |         Markwon.create(this).setMarkdown(textView, md); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private void softBreakAddsNewLine() { | ||||||
|  |         // insert a new line when markdown has a soft break | ||||||
|  | 
 | ||||||
|  |         final Markwon markwon = Markwon.builder(this) | ||||||
|  |                 .usePlugin(SoftBreakAddsNewLinePlugin.create()) | ||||||
|  |                 .build(); | ||||||
|  | 
 | ||||||
|  |         final String md = "" + | ||||||
|  |                 "Hello there ->(line)\n(break)<- going on and on"; | ||||||
|  | 
 | ||||||
|  |         markwon.setMarkdown(textView, md); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
| //    public void step_6() { | //    public void step_6() { | ||||||
| // | // | ||||||
| //        final Markwon markwon = Markwon.builder(this) | //        final Markwon markwon = Markwon.builder(this) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Dimitry Ivanov
						Dimitry Ivanov