pandoc/trypandoc/index.html
2022-08-18 08:09:50 -07:00

307 lines
12 KiB
HTML

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Try pandoc!</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<style>
body { margin: auto; font-family: sans-serif; font-size: 10pt; color: #555; }
#command { min-width: 26em; background-color: #555; color: #eee; border-radius: 9pt; margin: 6pt; padding: 6pt; }
h1 { margin-bottom: 1em; font-size: 166%; margin: 0; padding: 6pt; }
h1 a { text-decoration: none; color: inherit; }
label { font-weight: 600; }
textarea { height: auto; font-family: monospace; font-size: 10pt; margin-top: 15px; min-height: 65vh; width: 44vw; }
div.alert { margin: 1em; }
pre#results { width: 100%; margin-top: 15px; min-height: 65vh; width: 44vw; }
footer { color: #555; text-align: center; margin: 1em; }
p.version { color: #555; }
.container { margin: 12px; }
.row { display: flex; flex-wrap: nowrap; justify-content: space-between; }
#frompane { flex: 1; padding: 1em; }
#topane { flex: 1; padding: 1em; }
#command { font-family: monospace; padding: 1em; }
button#convert { vertical-align: bottom; }
pre#command { margin-top: 1em; background-color: transparent; border: none; }
</style>
</head>
<body>
<div class="container">
<div class="row">
<div id="title">
<h1>Try <a href="https://pandoc.org">pandoc</a>!</h1>
</div>
<div id="versioninfo">
<p class="version">v<span id="version"></span></p>
</footer>
</div>
<div id="command">
<pre id="command"></pre>
</div>
</div>
<div class="row">
<div id="frompane">
<button id="convert">Convert</button>
&nbsp;
<label for="from">
from
</label>
<select id="from">
<option value="bibtex">BibTeX</option>
<option value="biblatex">BibLaTeX</option>
<option value="commonmark">CommonMark</option>
<option value="commonmark_x">CommonMark (extended)</option>
<option value="creole">Creole</option>
<option value="csljson">CSL JSON</option>
<option value="csv">CSV</option>
<option value="docbook">DocBook</option>
<option value="dokuwiki">DokuWiki</option>
<option value="docx">Docx (Word)</option>
<option value="epub">EPUB</option>
<option value="fb2">FB2</option>
<option value="haddock">Haddock markup</option>
<option value="html">HTML</option>
<option value="jats">JATS</option>
<option value="jira">Jira</option>
<option value="ipynb">Jupyter Notebook (ipynb)</option>
<option value="latex">LaTeX</option>
<option value="man">Man</option>
<option value="markdown" selected>Markdown (pandoc)</option>
<option value="gfm">Markdown (GitHub-flavored)</option>
<option value="markdown_phpextra">Markdown (PHP Markdown Extra)</option>
<option value="markdown_strict">Markdown (strict)</option>
<option value="mediawiki">MediaWiki</option>
<option value="markdown_mmd">MultiMarkdown</option>
<option value="muse">Muse</option>
<option value="native">Native (Pandoc AST)</option>
<option value="odt">ODT</option>
<option value="opml">OPML</option>
<option value="org">Org Mode</option>
<option value="ris">RIS</option>
<option value="rst">reStructuredText</option>
<option value="t2t">Txt2Tags</option>
<option value="textile">Textile</option>
<option value="tikiwiki">TikiWiki</option>
<option value="twiki">TWiki</option>
<option value="vimwiki">Vimwiki</option>
</select><br/>
<label for="loadfile">Load from file</label>
<input id="loadfile" type="file" />
<br/>
<textarea id="text" rows="15"></textarea>
</div>
<div id="topane">
<label for="to">
to
</label>
<select id="to">
<option value="asciidoc">AsciiDoc (original)</option>
<option value="asciidoctor">AsciiDoc (asciidoctor-flavored)</option>
<option value="beamer">LaTeX Beamer</option>
<option value="bibtex">BibTeX</option>
<option value="biblatex">BibLaTeX</option>
<option value="commonmark">CommonMark</option>
<option value="context">ConTeXt</option>
<option value="csljson">CSL JSON</option>
<option value="docbook4">DocBook v4</option>
<option value="docbook5">DocBook v5</option>
<option value="docx">Docx (Word)</option>
<option value="dokuwiki">DokuWiki</option>
<option value="dzslides">DZSlides</option>
<option value="epub2">EPUB v2</option>
<option value="epub3">EPUB v3</option>
<option value="haddock">Haddock markup</option>
<option value="html4">HTML 4</option>
<option value="html5" selected>HTML 5</option>
<option value="icml">ICML</option>
<option value="jats">JATS</option>
<option value="jira">Jira</option>
<option value="json">JSON</option>
<option value="ipynb">Jupyter Notebook (ipynb)</option>
<option value="latex">LaTeX</option>
<option value="man">Man</option>
<option value="ms">Ms</option>
<option value="markdown">Markdown (pandoc)</option>
<option value="gfm">Markdown (GitHub-flavored)</option>
<option value="markdown_phpextra">Markdown (PHP Markdown Extra)</option>
<option value="markdown_strict">Markdown (strict)</option>
<option value="mediawiki">MediaWiki</option>
<option value="markdown_mmd">MultiMarkdown</option>
<option value="muse">Muse</option>
<option value="native">Native (Pandoc AST)</option>
<option value="odt">ODT</option>
<option value="opendocument">OpenDocument</option>
<option value="opml">OPML</option>
<option value="org">Org Mode</option>
<option value="plain">Plain text</option>
<option value="pptx">Powerpoint</option>
<option value="revealjs">reveal.js</option>
<option value="rst">reStructuredText</option>
<option value="rtf">RTF</option>
<option value="S5">S5</option>
<option value="slideous">Slideous</option>
<option value="slidy">Slidy</option>
<option value="tei">TEI</option>
<option value="texinfo">Texinfo</option>
<option value="textile">Textile</option>
<option value="zimwiki">ZimWiki</option>
</select>
<input type="checkbox" id="standalone" name="standalone">
<label for="standalone">Standalone
<a href="https://pandoc.org/MANUAL.html#option--standalone" target="_blank">(?)</a>
</label>
<input type="checkbox" id="citeproc" name="citeproc">
<label for="citeproc">Citeproc
<a href="https://pandoc.org/MANUAL.html#option--citeproc" target="_blank">(?)</a>
</label>
<br/>
<a id="permalink" title="link to this conversion" href="">permalink</a></br/>
<pre id="results"></pre>
</div>
</div>
</div>
<script>
"use strict";
var params = {
text: '"hello *world*"',
to: 'html5',
from: 'markdown',
standalone: false,
citeproc: false };
function permalink() {
let input = document.getElementById("text").value;
let from = document.getElementById("from").value;
let to = document.getElementById("to").value;
let standalone = document.getElementById("standalone").checked ? true : false;
let citeproc = document.getElementById("citeproc").checked ? true : false;
let href = window.location.href;
const URLparams = new URLSearchParams(Object.entries({text: input, from: from, to: to, standalone: standalone, citeproc: citeproc}));
return href.replace(/([?].*)?$/,"?" + URLparams);
}
const binaryFormats = {
docx: { extension: "docx",
mime: "application/vnd.openxmlformats-officedocument.wordprocessingml.document" },
odt: { extension: "odt",
mime: "application/vnd.oasis.opendocument.text" },
pptx: { extension: "pptx",
mime: "application/vnd.openxmlformats-officedocument.presentationml.presentation" },
epub: { extension: "epub",
mime: "application/epub+zip" },
epub2: { extension: "epub",
mime: "application/epub+zip" },
epub3: { extension: "epub",
mime: "application/epub+zip" }
};
function paramsFromURL() {
if (window.location.search.length > 0) {
const uparams = new URLSearchParams(window.location.search);
params.text = uparams.get("text") || "";
params.from = uparams.get("from") || "markdown";
params.to = uparams.get("to") || "html5";
params.standalone = uparams.get("standalone") === "true";
params.citeproc = uparams.get("citeproc") === "true";
}
}
function convert() {
let text = document.getElementById("text").value;
let from = document.getElementById("from").value;
let to = document.getElementById("to").value;
let standalone = document.getElementById("standalone").checked;
let citeproc = document.getElementById("citeproc").checked;
params = { text: text, from: from, to: to, standalone: standalone,
citeproc: citeproc };
if (text && text != "") {
fetch("/cgi-bin/pandoc-server.cgi/version")
.then(response => response.text())
.then(restext =>
document.getElementById("version").textContent = restext
);
// console.log(JSON.stringify(params));
let commandString = "pandoc"
+ " --from " + from + " --to " + to
+ (standalone ? " --standalone" : "")
+ (citeproc ? " --citeproc" : "") ;
document.getElementById("command").textContent = commandString;
fetch("/cgi-bin/pandoc-server.cgi", {
method: "POST",
headers: {"Content-Type": "application/json"},
body: JSON.stringify(params)
})
.then(response => response.text())
.then(restext => {
let binary = binaryFormats[to];
if (binary) {
document.getElementById("results").innerHTML =
'<a download="trypandoc.' + binary.extension +
'" href="data:' + binary.mime + ';base64,' + restext +
'">click to download trypandoc.' + binary.extension + '</a>';
} else {
document.getElementById("results").textContent = restext;
}
document.getElementById("permalink").href = permalink();
});
};
}
(function() {
paramsFromURL();
document.getElementById("text").value = params.text;
document.getElementById("from").value = params.from;
document.getElementById("to").value = params.to;
document.getElementById("standalone").checked = params.standalone;
document.getElementById("citeproc").checked = params.citeproc;
document.getElementById("convert").onclick = convert;
document.getElementById("from").onchange = convert;
document.getElementById("to").onchange = convert;
document.getElementById("standalone").onchange = convert;
document.getElementById("citeproc").onchange = convert;
const fileInput = document.getElementById('loadfile');
// Listen for the change event so we can capture the file
fileInput.addEventListener('change', (e) => {
// Get a reference to the file
const file = e.target.files[0];
// Encode the file using the FileReader API
const reader = new FileReader();
let binary = binaryFormats[params.from];
let inputtext = document.getElementById("text");
reader.onloadend = () => {
// Use a regex to remove data url part
if (binary) {
const base64String = reader.result
.replace('data:', '')
.replace(/^.+,/, '');
inputtext.value = base64String;
} else {
inputtext.value = reader.result;
}
};
if (binary) {
reader.readAsDataURL(file);
} else {
reader.readAsText(file);
}
});
convert();
})();
</script>
</body>
</html>