From 525edb86c0e4286f0ce061bddd8c98e194f92dde Mon Sep 17 00:00:00 2001 From: Mike Tzou Date: Tue, 17 Mar 2020 01:01:50 +0800 Subject: trypandoc: Add checkbox for standalone option (#6189) --- trypandoc/index.html | 11 +++++++++-- trypandoc/trypandoc.hs | 5 ++++- 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'trypandoc') 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() { + +
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 -- cgit v1.2.3