diff --git a/src/ac_scraper.rs b/src/ac_scraper.rs index 91e6b7c..8298c7a 100644 --- a/src/ac_scraper.rs +++ b/src/ac_scraper.rs @@ -573,16 +573,21 @@ pub async fn get_sample_cases( let mut outputs: Vec<(usize, String)> = Vec::new(); for pre_element in pre_elements { - let pre_content = pre_element.text().next().context(PARSE_ERROR)?; - let parent_element = pre_element - .parent() - .and_then(ElementRef::wrap) - .context(PARSE_ERROR)?; - let h3_element = parent_element - .select(&h3_selector) - .next() - .context(PARSE_ERROR)?; - let h3_content = h3_element.text().next().context(PARSE_ERROR)?; + let pre_content = pre_element.text().collect::(); + let mut h3_content: Option = None; + let mut cursor = pre_element.parent(); + while let Some(node) = cursor { + if let Some(parent) = ElementRef::wrap(node) { + if let Some(h3_element) = parent.select(&h3_selector).next() { + if let Some(text) = h3_element.text().next() { + h3_content = Some(text.to_string()); + break; + } + } + } + cursor = node.parent(); + } + let h3_content = h3_content.context(PARSE_ERROR)?; let is_input = h3_content.contains(INPUT_HEADER); let is_output = h3_content.contains(OUTPUT_HEADER); if is_input { @@ -592,7 +597,7 @@ pub async fn get_sample_cases( .collect::() .parse() .unwrap(); - inputs.push((index, pre_content.into())); + inputs.push((index, pre_content)); } else if is_output { let index: usize = h3_content .chars() @@ -600,7 +605,7 @@ pub async fn get_sample_cases( .collect::() .parse() .unwrap(); - outputs.push((index, pre_content.into())); + outputs.push((index, pre_content)); } } if let Some(target) = sample_case_id_arg {