pub mod adapters;
pub mod converter;
pub mod core;
pub mod error;
pub mod localization;
pub mod render;
pub use converter::DocxToMarkdown;
pub use error::{Error, Result};
pub use localization::parse_heading_style;
use std::path::PathBuf;
#[derive(Debug, Clone)]
pub struct ConvertOptions {
pub image_handling: ImageHandling,
pub preserve_whitespace: bool,
pub html_underline: bool,
pub html_strikethrough: bool,
pub strict_reference_validation: bool,
}
impl Default for ConvertOptions {
fn default() -> Self {
Self {
image_handling: ImageHandling::Inline,
preserve_whitespace: false,
html_underline: true,
html_strikethrough: false,
strict_reference_validation: false,
}
}
}
#[derive(Debug, Clone)]
pub enum ImageHandling {
SaveToDir(PathBuf),
Inline,
Skip,
}
#[cfg(feature = "python")]
mod python_bindings {
use super::*;
use pyo3::prelude::*;
use pyo3::types::PyBytes;
#[pyfunction]
fn convert_docx(input: &Bound<'_, PyAny>) -> PyResult<String> {
let options = ConvertOptions::default();
let converter = DocxToMarkdown::new(options);
if let Ok(path) = input.extract::<String>() {
converter
.convert(&path)
.map_err(|e| PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(e.to_string()))
} else if let Ok(bytes) = input.downcast::<PyBytes>() {
converter
.convert_from_bytes(bytes.as_bytes())
.map_err(|e| PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(e.to_string()))
} else {
Err(PyErr::new::<pyo3::exceptions::PyTypeError, _>(
"Expected string path or bytes",
))
}
}
#[pymodule]
pub fn dm2xcod(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(convert_docx, m)?)?;
Ok(())
}
}