1
1
mirror of https://github.com/divnix/digga.git synced 2024-12-23 16:11:51 +03:00
This commit is contained in:
blaggacao 2021-08-01 04:03:45 +00:00
parent 10510d6310
commit 0a5ebc360c
2 changed files with 25 additions and 9 deletions

30
book.js
View File

@ -108,9 +108,12 @@ function playground_text(playground) {
let text = playground_text(code_block); let text = playground_text(code_block);
let classes = code_block.querySelector('code').classList; let classes = code_block.querySelector('code').classList;
let has_2018 = classes.contains("edition2018"); let edition = "2015";
let edition = has_2018 ? "2018" : "2015"; if(classes.contains("edition2018")) {
edition = "2018";
} else if(classes.contains("edition2021")) {
edition = "2021";
}
var params = { var params = {
version: "stable", version: "stable",
optimize: "0", optimize: "0",
@ -133,7 +136,15 @@ function playground_text(playground) {
body: JSON.stringify(params) body: JSON.stringify(params)
}) })
.then(response => response.json()) .then(response => response.json())
.then(response => result_block.innerText = response.result) .then(response => {
if (response.result.trim() === '') {
result_block.innerText = "No output";
result_block.classList.add("result-no-output");
} else {
result_block.innerText = response.result;
result_block.classList.remove("result-no-output");
}
})
.catch(error => result_block.innerText = "Playground Communication: " + error.message); .catch(error => result_block.innerText = "Playground Communication: " + error.message);
} }
@ -151,15 +162,16 @@ function playground_text(playground) {
if (window.ace) { if (window.ace) {
// language-rust class needs to be removed for editable // language-rust class needs to be removed for editable
// blocks or highlightjs will capture events // blocks or highlightjs will capture events
Array code_nodes
.from(document.querySelectorAll('code.editable')) .filter(function (node) {return node.classList.contains("editable"); })
.forEach(function (block) { block.classList.remove('language-rust'); }); .forEach(function (block) { block.classList.remove('language-rust'); });
Array Array
.from(document.querySelectorAll('code:not(.editable)')) code_nodes
.forEach(function (block) { hljs.highlightBlock(block); }); .filter(function (node) {return !node.classList.contains("editable"); })
.forEach(function (block) { hljs.highlightElement(block); });
} else { } else {
code_nodes.forEach(function (block) { hljs.highlightBlock(block); }); code_nodes.forEach(function (block) { hljs.highlightElement(block); });
} }
// Adding the hljs class gives code blocks the color css // Adding the hljs class gives code blocks the color css

View File

@ -175,3 +175,7 @@ blockquote {
margin: 5px 0px; margin: 5px 0px;
font-weight: bold; font-weight: bold;
} }
.result-no-output {
font-style: italic;
}