trying to add a way for rust to find number of slides in reveal.js
This commit is contained in:
parent
58652eafa1
commit
b234795a36
3 changed files with 52 additions and 3 deletions
41
src/rust/reveal_js.rs
Normal file
41
src/rust/reveal_js.rs
Normal file
|
@ -0,0 +1,41 @@
|
|||
// use dirs;
|
||||
use std::fs::read_to_string;
|
||||
|
||||
// struct Slide {
|
||||
// num_fragments: usize,
|
||||
// }
|
||||
|
||||
// struct Presentation {
|
||||
// num_slides: usize,
|
||||
// num_fragments: usize,
|
||||
// }
|
||||
|
||||
pub fn count_slides_and_fragments(html_file_path: &str) -> i32 {
|
||||
// Read the HTML file
|
||||
let html_content = read_to_string(html_file_path).expect("Failed to read HTML file");
|
||||
|
||||
// Split HTML content by slide delimiters
|
||||
let slide_delimiter = "<section";
|
||||
let slide_content: Vec<&str> = html_content.split(slide_delimiter).collect();
|
||||
|
||||
// Count slides and fragments
|
||||
let num_slides = slide_content.len() - 1;
|
||||
let mut num_fragments = 0;
|
||||
|
||||
for slide_html in slide_content.iter().skip(1) {
|
||||
let fragments = slide_html.matches("fragment").count();
|
||||
num_fragments += fragments;
|
||||
}
|
||||
|
||||
let total = num_slides + num_fragments;
|
||||
|
||||
total as i32
|
||||
}
|
||||
|
||||
// fn main() {
|
||||
// let html_file_path = "path/to/presentation.html";
|
||||
// let presentation = count_slides_and_fragments(html_file_path);
|
||||
|
||||
// println!("Total number of slides: {}", presentation.num_slides);
|
||||
// println!("Total number of fragments: {}", presentation.num_fragments);
|
||||
// }
|
Loading…
Add table
Add a link
Reference in a new issue