File tree Expand file tree Collapse file tree 2 files changed +11
-5
lines changed
packages/mdbook-trpl/src/listing Expand file tree Collapse file tree 2 files changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -221,7 +221,13 @@ struct Listing {
221221
222222impl Listing {
223223 fn opening_html ( & self ) -> String {
224- let figure = String :: from ( "<figure class=\" listing\" >\n " ) ;
224+ let id_attribute = self
225+ . number
226+ . as_ref ( )
227+ . map ( |number| format ! ( " id=\" listing-{number}\" " ) )
228+ . unwrap_or_default ( ) ;
229+
230+ let figure = format ! ( "<figure class=\" listing\" {id_attribute}>\n " ) ;
225231
226232 match self . file_name . as_ref ( ) {
227233 Some ( file_name) => format ! (
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ fn main() {}
1818
1919 assert_eq ! (
2020 & result. unwrap( ) ,
21- r#"<figure class="listing">
21+ r#"<figure class="listing" id="listing-1-2" >
2222<span class="file-name">Filename: src/main.rs</span>
2323
2424````rust
@@ -80,7 +80,7 @@ fn get_a_box_of<T>(t: T) -> Box<T> {
8080
8181 assert_eq ! (
8282 & result. unwrap( ) ,
83- r#"<figure class="listing">
83+ r#"<figure class="listing" id="listing-34-5" >
8484
8585````rust
8686fn get_a_box_of<T>(t: T) -> Box<T> {
@@ -117,7 +117,7 @@ Save the file and go back to your terminal window"#,
117117 result. unwrap( ) ,
118118 r#"Now open the *main.rs* file you just created and enter the code in Listing 1-1.
119119
120- <figure class="listing">
120+ <figure class="listing" id="listing-1-1" >
121121<span class="file-name">Filename: main.rs</span>
122122
123123````rust
@@ -155,7 +155,7 @@ This is the closing."#,
155155 result. unwrap( ) ,
156156 r#"This is the opening.
157157
158- <figure class="listing">
158+ <figure class="listing" id="listing-1-1" >
159159
160160````rust
161161fn main() {}
You can’t perform that action at this time.
0 commit comments