@@ -1169,6 +1169,14 @@ impl clean::Type {
11691169 ) -> impl fmt:: Display + ' b + Captures < ' tcx > {
11701170 display_fn ( move |f| fmt_type ( self , f, false , cx) )
11711171 }
1172+
1173+ /// Emit this type in plain text form (no HTML).
1174+ pub ( crate ) fn print_plain < ' b , ' a : ' b , ' tcx : ' a > (
1175+ & ' a self ,
1176+ cx : & ' a Context < ' tcx > ,
1177+ ) -> impl fmt:: Display + ' b + Captures < ' tcx > {
1178+ Plain ( self . print ( cx) )
1179+ }
11721180}
11731181
11741182impl clean:: Path {
@@ -1178,6 +1186,14 @@ impl clean::Path {
11781186 ) -> impl fmt:: Display + ' b + Captures < ' tcx > {
11791187 display_fn ( move |f| resolved_path ( f, self . def_id ( ) , self , false , false , cx) )
11801188 }
1189+
1190+ /// Emit this type in plain text form (no HTML).
1191+ pub ( crate ) fn print_plain < ' b , ' a : ' b , ' tcx : ' a > (
1192+ & ' a self ,
1193+ cx : & ' a Context < ' tcx > ,
1194+ ) -> impl fmt:: Display + ' b + Captures < ' tcx > {
1195+ Plain ( self . print ( cx) )
1196+ }
11811197}
11821198
11831199impl clean:: Impl {
@@ -1325,15 +1341,20 @@ impl clean::BareFunctionDecl {
13251341/// - HTML attributes are quoted with double quotes.
13261342/// - The only HTML entities used are `<`, `>`, `&`, `"`, and `'`
13271343#[ derive( Debug , Clone ) ]
1328- struct HtmlRemover < W : fmt:: Write > {
1344+ pub ( super ) struct HtmlRemover < W : fmt:: Write > {
13291345 inner : W ,
13301346 state : HtmlTextCounterState ,
13311347}
13321348
13331349impl < W : fmt:: Write > HtmlRemover < W > {
1334- fn new ( w : W ) -> Self {
1350+ pub ( super ) fn new ( w : W ) -> Self {
13351351 HtmlRemover { inner : w, state : HtmlTextCounterState :: Text }
13361352 }
1353+
1354+ #[ cfg( test) ]
1355+ pub ( super ) fn into_inner ( self ) -> W {
1356+ self . inner
1357+ }
13371358}
13381359
13391360// A state machine that tracks our progress through the HTML.
@@ -1389,7 +1410,7 @@ impl<W: fmt::Write> fmt::Write for HtmlRemover<W> {
13891410}
13901411
13911412/// This generates the plain text form of a marked-up HTML input, using HtmlRemover.
1392- struct Plain < D : fmt:: Display > ( D ) ;
1413+ pub ( super ) struct Plain < D : fmt:: Display > ( pub ( super ) D ) ;
13931414
13941415impl < D : fmt:: Display > fmt:: Display for Plain < D > {
13951416 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
@@ -1801,37 +1822,3 @@ pub(crate) fn display_fn(
18011822
18021823 WithFormatter ( Cell :: new ( Some ( f) ) )
18031824}
1804-
1805- #[ test]
1806- fn test_html_remover ( ) {
1807- use std:: fmt:: Write ;
1808-
1809- fn assert_removed_eq ( input : & str , output : & str ) {
1810- let mut remover = HtmlRemover :: new ( String :: new ( ) ) ;
1811- write ! ( & mut remover, "{}" , input) . unwrap ( ) ;
1812- assert_eq ! ( & remover. inner, output) ;
1813- }
1814-
1815- assert_removed_eq ( "a<a href='https://example.com'>b" , "ab" ) ;
1816- assert_removed_eq ( "alpha <bet>" , "alpha <bet>" ) ;
1817- assert_removed_eq ( "<a href=\" "\" >" , "" ) ;
1818- assert_removed_eq ( "<tag>></tag>text<<tag>" , ">text<" ) ;
1819-
1820- let mut remover = HtmlRemover :: new ( String :: new ( ) ) ;
1821- assert ! ( write!( & mut remover, "&ent;" ) . is_err( ) ) ;
1822-
1823- let mut remover = HtmlRemover :: new ( String :: new ( ) ) ;
1824- assert ! ( write!( & mut remover, "&entity" ) . is_err( ) ) ;
1825-
1826- let mut remover = HtmlRemover :: new ( String :: new ( ) ) ;
1827- assert ! ( write!( & mut remover, "&&" ) . is_err( ) ) ;
1828-
1829- let mut remover = HtmlRemover :: new ( String :: new ( ) ) ;
1830- assert ! ( write!( & mut remover, "<open <tag" ) . is_err( ) ) ;
1831- }
1832-
1833- #[ test]
1834- fn test_plain ( ) {
1835- let d = Plain :: new ( "<strong>alpha</strong> <bet>" ) ;
1836- assert_eq ! ( & d. to_string( ) , "alpha <bet>" ) ;
1837- }
0 commit comments