Skip to content

Commit 111d0c1

Browse files
mdbook-slide-evaluator: evaluate if the embedded code examples have a visible ace_scrollbar-[hv]
1 parent 1046579 commit 111d0c1

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

mdbook-slide-evaluator/src/evaluator.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,36 @@ impl<'a> Evaluator<'_> {
232232
Ok(violations)
233233
}
234234

235+
/// Determines if the current page has a code example (using ACE) that has
236+
/// a scrollbar by evaluating if the ace_scrollbar-[hv] element is displayed
237+
async fn eval_code_example_scrollbar(
238+
&self,
239+
) -> anyhow::Result<Vec<PolicyViolation>> {
240+
let v_scrollbar_elements_path = fantoccini::Locator::XPath(
241+
r#"//*[@id="content"]//div[contains(@class, "ace_scrollbar-v")]"#,
242+
);
243+
let h_scrollbar_elements_path = fantoccini::Locator::XPath(
244+
r#"//*[@id="content"]//div[contains(@class, "ace_scrollbar-h")]"#,
245+
);
246+
let v_scrollbar_elements =
247+
self.webclient.find_all(v_scrollbar_elements_path).await?;
248+
let h_scrollbar_elements =
249+
self.webclient.find_all(h_scrollbar_elements_path).await?;
250+
251+
let mut violations = vec![];
252+
for element in v_scrollbar_elements {
253+
if element.is_displayed().await? {
254+
violations.push(PolicyViolation::CodeExampleVScrollbar);
255+
}
256+
}
257+
for element in h_scrollbar_elements {
258+
if element.is_displayed().await? {
259+
violations.push(PolicyViolation::CodeExampleHScrollbar);
260+
}
261+
}
262+
Ok(violations)
263+
}
264+
235265
/// evaluate a single slide
236266
pub async fn eval_slide(
237267
&self,
@@ -245,6 +275,8 @@ impl<'a> Evaluator<'_> {
245275
let mut policy_violations = vec![];
246276
// evaluate main content element size
247277
policy_violations.append(&mut self.eval_main_element(slide).await?);
278+
// evaluate code examples size
279+
policy_violations.append(&mut self.eval_code_example_scrollbar().await?);
248280

249281
let result = EvaluationResult { slide: slide.clone(), policy_violations };
250282
debug!("information about element: {:?}", result);
@@ -277,6 +309,10 @@ enum PolicyViolation {
277309
MaxWidth,
278310
/// violation of the maximum width
279311
MaxHeight,
312+
/// code examples should not contain a vertical scrollbar
313+
CodeExampleVScrollbar,
314+
/// code examples should not contain a horizontal scrollbar
315+
CodeExampleHScrollbar,
280316
}
281317

282318
/// the SlidePolicy struct contains all parameters for evaluating a slide

0 commit comments

Comments
 (0)