@@ -82,6 +82,7 @@ impl<'a> ParserError<Partial<&'a str>> for Error<'a> {
82
82
#[ derive( Debug ) ]
83
83
pub struct ParseState {
84
84
pub terminal_width : Option < usize > ,
85
+ pub markdown_disabled : Option < bool > ,
85
86
pub column : usize ,
86
87
pub in_codeblock : bool ,
87
88
pub bold : bool ,
@@ -93,9 +94,10 @@ pub struct ParseState {
93
94
}
94
95
95
96
impl ParseState {
96
- pub fn new ( terminal_width : Option < usize > ) -> Self {
97
+ pub fn new ( terminal_width : Option < usize > , markdown_disabled : Option < bool > ) -> Self {
97
98
Self {
98
99
terminal_width,
100
+ markdown_disabled,
99
101
column : 0 ,
100
102
in_codeblock : false ,
101
103
bold : false ,
@@ -135,8 +137,12 @@ pub fn interpret_markdown<'a, 'b>(
135
137
} ;
136
138
}
137
139
138
- match state. in_codeblock {
139
- false => {
140
+ match ( state. in_codeblock , state. markdown_disabled . unwrap_or ( false ) ) {
141
+ ( _, true ) => {
142
+ // If markdown is disabled, do not include markdown-related parsers
143
+ stateful_alt ! ( text, line_ending, fallback) ;
144
+ } ,
145
+ ( false , false ) => {
140
146
stateful_alt ! (
141
147
// This pattern acts as a short circuit for alphanumeric plaintext
142
148
// More importantly, it's needed to support manual wordwrapping
@@ -167,7 +173,7 @@ pub fn interpret_markdown<'a, 'b>(
167
173
fallback
168
174
) ;
169
175
} ,
170
- true => {
176
+ ( true , false ) => {
171
177
stateful_alt ! (
172
178
codeblock_less_than,
173
179
codeblock_greater_than,
@@ -646,7 +652,7 @@ mod tests {
646
652
use super :: * ;
647
653
648
654
macro_rules! validate {
649
- ( $test: ident, $input: literal, [ $( $commands: expr) ,+ $( , ) ?] ) => {
655
+ ( $test: ident, $input: literal, [ $( $commands: expr) ,+ $( , ) ?] , $markdown_enabled : expr ) => {
650
656
#[ test]
651
657
fn $test( ) -> eyre:: Result <( ) > {
652
658
use crossterm:: ExecutableCommand ;
@@ -655,7 +661,7 @@ mod tests {
655
661
input. push( ' ' ) ;
656
662
input. push( ' ' ) ;
657
663
658
- let mut state = ParseState :: new( Some ( 80 ) ) ;
664
+ let mut state = ParseState :: new( Some ( 80 ) , Some ( $markdown_enabled ) ) ;
659
665
let mut presult = vec![ ] ;
660
666
let mut offset = 0 ;
661
667
@@ -686,6 +692,10 @@ mod tests {
686
692
Ok ( ( ) )
687
693
}
688
694
} ;
695
+
696
+ ( $test: ident, $input: literal, [ $( $commands: expr) ,+ $( , ) ?] ) => {
697
+ validate!( $test, $input, [ $( $commands) ,+] , false ) ;
698
+ } ;
689
699
}
690
700
691
701
validate ! ( text_1, "hello world!" , [ style:: Print ( "hello world!" ) ] ) ;
@@ -759,4 +769,53 @@ mod tests {
759
769
validate ! ( square_bracket_url_like_2, "[text](without url part" , [ style:: Print (
760
770
"[text](without url part"
761
771
) ] ) ;
772
+
773
+ validate ! ( markdown_disabled_bold, "**hello**" , [ style:: Print ( "**hello**" ) ] , true ) ;
774
+ validate ! ( markdown_disabled_italic, "*hello*" , [ style:: Print ( "*hello*" ) ] , true ) ;
775
+ validate ! ( markdown_disabled_code, "`print`" , [ style:: Print ( "`print`" ) ] , true ) ;
776
+ validate ! (
777
+ markdown_disabled_heading,
778
+ "# Hello World" ,
779
+ [ style:: Print ( "# Hello World" ) ] ,
780
+ true
781
+ ) ;
782
+ validate ! ( markdown_disabled_bullet, "- bullet" , [ style:: Print ( "- bullet" ) ] , true ) ;
783
+ validate ! ( markdown_disabled_number, "1. number" , [ style:: Print ( "1. number" ) ] , true ) ;
784
+ validate ! ( markdown_disabled_blockquote, "> hello" , [ style:: Print ( "> hello" ) ] , true ) ;
785
+ validate ! (
786
+ markdown_disabled_url,
787
+ "[amazon](amazon.com)" ,
788
+ [ style:: Print ( "[amazon](amazon.com)" ) ] ,
789
+ true
790
+ ) ;
791
+ validate ! (
792
+ markdown_disabled_codeblock,
793
+ "```java hello world!```" ,
794
+ [ style:: Print ( "```java hello world!```" ) ] ,
795
+ true
796
+ ) ;
797
+ validate ! (
798
+ markdown_disabled_text,
799
+ "hello world!" ,
800
+ [ style:: Print ( "hello world!" ) ] ,
801
+ true
802
+ ) ;
803
+ validate ! (
804
+ markdown_disabled_line_ending,
805
+ "line one\n line two" ,
806
+ [
807
+ style:: Print ( "line one" ) ,
808
+ style:: ResetColor ,
809
+ style:: SetAttribute ( style:: Attribute :: Reset ) ,
810
+ style:: Print ( "\n " ) ,
811
+ style:: Print ( "line two" )
812
+ ] ,
813
+ true
814
+ ) ;
815
+ validate ! (
816
+ markdown_disabled_fallback,
817
+ "+ % @ . ?" ,
818
+ [ style:: Print ( "+ % @ . ?" ) ] ,
819
+ true
820
+ ) ;
762
821
}
0 commit comments