Select Git revision
-
Sigmund, Dominik authoredSigmund, Dominik authored
script.js 10.20 KiB
const urlHost = window.location.href.substr(0, window.location.href.lastIndexOf("/"));
// the following object keeps the file extension for the select option values of 'from' and 'to'
// access: value = extension["key"]
const extension = {"asciidoc_legacy": "asciidoc", "asciidoc": "asciidoc", "beamer": "tex", "biblatex": "bib", "bibtex": "bibtex", "chunkedhtml": "zip", "commonmark_x": "md", "commonmark": "md", "context": "tex", "creole": "txt", "csljson": "json", "csv": "csv", "docbook5": "xml", "docbook": "xml", "docx": "docx", "dokuwiki": "txt", "dzslides": "html", "endnotexml": "xml", "epub2": "epub", "epub3": "epub", "epub": "epub", "fb2": "fb2", "gfm": "md", "haddock": "md", "html4": "html", "html5": "html", "html": "html", "icml": "icml", "ipynb": "ipynb", "jats_archiving": "xml", "jats_articleauthoring": "xml", "jats_publishing": "xml", "jats": "xml", "jira": "txt", "json": "json", "latex": "tex", "man": "man", "markdown_mmd": "md", "markdown_phpextra": "md", "markdown_strict": "md", "markdown": "md", "markua": "md", "mediawiki": "txt", "ms": "ms", "muse": "txt", "native": "hs", "odt": "odt", "opendocument": "odf", "opml": "xml", "org": "txt", "pdf": "pdf", "plain": "txt", "pptx": "pptx", "preview": "html", "revealjs": "html", "ris": "ris", "rst": "rst", "rtf": "rtf", "s5": "html", "slideous": "html", "slidy": "html", "t2t": "t2t", "tei": "tei", "texinfo": "texi", "textile": "textile", "tikiwiki": "txt", "tsv": "tsv", "twiki": "txt", "typst": "typ", "vimwiki": "txt", "xwiki": "txt", "zimwiki": "txt"};
function pandoc(alert) {
var url = urlHost + '/pandoc.php';
if (typeof alert === 'undefined') {
alert === false;
}
// checkboxes
var standalone = document.getElementById('standalone').checked;
var tableOfContents = document.getElementById('table-of-contents').checked;
var numberSections = document.getElementById('number-sections').checked;
var citeproc = document.getElementById('citeproc').checked;
// selects
var wrap = document.getElementById('wrap').value;
var highlightStyle = document.getElementById('highlight-style').value;
var htmlMathMethod = document.getElementById('html-math-method').value;
// files
var useInputFile = document.getElementById('cb-inputfile').checked;
var inputFileExtension = extension[document.getElementById('from').value];
// docx, epub or odt must be dilivered as a file
if (!useInputFile && (inputFileExtension == 'docx' || inputFileExtension == 'epub' || inputFileExtension == 'odt')) {
if (alert === true) {
document.getElementById('options').setAttribute("open", "open");
document.getElementById('cb-inputfile').checked = true;
checkInputFile();
pushDialog("Error: For conversion from '" + inputFileExtension + "' you must select a file as input.", "error", "inputfile");
}
return;
}
var inputFile = false;
if (useInputFile) {
inputFile = document.getElementById('inputfile').files[0];
}
if (!inputFile && useInputFile) {
if (alert === true) {
pushDialog("Error: Nothing to convert.\nYou must select a file as input.", "error", "inputfile");
}
return;
}
var useOutputFile = document.getElementById('cb-outputfile').checked;
var outputFileExtension = extension[document.getElementById('to').value];
// content
var from = document.getElementById('from').value;
if (from === "none") {
if (alert === true) {
pushDialog("Error: You must select an input format in the 'From' pulldown menu.", "error", "from");
}
return;
}
var to = document.getElementById('to').value;
var input = document.getElementById('input').value;
if (isEmpty(input) && !useInputFile) {
if (alert === true) {
pushDialog("Error: Nothing to convert.\n\nYou must either write something into the 'Input field' or select a file as input in the 'Options'.", "error");
}
return;
}
var formData = new FormData();
// checkboxes
formData.set('standalone', standalone);
formData.set('tableOfContents', tableOfContents);
formData.set('numberSections', numberSections);
formData.set('citeproc', citeproc);
// selects
formData.set('wrap', wrap);
formData.set('highlightStyle', highlightStyle);