Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend functionality to include document types to output solutions and questions at the same time #2

Merged
merged 9 commits into from
Aug 10, 2023
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ extensions](https://quarto.org/docs/extensions/#managing-extensions).
header:

``` yaml
filters:
- unilur
format:
unilur-html: default
unilur-html+solution:
# You have to specify a different output file otherwise they will
# overwrite themselves
output-file: example-solution.html
```

- **Solution** code blocks are either **highlighted** or ~~discarded~~
Expand Down Expand Up @@ -80,7 +84,7 @@ Moreover:
- Create a custom callout (with icon), right now it is a CSS hack on the less used callout `caution`.
- Add tests.
- Remove the `unilur-solution: true` option from chunks when displayed (visible in `echo: fenced`).
+ Idea from Christophe Dervieux: treat `div` attribut
+ Idea from Christophe Dervieux: treat `div` attribute
+ Get `el` content and iterate with `walk()`
+ Add a filter `CodeBlock` which remove the `unilur` options

Expand Down
13 changes: 9 additions & 4 deletions _extensions/unilur/_extension.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
title: Unilur
author: Aurélien Ginolhac
version: 0.0.2
author: Aurélien Ginolhac, Michael Lydeamore
version: 0.0.3
quarto-required: ">=1.3.0"
contributes:
filters:
- unilur.lua
format:
common:
filters:
- unilur.lua
html: default
html+solution:
show-solution: true
7 changes: 3 additions & 4 deletions _extensions/unilur/unilur.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@

div.callout-caution.callout {
border-left-color: #12a629 !important;
}

div.callout-caution.callout-style-default > .callout-header {
div.callout-caution.callout-style-default>.callout-header {
background-color: #ceffd0 !important;
}

Expand All @@ -12,5 +11,5 @@ div.callout-caution.icon .callout-icon {
}

div.callout-caution.callout-captioned .callout-icon::before {
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-chat-left-dots" viewBox="0 0 16 16"><path d="M14 1a1 1 0 0 1 1 1v8a1 1 0 0 1-1 1H4.414A2 2 0 0 0 3 11.586l-2 2V2a1 1 0 0 1 1-1h12zM2 0a2 2 0 0 0-2 2v12.793a.5.5 0 0 0 .854.353l2.853-2.853A1 1 0 0 1 4.414 12H14a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2H2z"/><path d="M5 6a1 1 0 1 1-2 0 1 1 0 0 1 2 0zm4 0a1 1 0 1 1-2 0 1 1 0 0 1 2 0zm4 0a1 1 0 1 1-2 0 1 1 0 0 1 2 0z"/></svg>') ;
}
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-chat-left-dots" viewBox="0 0 16 16"><path d="M14 1a1 1 0 0 1 1 1v8a1 1 0 0 1-1 1H4.414A2 2 0 0 0 3 11.586l-2 2V2a1 1 0 0 1 1-1h12zM2 0a2 2 0 0 0-2 2v12.793a.5.5 0 0 0 .854.353l2.853-2.853A1 1 0 0 1 4.414 12H14a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2H2z"/><path d="M5 6a1 1 0 1 1-2 0 1 1 0 0 1 2 0zm4 0a1 1 0 1 1-2 0 1 1 0 0 1 2 0zm4 0a1 1 0 1 1-2 0 1 1 0 0 1 2 0z"/></svg>');
}
2 changes: 1 addition & 1 deletion _extensions/unilur/unilur.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ end

local function Div(el)
local options_collapse = true
if el.classes:includes("cell") and el.attributes["unilur-solution"] == "true" then
if (el.classes:includes("cell") and el.attributes["unilur-solution"] == "true") or (el.classes:includes("unilur-solution")) then
el.attributes["unilur-solution"] = nil
-- Embed solution code/block inside a callout if global option is true
if options_solution then
Expand Down
66 changes: 50 additions & 16 deletions example.qmd
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
---
title: "[Unilur](https://github.com/ginolhac/unilur) Example"
format:
html:
theme: unilur.scss
filters:
- unilur
show-solution: true
unilur-html: default
unilur-html+solution:
output-file: example-solution.html
embed-resources: true
---

Expand All @@ -14,11 +12,17 @@ embed-resources: true
- **Activate** the extension by adding the following lines to your YAML header:

``` yaml
filters:
- unilur
show-solution: true # or false
format:
unilur-html: default
unilur-html+solution:
# You have to specify a different output file otherwise they will
# overwrite themselves
output-file: example-solution.html
```

When you call `quarto render`, two HTML files will be produced. The one named
`example-solution.html` will have the solution blocks included.

- **Solution** code blocks are **highlighted** or ~~discarded~~ according to the chunk option `unilur-solution` Boolean and the global option `show-solution` in the YAML header.

Of note, if `show-solution` is absent, it is considered `false`.
Expand Down Expand Up @@ -52,13 +56,6 @@ Of note, if `show-solution` is absent, it is considered `false`.
1 + 2
```

- Solution with markdown text (`{block}`):

```{block}
#| unilur-solution: true
#| unilur-collapse: false
For text with **bold** or warning people about CO~2~ atmospheric concentration
```

Any machinery supported by Quarto can be used:

Expand All @@ -68,4 +65,41 @@ Any machinery supported by Quarto can be used:
#| unilur-solution: true
for i in [3, 5, 6]:
print(i)
```
```


- Solution with markdown text (`{block}`):

````{block}
#| unilur-solution: true
#| unilur-collapse: false
For text with **bold** or warning people about CO~2~ atmospheric concentration

R code can be displayed but not executed.

```{{r}}

1 + 1
```

````

You can also include `div` labels with `unilur-solution`.
Note the solution will only show up in the solution file.

::: unilur-solution

Here is a solution that is inside a div. The contents of this will only be shown
in the solution document. Source code highlighting is preserved inside the `div` and executable.

```{r}

sample(CO2, size = 5) |>
head(5)

```

:::

The advantage of working inside the div labels is that standard code formatting and
highlighting will apply, and code can be executed alongside standard text.