Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.quality(80)
.image_handling_mode(ImageHandlingMode::InMarkdown)
.image_output_path(None)
.include_slide_comment(true)
.build();
// alternatively use `let config = ParserConfig::default();`

Expand Down Expand Up @@ -74,14 +75,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

## Config Parameters

| Parameter | Type | Default | Description |
|------------------------|-----------------------|---------------|-----------------------------------------------------------------------------------------------------------|
| `extract_images` | `bool` | `true` | Whether images are extracted from slides or not. If false, images can not be extracted manually either. |
| `compress_images` | `bool` | `true` | Whether images are compressed before encoding or not. Effects manually extracted images too. |
| `image_quality` | `u8` | `80` | Defines the image compression quality `(0-100)`. Higher values mean better quality but larger file sizes. |
| `image_handling_mode` | `ImageHandlingMode` | `InMarkdown` | Determines how images are handled during content export |
| `image_output_path` | `Option<PathBuf>` | `None` | Output directory path for `ImageHandlingMode::Save` (mandatory for saving mode) |

| Parameter | Type | Default | Description |
|--------------------------|-----------------------|---------------|-----------------------------------------------------------------------------------------------------------|
| `extract_images` | `bool` | `true` | Whether images are extracted from slides or not. If false, images can not be extracted manually either. |
| `compress_images` | `bool` | `true` | Whether images are compressed before encoding or not. Effects manually extracted images too. |
| `image_quality` | `u8` | `80` | Defines the image compression quality `(0-100)`. Higher values mean better quality but larger file sizes. |
| `image_handling_mode` | `ImageHandlingMode` | `InMarkdown` | Determines how images are handled during content export |
| `image_output_path` | `Option<PathBuf>` | `None` | Output directory path for `ImageHandlingMode::Save` (mandatory for saving mode) |
| `include_slide_comment` | `bool` | `true` | Weather the slide number comment is included or not (`<!-- Slide [n] -->`) |
<br/>

#### Member of `ImageHandlingMode`
Expand Down
1 change: 1 addition & 0 deletions examples/basic_usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ fn main() -> Result<()> {
.compress_images(true)
.quality(75)
.image_handling_mode(ImageHandlingMode::InMarkdown)
.include_slide_comment(true)
.build();

// Open the PPTX file
Expand Down
11 changes: 11 additions & 0 deletions src/parser_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub enum ImageHandlingMode {
/// | `image_quality` | `u8` | `80` | Compression level (0-100);<br/> higher values retain more detail but increase file size |
/// | `image_handling_mode` | `ImageHandlingMode` | `InMarkdown` | Determines how images are handled during content export |
/// | `image_output_path` | `Option<PathBuf>` | `None` | Output directory path for `ImageHandlingMode::Save` (mandatory for the saving mode) |
/// | `include_slide_comment` | `bool` | `true` | Weather the slide number comment is included or not (`<!-- Slide [n] -->`) |
///
/// # Example
///
Expand All @@ -52,6 +53,7 @@ pub struct ParserConfig {
pub quality: u8,
pub image_handling_mode: ImageHandlingMode,
pub image_output_path: Option<PathBuf>,
pub include_slide_comment: bool,
}

impl Default for ParserConfig {
Expand All @@ -62,6 +64,7 @@ impl Default for ParserConfig {
quality: 80,
image_handling_mode: ImageHandlingMode::InMarkdown,
image_output_path: None,
include_slide_comment: true,
}
}
}
Expand All @@ -82,6 +85,7 @@ pub struct ParserConfigBuilder {
image_quality: Option<u8>,
image_handling_mode: Option<ImageHandlingMode>,
image_output_path: Option<PathBuf>,
include_slide_comment: Option<bool>,
}

impl ParserConfigBuilder {
Expand Down Expand Up @@ -119,6 +123,12 @@ impl ParserConfigBuilder {
self
}

/// Sets weather comments with current slide number are included or not
pub fn include_slide_comment(mut self, value: bool) -> Self {
self.include_slide_comment = Some(value);
self
}

/// Builds the final [`ParserConfig`] instance, applying default values for any fields that were not set.
pub fn build(self) -> ParserConfig {
ParserConfig {
Expand All @@ -127,6 +137,7 @@ impl ParserConfigBuilder {
quality: self.image_quality.unwrap_or(80),
image_handling_mode: self.image_handling_mode.unwrap_or(ImageHandlingMode::InMarkdown),
image_output_path: self.image_output_path,
include_slide_comment: self.include_slide_comment.unwrap_or(true),
}
}
}
2 changes: 1 addition & 1 deletion src/slide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl Slide {
/// - `None`: If a conversion error occurs during image encoding.
pub fn convert_to_md(&self) -> Option<String> {
let mut slide_txt = String::new();
slide_txt.push_str(format!("<!-- Slide {} -->\n\n", self.slide_number).as_str());
if self.config.include_slide_comment { slide_txt.push_str(format!("<!-- Slide {} -->\n\n", self.slide_number).as_str()); }
let mut image_count = 0;

for element in &self.elements {
Expand Down