@@ -1865,7 +1865,10 @@ impl TextDecorator for TrivialDecorator {
1865
1865
/// A decorator to generate rich text (styled) rather than
1866
1866
/// pure text output.
1867
1867
#[ derive( Clone , Debug ) ]
1868
- pub struct RichDecorator { }
1868
+ pub struct RichDecorator {
1869
+ // Don't output decorations around '*bold*' text.
1870
+ skip_decorations : bool ,
1871
+ }
1869
1872
1870
1873
/// Annotation type for "rich" text. Text is associated with a set of
1871
1874
/// these.
@@ -1896,10 +1899,20 @@ pub enum RichAnnotation {
1896
1899
}
1897
1900
1898
1901
impl RichDecorator {
1899
- /// Create a new `RichDecorator`.
1902
+ /// Create a new `RichDecorator` with the default settings .
1900
1903
#[ allow( clippy:: new_without_default) ]
1901
1904
pub fn new ( ) -> RichDecorator {
1902
- RichDecorator { }
1905
+ RichDecorator {
1906
+ skip_decorations : false ,
1907
+ }
1908
+ }
1909
+
1910
+ /// Create a new `RichDecorator` which doesn't add decorations
1911
+ /// when terminal formatting can be used.
1912
+ pub fn new_undecorated ( ) -> RichDecorator {
1913
+ RichDecorator {
1914
+ skip_decorations : true ,
1915
+ }
1903
1916
}
1904
1917
}
1905
1918
@@ -1923,11 +1936,19 @@ impl TextDecorator for RichDecorator {
1923
1936
}
1924
1937
1925
1938
fn decorate_strong_start ( & self ) -> ( String , Self :: Annotation ) {
1926
- ( "*" . to_string ( ) , RichAnnotation :: Strong )
1939
+ if self . skip_decorations {
1940
+ ( "" . to_string ( ) , RichAnnotation :: Strong )
1941
+ } else {
1942
+ ( "*" . to_string ( ) , RichAnnotation :: Strong )
1943
+ }
1927
1944
}
1928
1945
1929
1946
fn decorate_strong_end ( & self ) -> String {
1930
- "*" . to_string ( )
1947
+ if self . skip_decorations {
1948
+ "" . to_string ( )
1949
+ } else {
1950
+ "*" . to_string ( )
1951
+ }
1931
1952
}
1932
1953
1933
1954
fn decorate_strikeout_start ( & self ) -> ( String , Self :: Annotation ) {
@@ -1939,11 +1960,19 @@ impl TextDecorator for RichDecorator {
1939
1960
}
1940
1961
1941
1962
fn decorate_code_start ( & self ) -> ( String , Self :: Annotation ) {
1942
- ( "`" . to_string ( ) , RichAnnotation :: Code )
1963
+ if self . skip_decorations {
1964
+ ( "" . to_string ( ) , RichAnnotation :: Code )
1965
+ } else {
1966
+ ( "`" . to_string ( ) , RichAnnotation :: Code )
1967
+ }
1943
1968
}
1944
1969
1945
1970
fn decorate_code_end ( & self ) -> String {
1946
- "`" . to_string ( )
1971
+ if self . skip_decorations {
1972
+ "" . to_string ( )
1973
+ } else {
1974
+ "`" . to_string ( )
1975
+ }
1947
1976
}
1948
1977
1949
1978
fn decorate_preformat_first ( & self ) -> Self :: Annotation {
@@ -1979,7 +2008,7 @@ impl TextDecorator for RichDecorator {
1979
2008
}
1980
2009
1981
2010
fn make_subblock_decorator ( & self ) -> Self {
1982
- RichDecorator :: new ( )
2011
+ self . clone ( )
1983
2012
}
1984
2013
1985
2014
fn push_colour ( & mut self , colour : Colour ) -> Option < Self :: Annotation > {
0 commit comments