trypandoc: Add checkbox for standalone option (#6189)

This commit is contained in:
Mike Tzou 2020-03-17 01:01:50 +08:00 committed by GitHub
parent 004907f4f2
commit 525edb86c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View file

@ -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>

View file

@ -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