aboutsummaryrefslogtreecommitdiff
path: root/trypandoc
diff options
context:
space:
mode:
authorMike Tzou <Chocobo1@users.noreply.github.com>2020-03-17 01:01:50 +0800
committerGitHub <noreply@github.com>2020-03-16 10:01:50 -0700
commit525edb86c0e4286f0ce061bddd8c98e194f92dde (patch)
tree9a5da7d79110d38c30924c4413c04e531622cf0e /trypandoc
parent004907f4f229b4aff2ca9c2a96b694251b51cce9 (diff)
downloadpandoc-525edb86c0e4286f0ce061bddd8c98e194f92dde.tar.gz
trypandoc: Add checkbox for standalone option (#6189)
Diffstat (limited to 'trypandoc')
-rw-r--r--trypandoc/index.html11
-rw-r--r--trypandoc/trypandoc.hs5
2 files changed, 13 insertions, 3 deletions
diff --git a/trypandoc/index.html b/trypandoc/index.html
index ea7cacc2d..2b42ab179 100644
--- a/trypandoc/index.html
+++ b/trypandoc/index.html
@@ -32,8 +32,9 @@ function newpage() {
var input = $("#text").val();
var from = $("#from").val();
var to = $("#to").val();
+ var standalone = $("#standalone").is(':checked') ? "1" : "0";
var href = window.location.href;
- window.location.href = href.replace(/([?].*)?$/,"?" + $.param({text: input, from: from, to: to}));
+ window.location.href = href.replace(/([?].*)?$/,"?" + $.param({text: input, from: from, to: to, standalone: standalone}));
};
$(document).ready(function() {
@@ -43,8 +44,10 @@ $(document).ready(function() {
$("#from").val(from);
var to = $.QueryString["to"] || "html";
$("#to").val(to);
+ var standalone = ($.QueryString["standalone"] === "1") ? "1" : "0"
+ $("#standalone").prop('checked', (standalone === "1"));
if (text && text != "") {
- $.getJSON("/cgi-bin/trypandoc", { from: from, to: to, text: text },
+ $.getJSON("/cgi-bin/trypandoc", { from: from, to: to, text: text, standalone: standalone },
function(res) {
$("#results").text(res.html);
$("#version").text(res.version);
@@ -116,6 +119,10 @@ $(document).ready(function() {
<option value="twiki">TWiki</option>
<option value="vimwiki">Vimwiki</option>
</select>
+ <input type="checkbox" id="standalone" name="standalone">
+ <label for="standalone">Generate standalone document
+ <a href="https://pandoc.org/MANUAL.html#option--standalone" target="_blank">(?)</a>
+ </label>
<br/>
<textarea id="text" maxlength="3000" rows="15"></textarea>
</div>
diff --git a/trypandoc/trypandoc.hs b/trypandoc/trypandoc.hs
index 2e4797669..f56a00ac5 100644
--- a/trypandoc/trypandoc.hs
+++ b/trypandoc/trypandoc.hs
@@ -41,6 +41,9 @@ app req respond = do
text <- getParam "text" >>= checkLength . fromMaybe T.empty
fromFormat <- fromMaybe "" <$> getParam "from"
toFormat <- fromMaybe "" <$> getParam "to"
+ standalone <- (==) "1" . fromMaybe "" <$> getParam "standalone"
+ compiledTemplate <- runIO . compileDefaultTemplate $ toFormat
+ let template = if standalone then either (const Nothing) Just compiledTemplate else Nothing
let reader = case runPure $ getReader fromFormat of
Right (TextReader r, es) -> r readerOpts{
readerExtensions = es }
@@ -48,7 +51,7 @@ app req respond = do
++ T.unpack fromFormat
let writer = case runPure $ getWriter toFormat of
Right (TextWriter w, es) -> w writerOpts{
- writerExtensions = es }
+ writerExtensions = es, writerTemplate = template }
_ -> error $ "could not find writer for " ++
T.unpack toFormat
let result = case runPure $ reader (tabFilter 4 text) >>= writer of