feat: implement Pandoc conversion plugin
Release / check-release (push) Successful in 22s
Release / build (push) Skipped
Release / package (deb) (push) Skipped
Release / package (rpm) (push) Skipped
Release / publish (push) Skipped
CI / test (push) Successful in 1m38s
Plugin Releases / build-package-publish (push) Successful in 2m36s
Release / check-release (push) Successful in 22s
Release / build (push) Skipped
Release / package (deb) (push) Skipped
Release / package (rpm) (push) Skipped
Release / publish (push) Skipped
CI / test (push) Successful in 1m38s
Plugin Releases / build-package-publish (push) Successful in 2m36s
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
[package]
|
||||
name = "convertis-pandoc"
|
||||
build = "../../plugin-build.rs"
|
||||
version = "0.1.0"
|
||||
description = "Pandoc plugin for Convertis"
|
||||
edition.workspace = true
|
||||
authors.workspace = true
|
||||
license.workspace = true
|
||||
repository.workspace = true
|
||||
|
||||
[package.metadata.convertis]
|
||||
id = "pandoc"
|
||||
api-version = 2
|
||||
debian-dependencies = ["pandoc"]
|
||||
rpm-dependencies = ["/usr/bin/pandoc"]
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
convertis-plugin-api.workspace = true
|
||||
@@ -0,0 +1,68 @@
|
||||
// Copyright (C) 2026 Elias Wendland <eliaswendland@pm.me>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, version 3 exclusively.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use convertis_plugin_api::{Conversion, ConversionRequest, Plugin, PluginMetadata};
|
||||
use std::process::Command;
|
||||
|
||||
const INPUTS: &[&str] = &["md", "html", "pdf", "docx", "ltx", "epub"];
|
||||
const OUTPUTS: &[&str] = &["pdf", "html", "ltx", "md", "docx", "epub"];
|
||||
struct Pandoc;
|
||||
|
||||
impl Plugin for Pandoc {
|
||||
fn metadata(&self) -> PluginMetadata {
|
||||
PluginMetadata {
|
||||
id: "pandoc".into(),
|
||||
package: "convertis-pandoc".into(),
|
||||
description: "Pandoc document conversion".into(),
|
||||
conversions: INPUTS
|
||||
.iter()
|
||||
.flat_map(|from| {
|
||||
OUTPUTS
|
||||
.iter()
|
||||
.filter(move |to| to != &from)
|
||||
.map(move |to| Conversion::file(from, to, (240, 210, 180)))
|
||||
})
|
||||
.collect(),
|
||||
options: vec![],
|
||||
}
|
||||
}
|
||||
fn availability(&self) -> Result<(), String> {
|
||||
Command::new("pandoc")
|
||||
.arg("--version")
|
||||
.output()
|
||||
.map_err(|_| "'pandoc' is required".to_owned())
|
||||
.and_then(|output| {
|
||||
output
|
||||
.status
|
||||
.success()
|
||||
.then_some(())
|
||||
.ok_or_else(|| "'pandoc' is unavailable".to_owned())
|
||||
})
|
||||
}
|
||||
fn convert(&self, request: &ConversionRequest) -> Result<(), String> {
|
||||
let output = Command::new("pandoc")
|
||||
.arg(&request.input)
|
||||
.arg("-o")
|
||||
.arg(&request.output)
|
||||
.output()
|
||||
.map_err(|error| error.to_string())?;
|
||||
|
||||
if output.status.success() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(String::from_utf8_lossy(&output.stderr).into_owned())
|
||||
}
|
||||
}
|
||||
}
|
||||
convertis_plugin_api::export_plugin!(Pandoc, "pandoc");
|
||||
Reference in New Issue
Block a user