From 0a7fd0c3f9eecc5430cea50282d8b923e4c20028 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Siebren=20Fr=C3=B6lich?= <48289046+siebrenf@users.noreply.github.com> Date: Fri, 8 Jan 2021 19:32:54 +0100 Subject: [PATCH 1/4] add printButton --- .../templates/tutorial/resources/tutorial-format.css | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/inst/rmarkdown/templates/tutorial/resources/tutorial-format.css b/inst/rmarkdown/templates/tutorial/resources/tutorial-format.css index dd4e6b5e3..85d5abd4f 100644 --- a/inst/rmarkdown/templates/tutorial/resources/tutorial-format.css +++ b/inst/rmarkdown/templates/tutorial/resources/tutorial-format.css @@ -100,6 +100,17 @@ opacity: 1; } +.topicsFooter .printButton { + padding-left: 10px; + font-size: .66em; + cursor: pointer; + opacity: .7; +} + +.topicsFooter .printButton:hover { + opacity: 1; +} + .topicsList .topic { line-height: 40px; font-size: 15px; From 175fa1f8cb1b3581c4141913989122375d488820 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Siebren=20Fr=C3=B6lich?= <48289046+siebrenf@users.noreply.github.com> Date: Fri, 8 Jan 2021 19:36:14 +0100 Subject: [PATCH 2/4] add printButton --- .../templates/tutorial/resources/tutorial-format.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/inst/rmarkdown/templates/tutorial/resources/tutorial-format.js b/inst/rmarkdown/templates/tutorial/resources/tutorial-format.js index 05f2722bd..ed6eb8bf2 100644 --- a/inst/rmarkdown/templates/tutorial/resources/tutorial-format.js +++ b/inst/rmarkdown/templates/tutorial/resources/tutorial-format.js @@ -350,6 +350,12 @@ $(document).ready(function() { }); }); topicsFooter.append(resetButton); + + var printButton = $('Print'); + printButton.on('click', function() { + window.print(); + }); + topicsFooter.append(printButton); topicsList.append(topicsFooter); return topicsList; From 1448d4b8c1be46773048ddc15388aa63b22c57f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Siebren=20Fr=C3=B6lich?= <48289046+siebrenf@users.noreply.github.com> Date: Fri, 8 Jan 2021 19:37:35 +0100 Subject: [PATCH 3/4] add print CSS --- .../tutorial/resources/tutorial-format.css | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/inst/rmarkdown/templates/tutorial/resources/tutorial-format.css b/inst/rmarkdown/templates/tutorial/resources/tutorial-format.css index 85d5abd4f..c6a6eebd7 100644 --- a/inst/rmarkdown/templates/tutorial/resources/tutorial-format.css +++ b/inst/rmarkdown/templates/tutorial/resources/tutorial-format.css @@ -246,6 +246,33 @@ } } +@media print { + .topicsContainer, + .topicActions, + .exerciseActions .skip { + display: none; + } + .topics .tutorialTitle, + .topics .section.level2, + .topics .section.level3:not(.hide) { + display: block; + } + .topics { + width: 100%; + } + .tutorial-exercise, .tutorial-question { + page-break-inside: avoid; + } + .section.level3.done h3 { + padding-left: 0; + background-image: none; + } + .topics .showSkip .exerciseActions::before { + content: "Topic not yet completed..."; + font-style: italic; + } +} + /* override the width to be 100%, not 300px wide */ .shiny-input-container:not(.shiny-input-container-inline) { width: 100%; From 4138e759cf684d830386b0f8ed887c40980b43f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Siebren=20Fr=C3=B6lich?= <48289046+siebrenf@users.noreply.github.com> Date: Fri, 8 Jan 2021 19:44:55 +0100 Subject: [PATCH 4/4] Update NEWS.md --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index f0d73ed7d..f86a9eb49 100644 --- a/NEWS.md +++ b/NEWS.md @@ -12,6 +12,7 @@ learnr (development version) ## New features +* Added a print option to the default tutorial format. ([#467](https://github.com/rstudio/learnr/pull/467)) * Introduced "setup chunk chaining", which allows a setup chunk to depend on another setup chunk and so on, forming a chain of setup code that can be used for exercises via `exercise.setup`. Run `run_tutorial("setup-chunks", "learnr")` for a demo. ([#390](https://github.com/rstudio/learnr/pull/390)) * Introduced an [experimental](https://www.tidyverse.org/lifecycle/#experimental) function `external_evaluator()` which can be used to define an exercise evaluator that runs on a remote server and is invoked via HTTP. This allows all exercise execution to be performed outside of the Shiny process hosting the learnr document. ([#345](https://github.com/rstudio/learnr/pull/345), [#354](https://github.com/rstudio/learnr/pull/354)) * For the "forked" evaluator (the default used on Linux), add a limit to the number of forked exercises that learnr will execute in parallel. Previously, this was uncapped, which could cause a learnr process to run out of memory when an influx of traffic arrived. The default limit is 3, but it can be configured using the `tutorial.max.forked.procs` option or the `TUTORIAL_MAX_FORKED_PROCS` environment variable. ([#353](https://github.com/rstudio/learnr/pull/353))