@@ -1169,6 +1169,14 @@ impl clean::Type {
1169
1169
) -> impl fmt:: Display + ' b + Captures < ' tcx > {
1170
1170
display_fn ( move |f| fmt_type ( self , f, false , cx) )
1171
1171
}
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
+ }
1172
1180
}
1173
1181
1174
1182
impl clean:: Path {
@@ -1178,6 +1186,14 @@ impl clean::Path {
1178
1186
) -> impl fmt:: Display + ' b + Captures < ' tcx > {
1179
1187
display_fn ( move |f| resolved_path ( f, self . def_id ( ) , self , false , false , cx) )
1180
1188
}
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
+ }
1181
1197
}
1182
1198
1183
1199
impl clean:: Impl {
@@ -1325,15 +1341,20 @@ impl clean::BareFunctionDecl {
1325
1341
/// - HTML attributes are quoted with double quotes.
1326
1342
/// - The only HTML entities used are `<`, `>`, `&`, `"`, and `'`
1327
1343
#[ derive( Debug , Clone ) ]
1328
- struct HtmlRemover < W : fmt:: Write > {
1344
+ pub ( super ) struct HtmlRemover < W : fmt:: Write > {
1329
1345
inner : W ,
1330
1346
state : HtmlTextCounterState ,
1331
1347
}
1332
1348
1333
1349
impl < W : fmt:: Write > HtmlRemover < W > {
1334
- fn new ( w : W ) -> Self {
1350
+ pub ( super ) fn new ( w : W ) -> Self {
1335
1351
HtmlRemover { inner : w, state : HtmlTextCounterState :: Text }
1336
1352
}
1353
+
1354
+ #[ cfg( test) ]
1355
+ pub ( super ) fn into_inner ( self ) -> W {
1356
+ self . inner
1357
+ }
1337
1358
}
1338
1359
1339
1360
// A state machine that tracks our progress through the HTML.
@@ -1389,7 +1410,7 @@ impl<W: fmt::Write> fmt::Write for HtmlRemover<W> {
1389
1410
}
1390
1411
1391
1412
/// 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 ) ;
1393
1414
1394
1415
impl < D : fmt:: Display > fmt:: Display for Plain < D > {
1395
1416
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
@@ -1801,37 +1822,3 @@ pub(crate) fn display_fn(
1801
1822
1802
1823
WithFormatter ( Cell :: new ( Some ( f) ) )
1803
1824
}
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