2019-06-04 18:08:26 +00:00
|
|
|
use super::*;
|
2019-06-05 19:28:35 +00:00
|
|
|
use lazy_static::lazy_static;
|
2019-06-04 18:08:26 +00:00
|
|
|
use spawning::SpawningFileAdapter;
|
|
|
|
use std::process::Command;
|
|
|
|
|
|
|
|
// from https://github.com/jgm/pandoc/blob/master/src/Text/Pandoc/App/FormatHeuristics.hs
|
2019-06-11 11:34:04 +00:00
|
|
|
// excluding formats that could cause problems (.db ?= sqlite) or that are already text formats (e.g. xml-based)
|
2019-06-04 18:08:26 +00:00
|
|
|
//"db" -> Just "docbook"
|
|
|
|
//"adoc" -> Just "asciidoc"
|
|
|
|
//"asciidoc" -> Just "asciidoc"
|
|
|
|
//"context" -> Just "context"
|
|
|
|
//"ctx" -> Just "context"
|
|
|
|
//"dokuwiki" -> Just "dokuwiki"
|
|
|
|
//"htm" -> Just "html"
|
|
|
|
//"html" -> Just "html"
|
|
|
|
//"json" -> Just "json"
|
|
|
|
//"latex" -> Just "latex"
|
|
|
|
//"lhs" -> Just "markdown+lhs"
|
|
|
|
//"ltx" -> Just "latex"
|
|
|
|
//"markdown" -> Just "markdown"
|
|
|
|
//"md" -> Just "markdown"
|
|
|
|
//"ms" -> Just "ms"
|
|
|
|
//"muse" -> Just "muse"
|
|
|
|
//"native" -> Just "native"
|
|
|
|
//"opml" -> Just "opml"
|
|
|
|
//"org" -> Just "org"
|
|
|
|
//"roff" -> Just "ms"
|
|
|
|
//"rst" -> Just "rst"
|
|
|
|
//"s5" -> Just "s5"
|
|
|
|
//"t2t" -> Just "t2t"
|
|
|
|
//"tei" -> Just "tei"
|
|
|
|
//"tei.xml" -> Just "tei"
|
|
|
|
//"tex" -> Just "latex"
|
|
|
|
//"texi" -> Just "texinfo"
|
|
|
|
//"texinfo" -> Just "texinfo"
|
|
|
|
//"textile" -> Just "textile"
|
|
|
|
//"text" -> Just "markdown"
|
|
|
|
//"txt" -> Just "markdown"
|
|
|
|
//"xhtml" -> Just "html"
|
|
|
|
//"wiki" -> Just "mediawiki"
|
2019-06-05 14:43:40 +00:00
|
|
|
|
2019-06-05 19:28:35 +00:00
|
|
|
static EXTENSIONS: &[&str] = &["epub", "odt", "docx", "pptx", "fb2", "ipynb"];
|
2019-06-04 18:08:26 +00:00
|
|
|
|
2019-06-05 19:28:35 +00:00
|
|
|
lazy_static! {
|
|
|
|
static ref METADATA: AdapterMeta = AdapterMeta {
|
|
|
|
name: "pandoc".to_owned(),
|
|
|
|
version: 1,
|
2019-06-13 14:26:03 +00:00
|
|
|
description:
|
|
|
|
"Uses pandoc to convert binary/unreadable text documents to plain markdown-like text"
|
|
|
|
.to_owned(),
|
2019-06-11 11:34:04 +00:00
|
|
|
fast_matchers: EXTENSIONS
|
2019-06-05 19:28:35 +00:00
|
|
|
.iter()
|
2019-06-11 11:34:04 +00:00
|
|
|
.map(|s| FastMatcher::FileExtension(s.to_string()))
|
2019-06-05 19:28:35 +00:00
|
|
|
.collect(),
|
2019-06-11 11:34:04 +00:00
|
|
|
slow_matchers: None
|
2019-06-05 19:28:35 +00:00
|
|
|
};
|
2019-06-04 18:08:26 +00:00
|
|
|
}
|
2019-06-06 21:43:30 +00:00
|
|
|
#[derive(Default)]
|
2019-06-05 19:28:35 +00:00
|
|
|
pub struct PandocAdapter;
|
2019-06-04 18:08:26 +00:00
|
|
|
|
|
|
|
impl PandocAdapter {
|
|
|
|
pub fn new() -> PandocAdapter {
|
2019-06-05 19:28:35 +00:00
|
|
|
PandocAdapter
|
2019-06-04 18:08:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
impl GetMetadata for PandocAdapter {
|
2019-06-06 21:43:30 +00:00
|
|
|
fn metadata(&self) -> &AdapterMeta {
|
2019-06-05 19:28:35 +00:00
|
|
|
&METADATA
|
2019-06-04 18:08:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
impl SpawningFileAdapter for PandocAdapter {
|
2019-06-05 19:28:35 +00:00
|
|
|
fn get_exe(&self) -> &str {
|
|
|
|
"pandoc"
|
|
|
|
}
|
2019-06-06 09:00:13 +00:00
|
|
|
fn command(&self, filepath_hint: &Path, mut cmd: Command) -> Command {
|
2019-06-04 18:08:26 +00:00
|
|
|
cmd
|
2019-06-06 09:00:13 +00:00
|
|
|
.arg("--from").arg(filepath_hint.extension().unwrap())
|
2019-06-04 18:08:26 +00:00
|
|
|
// simpler markown (with more information loss but plainer text)
|
2019-06-05 14:43:40 +00:00
|
|
|
.arg("--to=commonmark-header_attributes-link_attributes-fenced_divs-markdown_in_html_blocks-raw_html-native_divs-native_spans-bracketed_spans")
|
2019-06-04 18:08:26 +00:00
|
|
|
.arg("--wrap=none")
|
2019-06-06 09:00:13 +00:00
|
|
|
.arg("--atx-headers");
|
2019-06-04 18:08:26 +00:00
|
|
|
cmd
|
|
|
|
}
|
|
|
|
}
|