Skip to content

Commit 9a04d81

Browse files
author
gaoyuan
committed
add id to Listing with number attribute for cross reference
1 parent 81a976a commit 9a04d81

File tree

1 file changed

+7
-1
lines changed
  • packages/mdbook-trpl/src/listing

1 file changed

+7
-1
lines changed

packages/mdbook-trpl/src/listing/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,13 @@ struct Listing {
221221

222222
impl Listing {
223223
fn opening_html(&self) -> String {
224-
let figure = String::from("<figure class=\"listing\">\n");
224+
let id_attribute = if let Some(number) = self.number.as_ref() {
225+
format!(" id=\"listing-{number}\"")
226+
} else {
227+
String::new()
228+
};
229+
230+
let figure = format!("<figure class=\"listing\"{id_attribute}>\n");
225231

226232
match self.file_name.as_ref() {
227233
Some(file_name) => format!(

0 commit comments

Comments
 (0)