@@ -930,6 +930,23 @@ impl<'a> Item<'a> {
930
930
clean:: ModuleItem ( ..) => true , _ => false
931
931
}
932
932
}
933
+
934
+ fn link ( & self ) -> ~str {
935
+ let mut path = Vec :: new ( ) ;
936
+ clean_srcpath ( self . item . source . filename . as_bytes ( ) , |component| {
937
+ path. push ( component. to_owned ( ) ) ;
938
+ } ) ;
939
+ let href = if self . item . source . loline == self . item . source . hiline {
940
+ format ! ( "{}" , self . item. source. loline)
941
+ } else {
942
+ format ! ( "{}-{}" , self . item. source. loline, self . item. source. hiline)
943
+ } ;
944
+ format ! ( "{root}src/{krate}/{path}.html\\ #{href}" ,
945
+ root = self . cx. root_path,
946
+ krate = self . cx. layout. krate,
947
+ path = path. connect( "/" ) ,
948
+ href = href)
949
+ }
933
950
}
934
951
935
952
impl < ' a > fmt:: Show for Item < ' a > {
@@ -977,23 +994,8 @@ impl<'a> fmt::Show for Item<'a> {
977
994
978
995
// Write `src` tag
979
996
if self . cx . include_sources {
980
- let mut path = Vec :: new ( ) ;
981
- clean_srcpath ( self . item . source . filename . as_bytes ( ) , |component| {
982
- path. push ( component. to_owned ( ) ) ;
983
- } ) ;
984
- let href = if self . item . source . loline == self . item . source . hiline {
985
- format ! ( "{}" , self . item. source. loline)
986
- } else {
987
- format ! ( "{}-{}" , self . item. source. loline, self . item. source. hiline)
988
- } ;
989
- try!( write ! ( fmt. buf,
990
- "<a class='source' \
991
- href='{root}src/{krate}/{path}.html\\ #{href}'>\
992
- [src]</a>",
993
- root = self . cx. root_path,
994
- krate = self . cx. layout. krate,
995
- path = path. connect( "/" ) ,
996
- href = href) ) ;
997
+ try!( write ! ( fmt. buf, "<a class='source' href='{}'>[src]</a>" ,
998
+ self . link( ) ) ) ;
997
999
}
998
1000
try!( write ! ( fmt. buf, "</h1>\n " ) ) ;
999
1001
@@ -1138,16 +1140,19 @@ fn item_module(w: &mut Writer, cx: &Context,
1138
1140
1139
1141
match myitem. inner {
1140
1142
clean:: StaticItem ( ref s) | clean:: ForeignStaticItem ( ref s) => {
1141
- struct Initializer < ' a > ( & ' a str ) ;
1143
+ struct Initializer < ' a > ( & ' a str , Item < ' a > ) ;
1142
1144
impl < ' a > fmt:: Show for Initializer < ' a > {
1143
1145
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1144
- let Initializer ( s) = * self ;
1146
+ let Initializer ( s, item ) = * self ;
1145
1147
if s. len ( ) == 0 { return Ok ( ( ) ) ; }
1146
1148
try!( write ! ( f. buf, "<code> = </code>" ) ) ;
1147
- let tag = if s. contains ( "\n " ) { "pre" } else { "code" } ;
1148
- try!( write ! ( f. buf, "<{tag}>{}</{tag}>" ,
1149
- s. as_slice( ) , tag=tag) ) ;
1150
- Ok ( ( ) )
1149
+ if s. contains ( "\n " ) {
1150
+ write ! ( f. buf,
1151
+ "<a href='{}'>[definition]</a>" ,
1152
+ item. link( ) )
1153
+ } else {
1154
+ write ! ( f. buf, "<code>{}</code>" , s. as_slice( ) )
1155
+ }
1151
1156
}
1152
1157
}
1153
1158
@@ -1160,7 +1165,7 @@ fn item_module(w: &mut Writer, cx: &Context,
1160
1165
VisSpace ( myitem. visibility) ,
1161
1166
* myitem. name. get_ref( ) ,
1162
1167
s. type_,
1163
- Initializer ( s. expr) ,
1168
+ Initializer ( s. expr, Item { cx : cx , item : myitem } ) ,
1164
1169
Markdown ( blank( myitem. doc_value( ) ) ) ) ) ;
1165
1170
}
1166
1171
0 commit comments